`experimental_getRealtimeToolDefinitions()`

experimental_getRealtimeToolDefinitions()

`experimental_getRealtimeToolDefinitions` 는 실험적 realtime API의 일부예요.

AI SDK ToolSet 을 프로바이더 중립적인 realtime tool 정의로 변환해 realtime 세션 설정 요청에 전달할 수 있게 해줘요.

단기 realtime 프로바이더 토큰을 만드는 서버 측 설정 엔드포인트에서 사용하세요.

import { openai } from '@ai-sdk/openai';
import { experimental_getRealtimeToolDefinitions, tool } from 'ai';
import { z } from 'zod';

const tools = {
  getWeather: tool({
    description: 'Get the current weather for a city',
    inputSchema: z.object({
      city: z.string(),
    }),
  }),
};

const toolDefinitions = await experimental_getRealtimeToolDefinitions({
  tools,
});

const token = await openai.experimental_realtime.getToken({
  model: 'gpt-realtime',
  sessionConfig: {
    tools: toolDefinitions,
  },
});

출처: 문서

본문

Import

<Snippet text={import { experimental_getRealtimeToolDefinitions } from "ai"} prompt={false} />

API 시그니처

매개변수 (Parameters)

<PropertiesTable content={[ { name: 'options', type: 'Object', description: 'The options for converting tools.', properties: [ { type: 'Object', parameters: [ { name: 'tools', type: 'ToolSet', description: 'The AI SDK tools to expose to the realtime model. Function and dynamic tools are converted to realtime function definitions. Provider tools are skipped.', }, { name: 'toolsContext', type: 'InferToolSetContext', isOptional: true, description: 'Per-tool context used when resolving dynamic tool descriptions.', }, ], }, ], }, ]} />

반환값 (Returns)

Promise<Experimental_RealtimeToolDefinition[]>.

반환된 각 정의는 다음을 포함해요:

<PropertiesTable content={[ { name: 'type', type: "'function'", description: 'The realtime tool definition type.', }, { name: 'name', type: 'string', description: 'The tool name from the input ToolSet.', }, { name: 'description', type: 'string | undefined', description: 'The tool description sent to the realtime model.', }, { name: 'parameters', type: 'JSONSchema7', description: 'The JSON schema converted from the tool inputSchema. The realtime model uses this schema to generate tool call arguments.', }, ]} />

참고 (Notes)

  • tool 실행은 experimental_getRealtimeToolDefinitions 가 처리하지 않아요. experimental_useRealtime 의 onToolCall 과 addToolOutput 을 사용해 tools를 실행하고 결과를 반환하세요.
  • realtime 프로바이더가 세션 설정에 일반 함수 정의를 기대하므로 프로바이더 tools는 건너뛰어요.
  • 동적 tool 설명은 정의가 반환되기 전에 toolsContext 의 일치하는 값으로 해석돼요.

더 알아보기 (Learn more)

전체 사이트맵