Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can we have an example of adding tools? Such as simply querying the weather. #39

Open
skxgood03 opened this issue Oct 15, 2024 · 3 comments
Assignees

Comments

@skxgood03
Copy link

Please provide us with the following information:

This issue is for a: (mark with an x)

- [ ] bug report -> please search issues before submitting
- [ ] feature request
- [ ] documentation issue or request
- [ ] regression (a behavior that used to work and stopped in a new release)

Minimal steps to reproduce

Any log messages given by the failure

Expected/desired behavior

OS and Version?

Windows 7, 8 or 10. Linux (which distribution). macOS (Yosemite? El Capitan? Sierra?)

Versions

Mention any other details that might be useful


Thanks! We'll be in touch soon.

@skxgood03
Copy link
Author

`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.

@glecaros glecaros self-assigned this Oct 15, 2024
@DemacL
Copy link

DemacL commented Oct 17, 2024

   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"
    })
}

@skxgood03
Copy link
Author

   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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants