Reputation: 470
I’m trying to use Azure AI OpenAI to generate responses from a trained model based on a set of data I’ll provide as part of the prompt. My goal is to pass a set of data (e.g., metrics, statistics, or past results) into the model, so it can generate a relevant response.
I’ve set up the OpenAI client in C# correctly, but I’m not sure how to structure the call properly to generate responses using a dataset as input.
How can I pass this data to the model and get a suitable response?
What I’ve tried so far:
I’ve configured the OpenAIClient with the Azure credentials. I’ve used the GetCompletionsAsync method, but I’m unsure how to structure the data properly to get a coherent response. Could anyone provide a basic example of how to make this type of query using Azure AI OpenAI?
What I have:
public class AzureAIService
{
private readonly AzureOpenAIClient _azureClient;
#pragma warning disable OPENAI001
private readonly AssistantClient _assistantClient;
public AzureAIService(string apiKey)
{
string keyFromEnvironment = Environment.GetEnvironmentVariable("AZURE_OPENAI_API_KEY") ?? string.Empty;
_azureClient = new(
new Uri("https://your-azure-openai-resource.com"),
new ApiKeyCredential(keyFromEnvironment));
ChatClient chatClient = _azureClient.GetChatClient("my-gpt-35-turbo-deployment");
_assistantClient = _azureClient.GetAssistantClient();
}
public async Task CreateChatClientAsync()
{
Assistant assistant = await _assistantClient.CreateAssistantAsync(
model: "my-gpt-4o-deployment",
new AssistantCreationOptions()
{
Name = "Ecommerce Assistant",
Instructions = "You are an assistant for an ecommerce and you have to evaluate a series of metrics",
Tools = { ToolDefinition.CreateCodeInterpreter() },
});
ThreadInitializationMessage initialMessage = new(
MessageRole.User,
[
"Here are your recommendations based on today's data:"
]);
AssistantThread thread = await _assistantClient.CreateThreadAsync(new ThreadCreationOptions()
{
InitialMessages = { initialMessage },
});
}
}
Upvotes: 0
Views: 50
Reputation: 2026
Your code seems using Assistant API, then yes you can create a .csv file (see more supported files here https://learn.microsoft.com/en-us/azure/ai-services/openai/how-to/assistant#supported-file-types) in order to be accessed from tools, like code_interpreter to run such prompt "Visualize your provided data" https://learn.microsoft.com/en-us/azure/ai-services/openai/how-to/code-interpreter?tabs=rest#upload-file-for-code-interpreter
Be noticed that up to now you can only use either Python SDK or REST, since your are using C# I would recommend you to send REST request such following:
# Upload a file with an "assistants" purpose
curl https://YOUR_RESOURCE_NAME.openai.azure.com/openai/files?api-version=2024-08-01-preview \
-H "api-key: $AZURE_OPENAI_API_KEY" \
-F purpose="assistants" \
-F file="@c:\\path_to_file\\file.csv"
# Create an assistant using the file ID
curl https://YOUR_RESOURCE_NAME.openai.azure.com/openai/assistants?api-version=2024-08-01-preview \
-H "api-key: $AZURE_OPENAI_API_KEY" \
-H 'Content-Type: application/json' \
-d '{
"instructions": "You are an AI assistant that can write code to help answer math questions.",
"tools": [
{ "type": "code_interpreter" }
],
"name": "Assistants playground",
"model": "Replace it with your-custom-model-deployment-name",
"tool_resources":{
"code_interpreter": {
"file_ids": ["assistant-1234"]
}
}
}'
and download result if there diagrams generated
curl https://YOUR_RESOURCE_NAME.openai.azure.com/openai/files/<YOUR-FILE-ID>/content?api-version=2024-05-01-preview \
-H "api-key: $AZURE_OPENAI_API_KEY" \
--output image.png
Upvotes: 0