@metorial/openai
v3.0.5
Published
OpenAI provider integration for Metorial - enables using Metorial tools with OpenAI's GPT models through function calling.
Downloads
337,758
Readme
@metorial/openai
OpenAI provider integration for Metorial - enables using Metorial tools with OpenAI's GPT models through function calling.
Installation
npm install @metorial/openai
# or
yarn add @metorial/openai
# or
pnpm add @metorial/openai
# or
bun add @metorial/openaiUsage
Basic Usage
import { Metorial } from 'metorial';
import { metorialOpenAI } from '@metorial/openai';
import OpenAI from 'openai';
let metorial = new Metorial({
apiKey: 'your-metorial-api-key'
});
let openai = new OpenAI({
apiKey: 'your-openai-api-key'
});
let session = await metorial.connect({
adapter: metorialOpenAI.chatCompletions(),
providers: [{ providerDeploymentId: 'your-provider-deployment-id' }]
});
let messages = [{ role: 'user', content: 'What are the latest commits?' }];
let response = await openai.chat.completions.create({
model: 'gpt-4o',
messages,
tools: session.tools()
});
// Handle tool calls
let toolCalls = response.choices[0]?.message.tool_calls;
if (toolCalls) {
let toolResponses = await session.callTools(toolCalls);
messages.push({ role: 'assistant', tool_calls: toolCalls }, ...toolResponses);
}License
MIT License - see LICENSE file for details.
