#chat/completions How does it work

1 messages · Page 1 of 1 (latest)

grizzled compass
#
curl https://api.openai.com/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $OPENAI_API_KEY" \
  -d '{
    "model": "gpt-3.5-turbo",
    "messages": [
      {
        "role": "system",
        "content": "You are a helpful assistant."
      },
      {
        "role": "user",
        "content": "Hello!"
      }
    ]
  }'

I have some confusion regarding the application of chat/completions.
How long is the message saved after I make a request?
And how can I access messages I've sent before?

Additionally, here's my understanding of its usage:
First, if I want to converse with it, I must use role: system to teach the AI how to assist users.
Afterward, I can include the content I wish to discuss in messages with role: user.
Can this process send multiple messages? Please provide me with examples of multiple messages.

Then, I want to understand, if with role: system, I have many messages that are the same, can I reuse previous content?
Or does each message require teaching again?
I don't want to keep rewriting the same instructions;
I want to know if this type of guidance has any form of memory.

slow novaBOT
#

Hi @grizzled compass. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:

#

The chat/completions endpoint of OpenAI's API works by taking a list of messages as input and returning a model-generated message as output. The messages are processed in the order they appear in the list, and the assistant responds accordingly. Each message in the list has two properties: role and content. The 'role' can take one of three values: 'system', 'user' or the 'assistant'. The 'content' contains the text of the message from the role[^1^][^2^].

The system message helps set the behavior of the assistant. For example, you can modify the personality of the assistant or provide specific instructions about how it should behave throughout the conversation[^1^]. However, the system message is optional and the model’s behavior without a system message is likely to be similar to using a generic message such as "You are a helpful assistant."[^1^].

The user messages provide requests or comments for the assistant to respond to. Assistant messages store previous assistant responses, but can also be written by you to give examples of desired behavior[^1^].

You can indeed send multiple messages in a conversation. Here's an example of a conversation with multiple messages[^2^]:

'messages': [{'role':'user', 'content':'tell me a joke'},   
{'role':'assistant', 'content':'why did the chicken cross the road'},   
{'role':'user', 'content':'I don't know, why did the chicken cross the road'}]
#

The Chat Completions API, unlike the Assistants API, is not stateful[^3^]. That means you have to manage the messages you pass to the model yourself. If you want to pass the same message to the model multiple times, you will have to pass the message each time you make a request to the API[^3^]. After a message has been processed by the model, it is deleted from OpenAI servers and not retained[^3^]. As of March 1st, 2023, OpenAI retains customer API data for 30 days but no longer uses customer data sent via the API to improve their models[^4^].

^1^]: [Text generation models > Chat Completions API Part 2 (https://platform.openai.com/docs/guides/text-generation)
^2^]: [Moving from Completions to Chat Completions in the OpenAI API (https://help.openai.com/en/articles/7042661-moving-from-completions-to-chat-completions-in-the-openai-api)
^3^]: [Managing images (https://platform.openai.com/docs/guides/vision)
^4^]: [How can I use the Chat Completion (ChatGPT) API? (https://help.openai.com/en/articles/7232945-how-can-i-use-the-chat-completion-chatgpt-api)

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: