How to use an assistant once you have created it

Hi,

I created an assistant where I uploaded some files, I would like then to interact with the assistant through python to ask it to perform specific tasks, but not able to create a dialogue or get a response:
response = client.chat.completions.create(
assistant_id = “assistant.id. key”
model=“gpt-4-1106-preview”,
messages=[
{“role”: “system”, “content”: “You are a helpful assistant.”},
{
“role”: “user”,
“content”: “Hello, can you read the reports and make a summary of each one of them?”
}
],

)

Is this the correct way to do it?

Interacting with an assistant has multiple steps and doesn’t save you any coding work…

Here’s a gateway to understanding the multiple steps and two dozen API methods for interacting with this misguided monstrosity.

https://platform.openai.com/docs/assistants/overview/agents

I have been using the documentation already. The steps I took are the following:

  1. Creating an assistant through python
  2. using the id of that assistant to add files in the directory directly into the assistant

and now I am trying to call the assistant to perform a task and tried to use the documentation to get it sorted out but without success.

The linked quickstart has a code snippet for each of:

  1. Create an Assistant in the API by defining its custom instructions and picking a model. If helpful, enable tools like Code Interpreter, Retrieval, and Function calling.
  2. Create a Thread when a user starts a conversation.
  3. Add Messages to the Thread as the user ask questions.
  4. Run the Assistant on the Thread to trigger responses. This automatically calls the relevant tools.

You then also need to add the regular polling for status, and retrieval of the final response, or handling of API tool calls, etc. Then management of all that for a pool of users and sessions.

I can see in your first post you still trying to use the chat completions endpoint. That’s not how the assistants agent works.

Basically rewrite ChatGPT plus yourself, but without the streamed responses, without the limitation on how much you are billed, without the built in web browsing or image creation, etc.

4 Likes

You are entering a very exciting journey. I started working with autogen as they have now added the assistants api. I would follow the advice provided before this, so as to get a sound footing in understanding how to engage with the api directly using python. Then when you hit the swarm discussions and getting assistants to colaborate and create “stuff”. It gets adictive. The same team created autogenstudio, but they do not seem to support the assistant api yet. But autogen definitely do. Getting to grip with how threads work is also important in the assistants api.

Wishing you well on this journey.