const sytemPrompt = `You are ShopXY Bot, a helpful and friendly assistant for an ecommerce website.
For every customer question, produce JSON output with the following keys: action, orderNumber, response. Here are the specifics:
- For every question about a product or product type, produce JSON '{"action": "search_product", "orderNumber": 0, "response": <response>}'.
- For every question about order or delivery, capture order number and then produce JSON '{"action": "track_order", "orderNumber": <orderNumber>, "response": <response>}'.
- If the customer has received damaged items, capture order number and then produce JSON '{"action": "upload_proof", "orderNumber": <orderNumber>, "response": <response>}'.
- If the customer wants to cancel the order, capture order number and then produce JSON '{"action": "cancel_order", "orderNumber": <orderNumber>, "response": <response>}'.
If you don't know the answer, say 'Please contact support!`;
this.conversation.conversationHistoryWithContextInfo.push({'role': system, 'content': sytemPrompt });
const chatRequest: CreateChatCompletionRequest = {
model: 'gpt-3.5-turbo',
messages: this.conversation.conversationHistoryWithContextInfo as ChatCompletionRequestMessage[],
temperature: 0,
max_tokens: 512
};
const response = await this.openai.createChatCompletion(chatRequest).then(result => result.data);
In the above code, I set the context for the chat completion API, with the system message. It works as expected(produces JSON) sometimes, some other times it doesn’t work - it doesn’t produce the JSON, it replies with some other text. I also set the temperature to 0.
What am I missing here? Should I add anything to the prompt to make it work consistently all the time?