Reputation: 13
Not sure if it's mentioned in any official documentation but what can I input in Azure Ai Studio's prompt flow that has the "Object" type?
Can I put a file as an "Object" input? If yes, how do I do it?
Upvotes: 0
Views: 410
Reputation: 3448
Can I put a file as an "Object" input? If yes, how do I do it?
Directly uploading a file as an "Object" input isn't natively supported. Instead, Convert the file into a Base64 string and include this string in a JSON object.
Test_Node.py:
from promptflow import tool
import base64
@tool
def my_python_tool(input1: dict) -> str:
# Check if input1 is valid and contains required keys
if not input1 or 'file_name' not in input1 or 'file_data' not in input1:
return "Invalid input: Missing 'file_name' or 'file_data'."
file_name = input1.get("file_name")
file_data_base64 = input1.get("file_data")
if not file_name or not file_data_base64:
return "Invalid input: 'file_name' or 'file_data' cannot be None."
try:
# Decode the Base64 encoded file data (even if we don't use it)
file_data = base64.b64decode(file_data_base64).decode('utf-8')
except Exception as e:
return f"Error decoding file data: {str(e)}"
# Create a static response string
response = "Hello boss, I am back!"
return response
{
"file_name": "example.txt",
"file_data": "SGVsbG8gd29ybGQh"
}
Output:
In this way, we can be able to input complex data structures into the prompt flow to provide richer context and also handle more advanced scenarios.
Upvotes: 0