cohere

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Feb 6, 2025 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ModelList = []string{
	"command", "command-nightly",
	"command-light", "command-light-nightly",
	"command-r", "command-r-plus",
}
View Source
var (
	WebSearchConnector = Connector{ID: "web-search"}
)

Functions

func Handler

func Handler(c *gin.Context, resp *http.Response, promptTokens int, modelName string) (*model.ErrorWithStatusCode, *model.Usage)

func ResponseCohere2OpenAI

func ResponseCohere2OpenAI(cohereResponse *Response) *openai.TextResponse

func StreamHandler

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

Types

type APIVersion

type APIVersion struct {
	Version string `json:"version"`
}

type Adaptor

type Adaptor struct{}

func (*Adaptor) ConvertImageRequest

func (*Adaptor) ConvertImageRequest(request *model.ImageRequest) (any, error)

ConvertImageRequest implements adaptor.Adaptor.

func (*Adaptor) ConvertRequest

func (a *Adaptor) ConvertRequest(c *gin.Context, relayMode int, request *model.GeneralOpenAIRequest) (any, error)

func (*Adaptor) DoRequest

func (a *Adaptor) DoRequest(c *gin.Context, meta *meta.Meta, requestBody io.Reader) (*http.Response, error)

func (*Adaptor) DoResponse

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

func (*Adaptor) GetChannelName

func (a *Adaptor) GetChannelName() string

func (*Adaptor) GetModelList

func (a *Adaptor) GetModelList() []string

func (*Adaptor) GetRequestURL

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

func (*Adaptor) Init

func (a *Adaptor) Init(meta *meta.Meta)

func (*Adaptor) SetupRequestHeader

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

type BilledUnits

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

type ChatEntry

type ChatEntry struct {
	Role    string `json:"role"`
	Message string `json:"message"`
}

type ChatMessage

type ChatMessage struct {
	Role    string `json:"role" required:"true"`
	Message string `json:"message" required:"true"`
}

type Citation

type Citation struct {
	Start       int      `json:"start"`
	End         int      `json:"end"`
	Text        string   `json:"text"`
	DocumentIDs []string `json:"document_ids"`
}

type Connector

type Connector struct {
	ID string `json:"id"`
}

type Document

type Document struct {
	ID        string `json:"id"`
	Snippet   string `json:"snippet"`
	Timestamp string `json:"timestamp"`
	Title     string `json:"title"`
	URL       string `json:"url"`
}

type Message

type Message struct {
	Role    string `json:"role"`
	Message string `json:"message"`
}

type Meta

type Meta struct {
	APIVersion  APIVersion  `json:"api_version"`
	BilledUnits BilledUnits `json:"billed_units"`
	Tokens      Usage       `json:"tokens"`
}

type ParameterSpec

type ParameterSpec struct {
	Description string `json:"description"`
	Type        string `json:"type" required:"true"`
	Required    bool   `json:"required"`
}

type Request

type Request struct {
	Message          string        `json:"message" required:"true"`
	Model            string        `json:"model,omitempty"`  // 默认值为"command-r"
	Stream           bool          `json:"stream,omitempty"` // 默认值为false
	Preamble         string        `json:"preamble,omitempty"`
	ChatHistory      []ChatMessage `json:"chat_history,omitempty"`
	ConversationID   string        `json:"conversation_id,omitempty"`
	PromptTruncation string        `json:"prompt_truncation,omitempty"` // 默认值为"AUTO"
	Connectors       []Connector   `json:"connectors,omitempty"`
	Documents        []Document    `json:"documents,omitempty"`
	Temperature      *float64      `json:"temperature,omitempty"` // 默认值为0.3
	MaxTokens        int           `json:"max_tokens,omitempty"`
	MaxInputTokens   int           `json:"max_input_tokens,omitempty"`
	K                int           `json:"k,omitempty"` // 默认值为0
	P                *float64      `json:"p,omitempty"` // 默认值为0.75
	Seed             int           `json:"seed,omitempty"`
	StopSequences    []string      `json:"stop_sequences,omitempty"`
	FrequencyPenalty *float64      `json:"frequency_penalty,omitempty"` // 默认值为0.0
	PresencePenalty  *float64      `json:"presence_penalty,omitempty"`  // 默认值为0.0
	Tools            []Tool        `json:"tools,omitempty"`
	ToolResults      []ToolResult  `json:"tool_results,omitempty"`
}

func ConvertRequest

func ConvertRequest(textRequest model.GeneralOpenAIRequest) *Request

type Response

type Response struct {
	ResponseID    string          `json:"response_id"`
	Text          string          `json:"text"`
	GenerationID  string          `json:"generation_id"`
	ChatHistory   []*Message      `json:"chat_history"`
	FinishReason  *string         `json:"finish_reason"`
	Meta          Meta            `json:"meta"`
	Citations     []*Citation     `json:"citations"`
	Documents     []*Document     `json:"documents"`
	SearchResults []*SearchResult `json:"search_results"`
	SearchQueries []*SearchQuery  `json:"search_queries"`
	Message       string          `json:"message"`
}

func StreamResponseCohere2OpenAI

func StreamResponseCohere2OpenAI(cohereResponse *StreamResponse) (*openai.ChatCompletionsStreamResponse, *Response)

type SearchQuery

type SearchQuery struct {
	Text         string `json:"text"`
	GenerationID string `json:"generation_id"`
}

type SearchResult

type SearchResult struct {
	SearchQuery *SearchQuery `json:"search_query"`
	DocumentIDs []string     `json:"document_ids"`
	Connector   *Connector   `json:"connector"`
}

type StreamResponse

type StreamResponse struct {
	IsFinished    bool            `json:"is_finished"`
	EventType     string          `json:"event_type"`
	GenerationID  string          `json:"generation_id,omitempty"`
	SearchQueries []*SearchQuery  `json:"search_queries,omitempty"`
	SearchResults []*SearchResult `json:"search_results,omitempty"`
	Documents     []*Document     `json:"documents,omitempty"`
	Text          string          `json:"text,omitempty"`
	Citations     []*Citation     `json:"citations,omitempty"`
	Response      *Response       `json:"response,omitempty"`
	FinishReason  string          `json:"finish_reason,omitempty"`
}

type Tool

type Tool struct {
	Name                 string                   `json:"name" required:"true"`
	Description          string                   `json:"description" required:"true"`
	ParameterDefinitions map[string]ParameterSpec `json:"parameter_definitions"`
}

type ToolCall

type ToolCall struct {
	Name       string                 `json:"name" required:"true"`
	Parameters map[string]interface{} `json:"parameters" required:"true"`
}

type ToolResult

type ToolResult struct {
	Call    ToolCall                 `json:"call"`
	Outputs []map[string]interface{} `json:"outputs"`
}

type Units

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

type Usage

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

type Version

type Version struct {
	Version string `json:"version"`
}

Jump to

Keyboard shortcuts

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