openrouter

package module
v0.0.0-...-9ebc1f9 Latest Latest
Warning

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

Go to latest
Published: Feb 7, 2025 License: Apache-2.0 Imports: 14 Imported by: 0

README

go-openrouter

Documentation

Index

Constants

View Source
const (
	ChatMessageRoleUser      = "user"
	ChatMessageRoleSystem    = "system"
	ChatMessageRoleAssistant = "assistant"
)
View Source
const (
	GooglePalm2CodeChatBison = "google/palm-2-codechat-bison"
	GooglePalm2ChatBison     = "google/palm-2-chat-bison"
	OpenaiGpt35Turbo         = "openai/gpt-3.5-turbo"
	OpenaiGpt35Turbo16k      = "openai/gpt-3.5-turbo-16k"
	OpenaiGpt4               = "openai/gpt-4"
	OpenaiGpt432K            = "openai/gpt-4-32k"
	OpenaiGpt4oMini          = "openai/gpt-4o-mini"
	AnthropicClaude2         = "anthropic/claude-2"
	AnthropicClaudeInstantV1 = "anthropic/claude-instant-v1"
	MetaLlamaLlama213bChat   = "meta-llama/llama-2-13b-chat"
	MetaLlamaLlama270bChat   = "meta-llama/llama-2-70b-chat"
	Palm2CodeChatBison       = "palm-2-codechat-bison"
	Palm2ChatBison           = "palm-2-chat-bison"
	Gpt35Turbo               = "gpt-3.5-turbo"
	Gpt35Turbo16k            = "gpt-3.5-turbo-16k"
	Gpt4                     = "gpt-4"
	G432K                    = "gpt-4-32k"
	Claude2                  = "claude-2"
	ClaudeInstantV1          = "claude-instant-v1"
	Llama213bChat            = "llama-2-13b-chat"
	Llama270bChat            = "llama-2-70b-chat"
)

Variables

View Source
var (
	ErrChatCompletionStreamNotSupported = errors.New("streaming is not supported with this method, please use CreateChatCompletionStream") //nolint:lll
	ErrCompletionUnsupportedModel       = errors.New("this model is not supported with this method")                                       //nolint:lll
)
View Source
var (
	ErrTooManyEmptyStreamMessages = errors.New("stream has sent too many empty messages")
)

Functions

This section is empty.

Types

type APIError

type APIError struct {
	Code           any    `json:"code,omitempty"`
	Message        string `json:"message"`
	Details        any    `json:"details"`
	HTTPStatusCode int    `json:"-"`
}

APIError provides error information returned by the OpenAI API.

func (*APIError) Error

func (e *APIError) Error() string

func (*APIError) UnmarshalJSON

func (e *APIError) UnmarshalJSON(data []byte) (err error)

type ChatCompletionChoice

type ChatCompletionChoice struct {
	Message      Index  `json:"message,omitempty"`
	FinishReason string `json:"finish_reason,omitempty"`
	Delta        Index  `json:"delta,omitempty"`
	Index        uint   `json:"index,omitempty"`
}

type ChatCompletionMessage

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

type ChatCompletionRequest

type ChatCompletionRequest struct {
	Model       string                  `json:"model"`
	Messages    []ChatCompletionMessage `json:"messages"`
	MaxTokens   int                     `json:"max_tokens,omitempty"`
	Stream      bool                    `json:"stream,omitempty"`
	Temperature *float32                `json:"temperature,omitempty"`
	TopP        *float32                `json:"top_p,omitempty"`
	TopK        *uint                   `json:"top_k,omitempty"`
}

ChatCompletionRequest represents a request structure for chat completion API.

type ChatCompletionResponse

type ChatCompletionResponse struct {
	ID      string                 `json:"id,omitempty"`
	Object  string                 `json:"object,omitempty"`
	Created int64                  `json:"created,omitempty"`
	Model   string                 `json:"model"`
	Choices []ChatCompletionChoice `json:"choices"`
}

ChatCompletionResponse represents a response structure for chat completion API.

type ChatCompletionStream

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

func (*ChatCompletionStream) Close

func (stream *ChatCompletionStream) Close()

func (*ChatCompletionStream) Recv

func (stream *ChatCompletionStream) Recv() (response *ChatCompletionResponse, err error)

type Client

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

func NewClient

func NewClient(auth, xTitle, httpReferer string) (*Client, error)

func NewClientWithConfig

func NewClientWithConfig(config ClientConfig) *Client

func (*Client) CreateChatCompletion

func (c *Client) CreateChatCompletion(
	ctx context.Context,
	request *ChatCompletionRequest,
) (response *ChatCompletionResponse, err error)

CreateChatCompletion — API call to Create a completion for the chat message.

func (*Client) CreateChatCompletionStream

func (c *Client) CreateChatCompletionStream(
	ctx context.Context,
	request *ChatCompletionRequest,
) (stream *ChatCompletionStream, err error)

CreateChatCompletionStream — API call to create a chat completion w/ streaming support. It sets whether to stream back partial progress. If set, tokens will be sent as data-only server-sent events as they become available, with the stream terminated by a data: [DONE] message.

type ClientConfig

type ClientConfig struct {
	XTitle             string
	HttpReferer        string
	BaseURL            string
	HTTPClient         *http.Client
	EmptyMessagesLimit uint
	// contains filtered or unexported fields
}

ClientConfig is a configuration of a client. XTitle、HttpRefer your own site url

func DefaultConfig

func DefaultConfig(auth, xTitle, httpReferer string) (ClientConfig, error)

func (ClientConfig) WithHttpClientConfig

func (c ClientConfig) WithHttpClientConfig(client *http.Client) ClientConfig

type ErrorResponse

type ErrorResponse struct {
	Error *APIError `json:"error,omitempty"`
}

type Index

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

type ModelName

type ModelName string

type RequestError

type RequestError struct {
	HTTPStatusCode int
	Err            error
}

RequestError provides informations about generic request errors.

func (*RequestError) Error

func (e *RequestError) Error() string

func (*RequestError) Unwrap

func (e *RequestError) Unwrap() error

type Usage

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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