provider

package
v0.2.4 Latest Latest
Warning

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

Go to latest
Published: Aug 12, 2025 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AnyParams

type AnyParams map[string]any

type Choice

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

	// for stream
	Delta *struct {
		Role    string `json:"role"`
		Content string `json:"content"`
	} `json:"delta,omitempty"`
}

Choice represents a completion choice

type Error added in v0.2.0

type Error struct {
	Code    int    `json:"code,omitempty"`
	Message string `json:"message,omitempty"`
	Type    string `json:"type,omitempty"`
}

func NewError added in v0.2.0

func NewError(code int, err error) *Error

func (*Error) String added in v0.2.0

func (e *Error) String() string

type Message

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

Message represents a single message in the conversation

type OpenAIProvider

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

OpenAIProvider implements the Provider interface for OpenAI

func NewOpenAIProvider

func NewOpenAIProvider(apiKey, endpoint, model string, timeout time.Duration) *OpenAIProvider

NewOpenAIProvider creates a new OpenAIProvider

func (*OpenAIProvider) Name

func (p *OpenAIProvider) Name() string

Name returns the provider name

func (*OpenAIProvider) SendRequest

func (p *OpenAIProvider) SendRequest(priorityParams, anyParam AnyParams, headers map[string]string) (*Response, *Error)

SendRequest sends a request to OpenAI API

func (*OpenAIProvider) SupportsStreaming

func (p *OpenAIProvider) SupportsStreaming() bool

SupportsStreaming returns whether OpenAI supports streaming

type Provider

type Provider interface {
	// Name returns the provider name
	Name() string

	// SendRequest sends a request to the LLM and returns the response
	SendRequest(priorityParams AnyParams, anyParam AnyParams, headers map[string]string) (*Response, *Error)

	// SupportsStreaming returns whether the provider supports streaming
	SupportsStreaming() bool
}

Provider interface for different LLM providers

type QwenProvider

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

QwenProvider implements the Provider interface for Qwen(same as OpenAI)

func NewQwenProvider

func NewQwenProvider(apiKey, endpoint, model string, timeout time.Duration) *QwenProvider

NewQwenProvider creates a new QwenProvider

func (*QwenProvider) Name

func (p *QwenProvider) Name() string

Name returns the provider name

func (*QwenProvider) SendRequest

func (p *QwenProvider) SendRequest(priorityParams, anyParam AnyParams, headers map[string]string) (*Response, *Error)

SendRequest sends a request to Qwen API

func (*QwenProvider) SupportsStreaming

func (p *QwenProvider) SupportsStreaming() bool

SupportsStreaming returns whether Qwen supports streaming

type Response

type Response struct {
	ID      string   `json:"id"`
	Model   string   `json:"model"`
	Choices []Choice `json:"choices,omitempty"`
	Usage   Usage    `json:"usage"`
	// local fields
	Latency           time.Duration `json:"-"`
	FirstTokenLatency time.Duration `json:"-"` // Streaming specific fields

	JsonData string `json:"-"`
}

Response represents an LLM response

func (*Response) String

func (r *Response) String() string

type Usage

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

Usage represents token usage information

Jump to

Keyboard shortcuts

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