JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 18
  • Score
    100M100P100Q82103F
  • License MIT

OpenAI integration for Robota SDK - GPT-4, GPT-3.5, function calling, and tool integration with OpenAI's API

Package Exports

  • @robota-sdk/openai
  • @robota-sdk/openai/dist/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@robota-sdk/openai) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

@robota-sdk/openai

npm version

OpenAI integration package for Robota SDK.

Documentation

For full documentation, visit https://robota.io

Installation

npm install @robota-sdk/openai @robota-sdk/core openai

Overview

@robota-sdk/openai provides integration with OpenAI models for Robota SDK. This package allows you to use OpenAI's GPT models with function calling capabilities in your AI agent applications.

Basic Usage

import { Robota } from '@robota-sdk/core';
import { OpenAIProvider } from '@robota-sdk/openai';
import OpenAI from 'openai';

// Initialize OpenAI client
const openaiClient = new OpenAI({
  apiKey: process.env.OPENAI_API_KEY
});

// Create OpenAI provider
const provider = new OpenAIProvider({
  client: openaiClient
});

// Create Robota instance with OpenAI provider
const robota = new Robota({
  aiProviders: {
    openai: provider
  },
  currentProvider: 'openai',
  currentModel: 'gpt-4',
  systemPrompt: 'You are a helpful AI assistant.'
});

// Run a simple conversation
const response = await robota.run('What can you tell me about artificial intelligence?');
console.log(response);

Function Calling

OpenAI provider supports function calling capabilities through tool providers:

import { Robota } from '@robota-sdk/core';
import { OpenAIProvider } from '@robota-sdk/openai';
import { createZodFunctionToolProvider } from '@robota-sdk/tools';
import OpenAI from 'openai';
import { z } from 'zod';

// Create tool provider with functions
const toolProvider = createZodFunctionToolProvider({
  tools: {
    getWeather: {
      name: 'getWeather',
      description: 'Get weather information for a location',
      parameters: z.object({
        location: z.string().describe('The city name'),
        unit: z.enum(['celsius', 'fahrenheit']).default('celsius')
      }),
      handler: async (params) => {
        // Implement weather lookup logic
        return { temperature: 22, condition: 'Sunny' };
      }
    }
  }
});

// Initialize provider
const provider = new OpenAIProvider({
  client: new OpenAI({ apiKey: process.env.OPENAI_API_KEY })
});

const robota = new Robota({
  aiProviders: {
    openai: provider
  },
  currentProvider: 'openai',
  currentModel: 'gpt-4',
  toolProviders: [toolProvider]
});

const response = await robota.run('What\'s the weather like in Seoul?');

Models

Supports all OpenAI models including:

  • GPT-4
  • GPT-3.5 Turbo
  • And other compatible models

License

MIT