openai

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2025 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type APIResponse

type APIResponse struct {
	ID      string   `json:"id"`
	Object  string   `json:"object"`
	Created int64    `json:"created"`
	Model   string   `json:"model"`
	Usage   Usage    `json:"usage"`
	Choices []Choice `json:"choices"`
}

type Choice

type Choice struct {
	Index        int          `json:"index"`
	Message      MessageParam `json:"message"`
	FinishReason string       `json:"finish_reason"`
}

type Client

type Client struct {
	// contains filtered or unexported fields
}

func NewClient

func NewClient(apiKey string, baseURL string) *Client

func (*Client) CreateChatCompletion

func (c *Client) CreateChatCompletion(ctx context.Context, req CreateRequest) (*APIResponse, error)

type CreateRequest

type CreateRequest struct {
	Model       string         `json:"model"`
	Messages    []MessageParam `json:"messages"`
	Tools       []Tool         `json:"tools,omitempty"`
	MaxTokens   int            `json:"max_tokens,omitempty"`
	Temperature float32        `json:"temperature,omitempty"`
}

type FunctionCall

type FunctionCall struct {
	Name      string `json:"name"`
	Arguments string `json:"arguments"`
}

type FunctionDef

type FunctionDef struct {
	Name        string      `json:"name"`
	Description string      `json:"description"`
	Parameters  interface{} `json:"parameters"`
}

type Message

type Message struct {
	Resp   *APIResponse
	Choice *Choice
}

Message implements the llm.Message interface

func (*Message) GetContent

func (m *Message) GetContent() string

func (*Message) GetRole

func (m *Message) GetRole() string

func (*Message) GetToolCalls

func (m *Message) GetToolCalls() []llm.ToolCall

func (*Message) GetToolResponseID

func (m *Message) GetToolResponseID() string

func (*Message) GetUsage

func (m *Message) GetUsage() (int, int)

func (*Message) IsToolResponse

func (m *Message) IsToolResponse() bool

type MessageParam

type MessageParam struct {
	Role             string        `json:"role"`
	Content          *string       `json:"content"`
	ReasoningContent *string       `json:"reasoning_content,omitempty"`
	FunctionCall     *FunctionCall `json:"function_call,omitempty"`
	ToolCalls        []ToolCall    `json:"tool_calls,omitempty"`
	Name             string        `json:"name,omitempty"`
	ToolCallID       string        `json:"tool_call_id,omitempty"`
}

type Provider

type Provider struct {
	// contains filtered or unexported fields
}

func NewProvider

func NewProvider(apiKey, baseURL, model, systemPrompt string) *Provider

func (*Provider) CreateMessage

func (p *Provider) CreateMessage(
	ctx context.Context,
	prompt string,
	messages []llm.Message,
	tools []llm.Tool,
) (llm.Message, error)

func (*Provider) CreateToolResponse

func (p *Provider) CreateToolResponse(
	toolCallID string,
	content interface{},
) (llm.Message, error)

func (*Provider) Name

func (p *Provider) Name() string

func (*Provider) SupportsTools

func (p *Provider) SupportsTools() bool

type Tool

type Tool struct {
	Type     string      `json:"type"`
	Function FunctionDef `json:"function"`
}

type ToolCall

type ToolCall struct {
	ID       string       `json:"id"`
	Type     string       `json:"type"`
	Function FunctionCall `json:"function"`
}

type ToolCallWrapper

type ToolCallWrapper struct {
	Call ToolCall
}

ToolCallWrapper implements llm.ToolCall

func (*ToolCallWrapper) GetArguments

func (t *ToolCallWrapper) GetArguments() map[string]interface{}

func (*ToolCallWrapper) GetID

func (t *ToolCallWrapper) GetID() string

func (*ToolCallWrapper) GetName

func (t *ToolCallWrapper) GetName() string

type Usage

type Usage struct {
	PromptTokens     int `json:"prompt_tokens"`
	CompletionTokens int `json:"completion_tokens"`
	TotalTokens      int `json:"total_tokens"`
}

Jump to

Keyboard shortcuts

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