intentkit-openai
v1.2.0
Published
OpenAI function calling bridge for IntentKit
Maintainers
Readme
intentkit-openai
OpenAI function calling bridge for IntentKit. Converts IntentKit functions into OpenAI-compatible tool definitions and provides a handler for executing function calls.
Install
npm install intentkit-openai intentkitUsage
Generate Tool Definitions
import { IntentRegistry } from 'intentkit';
import { generateOpenAITools } from 'intentkit-openai';
const registry = new IntentRegistry().register(/* your functions */);
const tools = generateOpenAITools(registry);
// Pass to OpenAI API
const response = await openai.chat.completions.create({
model: 'gpt-4',
messages: [{ role: 'user', content: 'Create a task called "Ship v2"' }],
tools,
});Handle Function Calls
import { createOpenAIHandler } from 'intentkit-openai';
const handler = createOpenAIHandler({
registry,
context,
roles: { admin: ['*'], viewer: ['task:read'] },
defaultRole: 'admin',
});
// Process tool calls from the response
for (const toolCall of response.choices[0].message.tool_calls ?? []) {
const result = await handler(
toolCall.function.name,
JSON.parse(toolCall.function.arguments),
);
console.log(result);
}License
MIT
