I am a neophyte Python and OpenAI developer, who used to be a competent C/C++ programmer. I think I am missing some methods probably very obvious to seasoned programmers in this space.
Following Assistants, how-it-works, creating-assistants:
→ I am successful with OpenAI Assistant calls like:
from openai import OpenAI
client = OpenAI()
assistant = client.beta.assistants.create(...)
thread = client.beta.threads.create()
message = client.beta.threads.messages.create(...)
(Obviously also with arguments in place of … in those calls)
→ And what I get back from run(…) is of this form: (/n’s added)
SyncCursorPage[ThreadMessage](data=[ThreadMessage(id=‘msg_3Fn9nQJXMDbQKv7tDVoHUf42’,
assistant_id=‘asst_AvD1LtW8iZCevetBioCujuta’, content=[MessageContentText(text=Text(annotations=,
value=‘The solution to the equation 3x + 11 = 14
is x = 1
.’), type=‘text’)], created_at=1706145471,
(etc.)
But what I see in all the APIreferences is very different:
→ Response messages like:
{
“id”: “asst_abc123”,
“object”: “assistant”,
“created_at”: 1698984975,
“name”: “Math Tutor”,
“description”: null,
“model”: “gpt-4”,
“instructions”: “You are a personal math tutor. When asked a question, write and run Python code to answer the question.”,
“tools”: [
{
“type”: “code_interpreter”
}
],
“file_ids”: ,
“metadata”: {}
}
→ From curl calls such as:
curl (URL)
-H “Content-Type: application/json”
-H “Authorization: Bearer $OPENAI_API_KEY”
-H “OpenAI-Beta: assistants=v1”
Can anyone explain for me:
- What’s going on with these two different “ways” to call an OpenAI Assistant?
- From Python, how do I “use” the above forms of response, e.g., how do I know how many messages are in: SyncCursorPage[ThreadMessage]
– How do I extracxt each of them?
– Is there an API to parse this structure? Or what?
Apologize if this is a “dumb” question, as I said in my opening, I think I am missing some methods probably very obvious to seasoned programmers in this space.