Skip to content

Commit

Permalink
feat: Make tools inventory overridable per session update
Browse files Browse the repository at this point in the history
  • Loading branch information
tillkolter committed Oct 9, 2024
1 parent 39669af commit f36605b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
5 changes: 5 additions & 0 deletions .changeset/lovely-horses-eat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@livekit/agents-plugin-openai': minor
---

Narrow tools inventory per session update
19 changes: 11 additions & 8 deletions plugins/openai/src/realtime/realtime_model.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
// SPDX-FileCopyrightText: 2024 LiveKit, Inc.
//
// SPDX-License-Identifier: Apache-2.0
import { AsyncIterableQueue, Future, Queue } from '@livekit/agents';
import { llm, log, multimodal } from '@livekit/agents';
import { AsyncIterableQueue, Future, Queue, llm, log, multimodal } from '@livekit/agents';
import { AudioFrame } from '@livekit/rtc-node';
import { once } from 'events';
import { WebSocket } from 'ws';
Expand Down Expand Up @@ -392,6 +391,7 @@ export class RealtimeSession extends multimodal.RealtimeSession {
temperature = this.#opts.temperature,
maxResponseOutputTokens = this.#opts.maxResponseOutputTokens,
toolChoice = 'auto',
allowedFunctions = Object.keys(this.#fncCtx || {}),
}: {
modalities: ['text', 'audio'] | ['text'];
instructions?: string;
Expand All @@ -403,6 +403,7 @@ export class RealtimeSession extends multimodal.RealtimeSession {
temperature?: number;
maxResponseOutputTokens?: number;
toolChoice?: api_proto.ToolChoice;
allowedFunctions?: string[];
}) {
this.#opts = {
modalities,
Expand All @@ -420,12 +421,14 @@ export class RealtimeSession extends multimodal.RealtimeSession {
};

const tools = this.#fncCtx
? Object.entries(this.#fncCtx).map(([name, func]) => ({
type: 'function' as const,
name,
description: func.description,
parameters: llm.oaiParams(func.parameters),
}))
? Object.entries(this.#fncCtx)
.filter(([name]) => allowedFunctions.includes(name))
.map(([name, func]) => ({
type: 'function' as const,
name,
description: func.description,
parameters: llm.oaiParams(func.parameters),
}))
: [];

this.queueMsg({
Expand Down

0 comments on commit f36605b

Please sign in to comment.