Documentation

OpenAI Models

A drag-and-drop component for integrating OpenAI's language models. Configure model parameters and connect inputs/outputs to leverage OpenAI's powerful AI capabilities.

OpenAI Component

OpenAI component interface and configuration

API Key Notice: A valid OpenAI API key is required to use this component. Ensure your API key has sufficient quota and appropriate rate limits for your application needs.

Component Inputs

  • Input: Text input for the model

    Example: "Explain the concept of machine learning in simple terms."

  • System Message: System prompt to guide model behavior

    Example: "You are a helpful AI assistant that explains complex topics in simple language."

  • Stream: Toggle for streaming responses

    Example: true (for real-time token streaming) or false (for complete response)

  • Model Name: The OpenAI model to use

    Example: "gpt-4o-mini", "gpt-4o", "gpt-4-turbo"

  • OpenAI API Key: Your API authentication key

    Example: "sk-abcdefghijklmnopqrstuvwxyz123456789"

  • OpenAI API Base: Custom API endpoint (optional)

    Example: "https://custom-openai-endpoint.com/v1"

  • JSON Mode: Toggle for JSON output format

    Example: true (forces model to return valid JSON)

Component Outputs

  • Text: Generated text output

    Example: "Machine learning is a type of artificial intelligence that allows computers to learn from data without being explicitly programmed..."

  • Language Model: Model information and metadata

    Example: model: gpt-4o-mini, usage: {prompt_tokens: 42, completion_tokens: 128, total_tokens: 170}

Generation Parameters

Max Tokens

Maximum tokens to generate in the response

Default: Model-dependent (e.g., 4096 for most GPT-4 models) Range: 1 to model maximum Recommendation: Set based on expected response length

Temperature

Controls randomness in the output - higher values increase creativity

Default: 0.10 Range: 0.0 to 2.0 Recommendation: Lower (0.0-0.3) for factual/consistent responses, Higher (0.7-1.0) for creative tasks

Seed

Random seed for reproducible results

Default: 1 Range: Integer values Recommendation: Use consistent seed values when reproducibility is important

Implementation Example

// Basic configuration const openAI = { modelName: "gpt-4o-mini", openAIApiKey: process.env.OPENAI_API_KEY, systemMessage: "You are a helpful assistant." }; // Advanced configuration const advancedOpenAI = { modelName: "gpt-4o", openAIApiKey: process.env.OPENAI_API_KEY, openAIApiBase: "https://api.openai.com/v1", temperature: 0.7, maxTokens: 1000, jsonMode: true, stream: true, seed: 12345, modelKwargs: { response_format: { type: "json_object" } } }; // Usage example async function generateResponse(input) { const response = await openaiComponent.generate({ input: input, systemMessage: "You are an expert in climate science.", temperature: 0.3 }); return response.text; }

Use Cases

  • Chatbots and Virtual Assistants: Create conversational agents using streaming responses
  • Content Generation: Create articles, blog posts, and creative writing
  • Data Extraction: Use JSON mode to extract structured information from unstructured text
  • RAG Applications: Generate responses based on retrieved context
  • Code Generation: Create code snippets and programming solutions

Best Practices

  • Use environment variables for API keys in production environments
  • Monitor token usage to manage costs
  • Implement proper error handling for API failures
  • Use system messages effectively to guide model behavior
  • Set appropriate temperature values based on your specific use case