New RunLLM response generated: >>>*# Question* He...
# runllm-flyte-trial
a
New RunLLM response generated: >>>*# Question* Hey all, is there any easy way to convert Flyte execution output to json string? I have tried using
Copy code
execution = remote.fetch_execution(name="...", project="...", domain="...")
execution_output = {}
for key, val in execution.outputs.items():
        execution_output[key] = val
this works well if the output is a python dict. But it will throw exception
Cannot convert from <FlyteLiteral scalar { primitive
{ string_value:… to <class Dict>
when the workflow return type is primitive type. how could I handle both scenarios? Any help is appreciated! # Answer To convert Flyte execution output to a JSON string, you can use the
to_dict
method provided by Flyte's
TypeEngine
to handle both primitive and complex types. Here's an example:
Copy code
from flytekit.remote.remote import FlyteRemote, Config
from flytekit.core.type_engine import TypeEngine
import json

remote = FlyteRemote(config=Config.auto(config_file="path/to/config.yaml"))
execution = remote.fetch_execution(name="...", project="...", domain="...")

execution_output = {}
for key, val in execution.outputs.items():
    execution_output[key] = TypeEngine.to_python_value(val)

json_output = json.dumps(execution_output)
print(json_output)
This approach ensures that both primitive and complex types are correctly converted to their Python equivalents before being serialized to JSON. Would you like more details on this approach or any other aspect of Flyte? Sources: - TypeEngine Source Code Slack Link https://flyte-org.slack.com/archives/CP2HDHKE1/p1723933608.410679 👍 0 button 👎 0 button 💡 Hint: Mention @runllm in the thread for followups.