I need to get a thread id and I don’t understand where I’m supposed to make a thread from and I need an api key and yes you guessed it I have no clue where to get that from either all I have is the assistant key someone please help.
You will likely not want to start with Assistants, their “threads”, and the multiple API calls that must procedurally set up and interact with different endpoint methods.
Instead, Chat Completions allows you to send an AI model messages, and immediately get back an API response with the generated response language.
Then, because the API model is stateless, having no memory server-side, if you want to have a chat based on continued reference to what you were just talking about, you simulate that memory by providing prior user inputs and AI responses as chat turn messages before the latest input that needs to be fulfilled by an AI.
The Assistants endpoint keeps a conversation server-side, to send to a model. This does not make it something for novices to program though. It is a lower bar to have a program keep a chat record of user chats than to write the required interactions on Assistants platform (that also doesn’t serve the needs of experts).
To get started, read the “quickstart” in the documentation link. Some programming ability is a prerequisite. The site platform.openai.com is where you manage an API account.
To use API services, you must prepay credits, to pay for the data which is input and generated. https://openai.com/api/pricing/
Sending a conversation with an AI, showing the growing turns of a request - and answers within.
``
from openai import OpenAI
client = OpenAI()
response = client.chat.completions.create(
model=“gpt-4”,
messages=[
{
“role”: “system”,
“content”: [
{
“type”: “text”,
“text”: “You are an assistant who only provides the briefest of answers with the highest-quality truthful essential knowledge needed.”
}
]
},
{
“role”: “user”,
“content”: [
{
“type”: “text”,
“text”: “How should I program procedurally for the OpenAI API to make a chatbot that remembers what was discussed previously?”
}
]
},
{
“role”: “assistant”,
“content”: [
{
“type”: “text”,
“text”: “Use the ‘messages’ parameter in the API call. Include all conversation history each time you call the API. The history should contain alternating ‘role’ and ‘content’ pairs, with ‘role’ being ‘system’, ‘user’, or ‘assistant’, and ‘content’ being the text of the message from the role.”
}
]
},
{
“role”: “user”,
“content”: [
{
“type”: “text”,
“text”: “Why must a programmer keep their own record of past chat turns when using language models?”
}
]
},
{
“role”: “assistant”,
“content”: [
{
“type”: “text”,
“text”: “Language models like GPT-3 don’t have memory of past requests. They generate responses based on the input they receive in the current request only.”
}
]
}
],
max_completion_tokens=2048,
top_p=0.3,
)