anthropic

package
v0.0.0-...-03c30b8 Latest Latest
Warning

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

Go to latest
Published: Jan 10, 2025 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ModelList = []*model.ModelConfig{
	{
		Model: "claude-instant-1.2",
		Type:  relaymode.ChatCompletions,
		Owner: model.ModelOwnerAnthropic,
	},
	{
		Model: "claude-2.0",
		Type:  relaymode.ChatCompletions,
		Owner: model.ModelOwnerAnthropic,
	},
	{
		Model: "claude-2.1",
		Type:  relaymode.ChatCompletions,
		Owner: model.ModelOwnerAnthropic,
	},
	{
		Model: "claude-3-haiku-20240307",
		Type:  relaymode.ChatCompletions,
		Owner: model.ModelOwnerAnthropic,
	},
	{
		Model: "claude-3-sonnet-20240229",
		Type:  relaymode.ChatCompletions,
		Owner: model.ModelOwnerAnthropic,
	},
	{
		Model: "claude-3-opus-20240229",
		Type:  relaymode.ChatCompletions,
		Owner: model.ModelOwnerAnthropic,
	},
	{
		Model: "claude-3-5-sonnet-20240620",
		Type:  relaymode.ChatCompletions,
		Owner: model.ModelOwnerAnthropic,
	},
	{
		Model: "claude-3-5-sonnet-20241022",
		Type:  relaymode.ChatCompletions,
		Owner: model.ModelOwnerAnthropic,
	},
	{
		Model: "claude-3-5-sonnet-latest",
		Type:  relaymode.ChatCompletions,
		Owner: model.ModelOwnerAnthropic,
	},
}

Functions

func Handler

func Handler(meta *meta.Meta, c *gin.Context, resp *http.Response) (*model.ErrorWithStatusCode, *model.Usage)

func ResponseClaude2OpenAI

func ResponseClaude2OpenAI(claudeResponse *Response) *openai.TextResponse

func StreamHandler

func StreamHandler(_ *meta.Meta, c *gin.Context, resp *http.Response) (*model.ErrorWithStatusCode, *model.Usage)

Types

type Adaptor

type Adaptor struct{}

func (*Adaptor) ConvertRequest

func (a *Adaptor) ConvertRequest(meta *meta.Meta, req *http.Request) (http.Header, io.Reader, error)

func (*Adaptor) DoRequest

func (a *Adaptor) DoRequest(_ *meta.Meta, _ *gin.Context, req *http.Request) (*http.Response, error)

func (*Adaptor) DoResponse

func (a *Adaptor) DoResponse(meta *meta.Meta, c *gin.Context, resp *http.Response) (usage *relaymodel.Usage, err *relaymodel.ErrorWithStatusCode)

func (*Adaptor) GetChannelName

func (a *Adaptor) GetChannelName() string

func (*Adaptor) GetModelList

func (a *Adaptor) GetModelList() []*model.ModelConfig

func (*Adaptor) GetRequestURL

func (a *Adaptor) GetRequestURL(meta *meta.Meta) (string, error)

func (*Adaptor) SetupRequestHeader

func (a *Adaptor) SetupRequestHeader(meta *meta.Meta, c *gin.Context, req *http.Request) error

type Content

type Content struct {
	Type   string       `json:"type"`
	Text   string       `json:"text,omitempty"`
	Source *ImageSource `json:"source,omitempty"`
	// tool_calls
	ID        string `json:"id,omitempty"`
	Name      string `json:"name,omitempty"`
	Input     any    `json:"input,omitempty"`
	Content   string `json:"content,omitempty"`
	ToolUseID string `json:"tool_use_id,omitempty"`
}

type Delta

type Delta struct {
	StopReason   *string `json:"stop_reason"`
	StopSequence *string `json:"stop_sequence"`
	Type         string  `json:"type"`
	Text         string  `json:"text"`
	PartialJSON  string  `json:"partial_json,omitempty"`
}

type Error

type Error struct {
	Type    string `json:"type"`
	Message string `json:"message"`
}

type ImageSource

type ImageSource struct {
	Type      string `json:"type"`
	MediaType string `json:"media_type"`
	Data      string `json:"data"`
}

type InputSchema

type InputSchema struct {
	Properties any    `json:"properties,omitempty"`
	Required   any    `json:"required,omitempty"`
	Type       string `json:"type"`
}

type Message

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

type Metadata

type Metadata struct {
	UserID string `json:"user_id"`
}

type Request

type Request struct {
	ToolChoice    any       `json:"tool_choice,omitempty"`
	Temperature   *float64  `json:"temperature,omitempty"`
	TopP          *float64  `json:"top_p,omitempty"`
	Model         string    `json:"model"`
	System        string    `json:"system,omitempty"`
	Messages      []Message `json:"messages"`
	StopSequences []string  `json:"stop_sequences,omitempty"`
	Tools         []Tool    `json:"tools,omitempty"`
	MaxTokens     int       `json:"max_tokens,omitempty"`
	TopK          int       `json:"top_k,omitempty"`
	Stream        bool      `json:"stream,omitempty"`
}

func ConvertRequest

func ConvertRequest(meta *meta.Meta, req *http.Request) (*Request, error)

type Response

type Response struct {
	StopReason   *string   `json:"stop_reason"`
	StopSequence *string   `json:"stop_sequence"`
	Error        Error     `json:"error"`
	ID           string    `json:"id"`
	Type         string    `json:"type"`
	Role         string    `json:"role"`
	Model        string    `json:"model"`
	Content      []Content `json:"content"`
	Usage        Usage     `json:"usage"`
}

type StreamResponse

type StreamResponse struct {
	Message      *Response `json:"message"`
	ContentBlock *Content  `json:"content_block"`
	Delta        *Delta    `json:"delta"`
	Usage        *Usage    `json:"usage"`
	Type         string    `json:"type"`
	Index        int       `json:"index"`
}

type Tool

type Tool struct {
	InputSchema InputSchema `json:"input_schema"`
	Name        string      `json:"name"`
	Description string      `json:"description,omitempty"`
}

type Usage

type Usage struct {
	InputTokens  int `json:"input_tokens"`
	OutputTokens int `json:"output_tokens"`
}

Jump to

Keyboard shortcuts

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