How to organize the work with the context using the API in the same way as the Chat tab in ChatGPT? What would be when the user accesses through my UI interface working through the API
context was preserved.
Как организовать работу с контекстом c использованием API аналогично работе вкладки Chat в ChatGPT? Что бы при обращении пользователя через мой UI интерфейс работающий через API
сохранялся контекст общения.
- You need to use the new chat API.
- Note that it uses a
messages
array that you send with every request, which takes the entire history of the chat conversation from your UI (including the back-and-forth messages between user and AI):
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Who won the world series in 2020?"},
{"role": "assistant", "content": "The Los Angeles Dodgers won the World Series in 2020."},
{"role": "user", "content": "Where was it played?"}
]
- With the
system
message, you prime the AI to be prepared for your type of conversation.
- Then you add each message from your UI
user
, followed by whatever the AI assistant
returns and so on.
- This way each request submits the full history of your chat, and takes it into account as context for each new response.
1 Like