Hi! I have a function that returns a JSON object. I want to format this object in the resulting chat message. How do I best provide these instructions?
For example:
I have a function called articulate_values_card
. I want to call it when a user in the chat has articulated something important to them. This function returns an object with a title and a short description of the value.
Now, I want to show this object in a particular way in the chat. For instance, I want the assistant to refer to the title of the card, and ask the user if they like it. How do I best provide this instruction?
So far I have tried:
- Adding instructions in the system prompt for formatting results from
articulate_values_card
- Adding instructions in the description of the function around how outputs should be interpreted.
- Returning an instruction string instead of the actual response from the function in the “function” message.
The latter seems to work best, but it feels like an ugly way of doing it.
To clarify, what I mean is that if my function is returning:
'{"title":"Embodied Justice","short_description":"When I sense into what feels just in my body, life feels authentic and real"}'
I actually send this string as the function result for the chat completion:
<A card (${card.title}) was articulated and shown to the user. The preview of the card is shown in the UI, no need to repeat it here. The user can now choose to submit the card.>
const res = await openai.createChatCompletion({
model: "gpt-3.5-turbo-0613",
messages: [
...messages,
{
role: "assistant",
content: null,
function_call: {
name: "articulate_values_card",
arguments: args
},
},
{
role: "function",
name: "articulate_values_card",
content: `<A card (${card.title}) was articulated and shown to the user. The preview of the card is shown in the UI, no need to repeat it here. The user can now choose to submit the card.>`
},
],
temperature: 0.7,
functions,
stream: true,
})
Is there a best-practice for how to format chat responses following the output of a function call?