You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello. I'm having trouble knowing the correct way to code the following situation.
I'm using AssistantsEndpoint because I need to send a file - which I sent using UploadFileAsync - for ChatGPT to analyze and answer questions about that file.
I managed to do this, but I created a list of hard-coded messages, and used CreateThreadRequest(messages) passing this list, so that ChatGPT could answer the questions. So far so good.
However, I want to make this iterative with the user - that is, the user types in the question they want to ask about the file, and I send it to ChatGPT.
I'm doing it this way: passing the complete list of messages every time and creating a new CreateThreadRequest - but in my understanding this is not the right way to do it.
I would like to pass only new messages to get new responses. Is it possible to do that?
Thank you very much in advance.
using OpenAI;using OpenAI.Assistants;using OpenAI.Threads;using System.Net;internalclassProgram{privatestaticasync Task Main(string[]args){
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;stringapiKey="....";usingvarapi=new OpenAIClient(apiKey);vartools=newList<Tool>{// Use a predefined tool
Tool.Retrieval, Tool.CodeInterpreter,};varcreateRequest=new CreateAssistantRequest("gpt-3.5-turbo", tools: tools);//var createRequest = new CreateAssistantRequest("gpt-4-turbo-preview", tools: tools);varassistant=await api.AssistantsEndpoint.CreateAssistantAsync(createRequest);varfilePath="assistant_test_2.txt";varassistantFile=await assistant.UploadFileAsync(filePath);varmessages=newList<OpenAI.Threads.Message>{new OpenAI.Threads.Message("What does the attached text talk about?"),new OpenAI.Threads.Message("Which character is mentioned in the text?"),new OpenAI.Threads.Message("Where does the story take place?"),};varthreadRequest=new CreateThreadRequest(messages);varrun=await assistant.CreateThreadAndRunAsync(threadRequest);run=await run.WaitForStatusChangeAsync();var_messages=await run.ListMessagesAsync();foreach(var message in _messages.Items.OrderBy(response => response.CreatedAt)){
Console.WriteLine($"{message.Role}: {message.PrintContent()}");}
Console.Read();}}
This discussion was converted from issue #279 on April 10, 2024 14:49.
Heading
Bold
Italic
Quote
Code
Link
Numbered list
Unordered list
Task list
Attach files
Mention
Reference
Menu
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hello. I'm having trouble knowing the correct way to code the following situation.
I'm using AssistantsEndpoint because I need to send a file - which I sent using UploadFileAsync - for ChatGPT to analyze and answer questions about that file.
I managed to do this, but I created a list of hard-coded messages, and used CreateThreadRequest(messages) passing this list, so that ChatGPT could answer the questions. So far so good.
However, I want to make this iterative with the user - that is, the user types in the question they want to ask about the file, and I send it to ChatGPT.
I'm doing it this way: passing the complete list of messages every time and creating a new CreateThreadRequest - but in my understanding this is not the right way to do it.
I would like to pass only new messages to get new responses. Is it possible to do that?
Thank you very much in advance.
Beta Was this translation helpful? Give feedback.
All reactions