providers

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 20, 2025 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type OpenAIMessage

type OpenAIMessage struct {
	Role    string `json:"role"`
	Content string `json:"content"`
}

OpenAIMessage represents a message in the OpenAI chat format

type OpenAIProvider

type OpenAIProvider struct {
	APIKey     string
	Model      string
	BaseURL    string
	HTTPClient *http.Client
	Timeout    time.Duration
}

OpenAIProvider implements the Provider interface for OpenAI models

func NewOpenAIProvider

func NewOpenAIProvider(apiKey, model string) *OpenAIProvider

NewOpenAIProvider creates a new OpenAI provider

func (*OpenAIProvider) GetModelInfo

func (p *OpenAIProvider) GetModelInfo() map[string]interface{}

GetModelInfo returns information about the model

func (*OpenAIProvider) GetUsageInfo

func (p *OpenAIProvider) GetUsageInfo() map[string]interface{}

GetUsageInfo returns token usage information

func (*OpenAIProvider) SendPrompt

func (p *OpenAIProvider) SendPrompt(ctx context.Context, prompt string) (string, error)

SendPrompt sends a prompt to the OpenAI API and returns the response

type OpenAIRequest

type OpenAIRequest struct {
	Model       string          `json:"model"`
	Messages    []OpenAIMessage `json:"messages"`
	Temperature float64         `json:"temperature,omitempty"`
	MaxTokens   int             `json:"max_tokens,omitempty"`
}

OpenAIRequest represents a request to the OpenAI API

type OpenAIResponse

type OpenAIResponse struct {
	ID      string `json:"id"`
	Object  string `json:"object"`
	Created int64  `json:"created"`
	Choices []struct {
		Index   int `json:"index"`
		Message struct {
			Role    string `json:"role"`
			Content string `json:"content"`
		} `json:"message"`
		FinishReason string `json:"finish_reason"`
	} `json:"choices"`
	Usage struct {
		PromptTokens     int `json:"prompt_tokens"`
		CompletionTokens int `json:"completion_tokens"`
		TotalTokens      int `json:"total_tokens"`
	} `json:"usage"`
}

OpenAIResponse represents a response from the OpenAI API

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL