I am using a different language, PHP. Here is the code with the prompt:
$instruction = "Generate a standalone question which is based on the new question plus the chat history. Just create the standalone question without commentary. New question: ".$question;
$chatHistory[] = ["role" => "user", "content" => $instruction];
// Define the data for the API request
$data = array(
'messages' => $chatHistory,
'model' => $model,
'temperature' => $temperature
);
So, I append the $instruction you see above to the existing chat history and submit that as my chat completion ‘messages’.
It has worked so far on 100% of the questions I have sent. However, everybody’s application is different. My goal was for the model to keep general track of conversation, and I do this using the “standalone question”. Here is a brief conversation I just executed. My vector store has 3 articles concerning Star Trek. What you see below is my question, the question concept created (used to retrieve the context documents), the standalone question created and the assistant response.
Note how the assistant is able to keep track of what I am talking about as I switch from Star Trek to Harlan Ellison’s lawsuit to the Hugo award to the Netflix deal without specifically mentioning any of them :
Question (type ‘exit’ to quit): what do you know about star trek?
Star Trek
First Question: what do you know about star trek?
Response: Star Trek is a popular science fiction television series. One notable episode is titled “City on the Edge of Forever,” which was written by Harlan Ellison. The episode, which aired in April 1967, centers on time travel and stars Joan Collins. It won the WGA teleplay award and a Hugo award. Harlan Ellison sued CBS Paramount for not paying him for the merchandising, publishing, and other exploitations of the episode. Later, he settled the lawsuit with CBS Paramount, but the terms of the settlement were not disclosed. In 2011, Netflix signed a $200 million deal with CBS for nonexclusive streaming rights to popular TV shows, including Star Trek.
Question (type ‘exit’ to quit): who won the lawsuit?
chat history tokens 229
settlement of lawsuit
Standalone Question: Who did Harlan Ellison settle the lawsuit with?
Response: Harlan Ellison settled the lawsuit with CBS Paramount.
Question (type ‘exit’ to quit): did he win an award?
chat history tokens 260
Awards won by ‘City on the Edge of Forever’
Standalone Question: Did “City on the Edge of Forever” win any awards?
Response: Yes, “City on the Edge of Forever” won the WGA teleplay award and a Hugo award. The episode, written by Harlan Ellison, first aired in April 1967 and centered on time travel, starring Joan Collins.
Question (type ‘exit’ to quit): when was the deal?
chat history tokens 330
Netflix signed a $200 million deal with CBS for nonexclusive streaming rights to popular TV shows, including Star Trek
Standalone Question: When did Netflix sign a $200 million deal with CBS for nonexclusive streaming rights to popular TV shows, including Star Trek?
Response: Netflix signed a $200 million deal with CBS for nonexclusive streaming rights to popular TV shows, including Star Trek, on February 13, 2011.
How, may I ask, is your use case different? That may explain why you’re only getting 50% results.