Azure / azure-sdk-for-net

This repository is for active development of the Azure SDK for .NET. For consumers of the SDK we recommend visiting our public developer docs at https://learn.microsoft.com/dotnet/azure/ or our versioned developer docs at https://azure.github.io/azure-sdk-for-net.
MIT License
5.37k stars 4.79k forks source link

[QUERY] OpenAI Assistants V2 on Azure - Activate File search on assistant + specify file_ids in message's attachments #44574

Closed Freddeb closed 4 months ago

Freddeb commented 4 months ago

Library name and version

Azure OpenAI 2.0.0-beta

Query/Question

Hi,

I need to port my chatbot application (.net Core) from the API openai.com to the Azure OpenAI. My project now has a reference to the new Azure OpenAI 2.0.0-beta library which (from what I understand) makes call now to the official .net library supported by OpenAI.

My chatbot application uses the Assistant V2 functionality and more specifically the search in files (I upload PDF in the bot prompt).

You will undoubtedly tell me that there is a way to do it with the Assistant V1 version but the V2 version corresponds much better to what I am looking for, i.e. being able to associate files with a message (attachment) rather than associating them with an Assistant.

Now although I find the Assistants V2 characteristics in the new Azure OpenAI 2.0.0-beta library, at the level of Azure OpenAI Studio nothing brings up the new options of V2 such as for example the "File search" option which must be activated on the assistant if I associate file identifiers in the attachments of my message.

I tried to programmatically modify the assistant by adding the tool definition "file search".

var amo = new EditOptionsAssistant(); List toolDefinitions = new List(); toolDefinitions.Add(ToolDefinition.CreateFileSearch()); assistant = await client.ModifyAssistantAsync(assistant.Id, new AssistantModificationOptions() { DefaultTools = toolDefinitions });

But I get the following error exception when ModifyAssistantAsync is called : vector store with id 'asst_oMyZfNBwPZexgfEeDGIXUyom' not found.

This "vector store" error seems to suggest that Assistant V2 does exist in the OpenAI Azure service.

What do I need to do to be able to use this feature through Azure? Am I doing something wrong?

I'm new to Azure OpenAI, I hope my question makes sense...

Thanks for your help.

Fred

Environment

Windows 10 Visual Studio 2022 - Version 17.9.6 .NET 6 Microsoft Bot Framework 4

github-actions[bot] commented 4 months ago

Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @jpalvarezl @ralph-msft @trrwilson.

trrwilson commented 4 months ago

Hello, @Freddeb! The latest library absolutely does support Assistants v2, so you're looking in the right place.

Could you share a more complete code snippet demonstrating the creation of the assistant and any additional modification details? That error message indicates that a tool resource is being provided. For reference, here's a code snippet that creates an assistant and then modifies it like you shared:

AzureOpenAIClient azureClient = new(endpoint, keyCredential);
AssistantClient client = azureClient.GetAssistantClient();

Assistant assistant = await client.CreateAssistantAsync("gpt-4-turbo");

assistant = await client.ModifyAssistantAsync(assistant, new AssistantModificationOptions()
{
    DefaultTools = { new CodeInterpreterToolDefinition() },
});

Console.WriteLine(assistant.Tools[0].ToString());
Freddeb commented 4 months ago

Hello @trrwilson,

Thank you for you feedback. I will follow you code snippet and create the assistant this time from my code. I'll give you my feedback in a couple of hours.

It is maybe important to say that I firstly created my assistant from the web interface of Azure (Assistant Playground) and then i retrieved the assistant by id from my code, then I called the method ModifyAssistantAsync. This web interface only shows V1 features.

image

Thank you.

Freddeb commented 4 months ago

Hello @trrwilson, Based on your code snippet, I've created a new assistant from my C# code (and not from the Azure OpenAI studio web interface). The following actions were all successful : Creation of the assistant (Type: code interpreter) Modification of the assistant (Type: file search) Create a thread Create a message with 1 attachment (file_id -> PDF), user message = question about the PDF document content. Create a run and wait for completion. The returned message was all my expectations.

I hope that the Azure platform will quickly adapt its web interface to give the possibility of creating assistants in version V2.

Thank you for you help and for your work. FdB