Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.Net: New Feature: OpenAIAssistantAgent's AddChatMessageAsync for files. #9790

Open
aeras3637 opened this issue Nov 22, 2024 · 5 comments
Open
Assignees
Labels
agents experimental Associated with an experimental feature follow up Issues that require a follow up from the community. .NET Issue or Pull requests regarding .NET code question Further information is requested

Comments

@aeras3637
Copy link


name: OpenAIAssistantAgent's AddChatMessageAsync for files.
Please use OpenAIAssistantAgent's AddChatMessageAsync to correspond to the file.

You may want to upload a file in the middle of an Agent's conversation.
In AssistantMessageFactory.CreateOptions, only Metadata is supported and there is no way to pass FileId.
If FileReferenceContent is included in Items of ChatMessageContent, please set it to Attachments in MessageCreationOptions.


@markwallace-microsoft markwallace-microsoft added .NET Issue or Pull requests regarding .NET code agents and removed triage labels Nov 22, 2024
@github-actions github-actions bot changed the title New Feature: OpenAIAssistantAgent's AddChatMessageAsync for files. .Net: New Feature: OpenAIAssistantAgent's AddChatMessageAsync for files. Nov 22, 2024
@crickman crickman added experimental Associated with an experimental feature question Further information is requested labels Nov 22, 2024
@crickman crickman moved this to Sprint: In Progress in Semantic Kernel Nov 22, 2024
@crickman
Copy link
Contributor

Hi @aeras3637, thank you for this suggestion. I'm curious on which type of file you are aiming to upload?

The Assistant API support both text and image content for input messages; although, Azure services / deployments are restricted to text-only.

All other file content must be either referenced from a Vector Store (for the file-search tool) or as a tool resource (for the code-interpreter tool). You may add files to a referenced vector store at any point using the OpenAIFileClient , as shown here:

https://github.com/microsoft/semantic-kernel/blob/main/dotnet/samples/GettingStartedWithAgents/Step11_AssistantTool_FileSearch.cs

Additionally, files specific to a particular thread may be specified upon thread-creation via: https://github.com/microsoft/semantic-kernel/blob/main/dotnet/src/Agents/OpenAI/OpenAIThreadCreationOptions.cs

(Either code-interpreter files, or a Vector Store for file-search).

From a design perspective, we chose to avoid managing , obfuscating, or otherwise interfering with how a developer might defined and update a Vector Store.

In terms of providing file-content to an assistant, we are constrained by what is possible via the API:

https://platform.openai.com/docs/api-reference/assistants

With that said, I'd very much be open to continuing to explore your proposal. Looking forward to your response.

@crickman crickman added the follow up Issues that require a follow up from the community. label Nov 22, 2024
@aeras3637
Copy link
Author

Hi @crickman, Thank you for your response.

The files to be uploaded are in formats such as CSV and XLSX.

At the start of the chat, I specify the FileId uploaded with OpenAIFileClient to CodeInterpreterFileIds in OpenAIAssistantAgent.CreateAsync. I create an agent, create a thread with CreateThreadAsync, and execute InvokeAsync.

What I want to achieve is that, although I initially uploaded a file, there are cases where I want to upload additional files during the course of the chat conversation. However, I couldn't find a method to upload files in such cases.

@crickman
Copy link
Contributor

I see, thank you. You can use the AssistantClient to modify the thread.

https://platform.openai.com/docs/api-reference/threads/modifyThread

Currently we don't directly expose patterns for thread modification. At this point in time, you can access the AssistantClient directly for this using the same OpenAIClientProvider you used to create the agent and access the OpenAIFileCient

  AssistantClient assistantClient = provider.Client.GetAssistantClient();
  await assistantClient.ModifyThreadAsync(threadId, new ThreadModificationOptions() { ToolResources = { CodeInterpreter = { FileIds = { newFileId } } } });

@aeras3637
Copy link
Author

Thank you.

I was able to add the file with assistantClient.ModifyThreadAsync.

When adding files from the conversation flow, it feels more natural to be able to add files with AddChatMessageAsync, do you plan to support this?
The API seems to support this.
https://platform.openai.com/docs/api-reference/messages/createMessage#messages-createmessage-attachments

@crickman
Copy link
Contributor

I've left this issue open for consideration. I'm not entirely sure on the full impact of integrating this as part of create message loop, but we also have a request to support modify assistant scenario...so I'll be looking at modify cases broadly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
agents experimental Associated with an experimental feature follow up Issues that require a follow up from the community. .NET Issue or Pull requests regarding .NET code question Further information is requested
Projects
Status: Sprint: In Progress
Development

No branches or pull requests

3 participants