Mishalabdullah / Chiua

A fronted for the chatgpt
https://chiua.vercel.app
Apache License 2.0
2 stars 1 forks source link

[Improvements] The chat interface should send previous responses to ChatGPT in order to get context. #2

Closed Mishalabdullah closed 3 months ago

Mishalabdullah commented 3 months ago

When you use the OpenAI API (such as the GPT-3 API) to interact with the ChatGPT model, the model does not inherently remember previous responses from past API calls. Each API call is stateless, meaning it does not retain memory of prior interactions unless that context is explicitly provided in the input.

To create an interaction that feels like the model is remembering previous responses, you need to include the history of the conversation in each API request. This means you should send a conversation history along with each prompt.

Here’s an example of how you might structure the input so the model "remembers" the context:

{ "model": "text-davinci-003", "prompt": "User: What is the capital of France?\nAI: The capital of France is Paris.\nUser: What is its population?", "max_tokens": 50 } Python Example Using OpenAI API import openai

openai.api_key = 'your-api-key'

Conversation history

conversation = [ {"role": "user", "content": "What is the capital of France?"}, {"role": "assistant", "content": "The capital of France is Paris."}, {"role": "user", "content": "What is its population?"} ]

response = openai.ChatCompletion.create( model="gpt-3.5-turbo", # use the specific model you are working with messages=conversation, max_tokens=50 )

print(response['choices'][0]['message']['content']) Each subsequent request should include the full conversation history in the messages parameter to maintain context. This is essential for tasks that require context continuity, such as chatbots or virtual assistants.

Mishalabdullah commented 3 months ago

This has been fixed in the commit 00a53a8584afef74759d60c541316413b46482ab

for reference :- click here