0.3.6 • Published 8 months ago

@paybyrd/ai-agent-openai v0.3.6

Weekly downloads
-
License
MIT
Repository
-
Last release
8 months ago

Paybyrd AI Agent for OpenAI

OpenAI integration for Paybyrd's AI Agent Toolkit.

Installation

npm install @paybyrd/ai-agent-openai

Quick Start

This package provides tools for OpenAI's function calling API.

Setup

import OpenAI from 'openai';
import { OpenAIAgentToolkit } from '@paybyrd/ai-agent-openai';

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

// Initialize the Paybyrd toolkit
const toolkit = new OpenAIAgentToolkit({
  authToken: process.env.PAYBYRD_API_KEY,
  configuration: {
    actions: {
      paymentLinks: { create: true },
      refunds: { create: true },
      order: { read: true }
    },
  },
});

Function Calling Example

async function createPaymentLink() {
  // Get the tools for OpenAI
  const tools = toolkit.getTools();
  
  // Make a request to OpenAI with the tools
  const response = await openai.chat.completions.create({
    model: 'gpt-4o',
    messages: [
      { 
        role: 'system', 
        content: 'You are a helpful assistant that can create payment links and process refunds.' 
      },
      { 
        role: 'user', 
        content: 'Can you create a payment link for €50 for a customer named John Smith?' 
      }
    ],
    tools: tools,
  });
  
  const message = response.choices[0].message;
  
  // Handle tool calls if any were made
  if (message.tool_calls && message.tool_calls.length > 0) {
    // Process the tool calls
    const toolResults = await Promise.all(
      message.tool_calls.map(toolCall => toolkit.handleToolCall(toolCall))
    );
    
    // Continue the conversation with the results
    const finalResponse = await openai.chat.completions.create({
      model: 'gpt-4o',
      messages: [
        { 
          role: 'system', 
          content: 'You are a helpful assistant that can create payment links and process refunds.' 
        },
        { 
          role: 'user', 
          content: 'Can you create a payment link for €50 for a customer named John Smith?' 
        },
        message,
        ...toolResults,
      ],
    });
    
    return finalResponse.choices[0].message;
  }
  
  return message;
}

Available Tools

The toolkit provides these tools to OpenAI:

  • create_payment_link: Create a payment link for a customer
  • create_refund: Process a refund for a transaction
  • retrieve_order: Get details about an order

License

MIT

0.3.6

8 months ago

0.3.5

8 months ago

0.3.4

8 months ago

0.3.3

8 months ago

0.3.2

8 months ago

0.3.1

8 months ago

0.3.0

8 months ago

0.2.7

8 months ago

0.2.6

8 months ago

0.2.5

8 months ago

0.2.4

8 months ago