Open skxgood03 opened 1 month ago
`function createConfigMessage(): SessionUpdateMessage {
let configMessage: SessionUpdateMessage = {
type: "session.update",
session: {
turn_detection: {
type: "server_vad",
},
input_audio_transcription: {
model: "whisper-1"
},
tools: [
{
type: "function",
name: "get_weather_for_location",
description: "gets the weather for a location",
parameters: {
type: "object",
properties: {
location: {
type: "string",
description: "The city and state e.g. San Francisco, CA"
},
unit: {
type: "string",
enum: ["c", "f"]
}
},
required: ["location", "unit"]
}
}
],
tool_choice: {
type: "function",
function: "get_weather_for_location"
}
}
};
const systemMessage = getSystemMessage();
const temperature = getTemperature();
const voice = getVoice();
if (systemMessage) {
configMessage.session.instructions = systemMessage;
}
if (!isNaN(temperature)) {
configMessage.session.temperature = temperature;
}
if (voice) {
configMessage.session.voice = voice;
}
return configMessage;
}`I added tools here, but I don't understand how to write it later to make it complete.
case 'response.function_call_arguments.done':
handleFunctionCall(message)
break
2.
async function handleFunctionCall(message: any) {
params = JSON.parse(message.arguments)
let funcName = message.name
if (funcName === 'XXXX') {
console.log('funcName', funcName) // get Data
const data = 'your data'
const msg = {
type: "conversation.item.create",
previous_item_id: message.item_id,
item: {
type: 'message',
role: "user",
content: [{
type: "input_text",
text: `$ {
handle your data
}`,
}],
status: 'completed',
}
}
realtimeStreaming.send(msg)
}
realtimeStreaming.send({
type: "response.create"
})
}
case 'response.function_call_arguments.done': handleFunctionCall(message) break
async function handleFunctionCall(message: any) { params = JSON.parse(message.arguments) let funcName = message.name if (funcName === 'XXXX') { console.log('funcName', funcName) // get Data const data = 'your data' const msg = { type: "conversation.item.create", previous_item_id: message.item_id, item: { type: 'message', role: "user", content: [{ type: "input_text", text: `$ { handle your data }`, }], status: 'completed', } } realtimeStreaming.send(msg) } realtimeStreaming.send({ type: "response.create" }) }
Thank you, I have been solved.
This issue is for a: (mark with an
x
)Minimal steps to reproduce
Any log messages given by the failure
Expected/desired behavior
OS and Version?
Versions
Mention any other details that might be useful