cohere

package
v0.0.0-...-af8a321 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ModelList = []*model.ModelConfig{
	{
		Model: "command",
		Type:  relaymode.ChatCompletions,
		Owner: model.ModelOwnerCohere,
	},
	{
		Model: "command-nightly",
		Type:  relaymode.ChatCompletions,
		Owner: model.ModelOwnerCohere,
	},
	{
		Model: "command-light",
		Type:  relaymode.ChatCompletions,
		Owner: model.ModelOwnerCohere,
	},
	{
		Model: "command-light-nightly",
		Type:  relaymode.ChatCompletions,
		Owner: model.ModelOwnerCohere,
	},
	{
		Model: "command-r",
		Type:  relaymode.ChatCompletions,
		Owner: model.ModelOwnerCohere,
	},
	{
		Model: "command-r-plus",
		Type:  relaymode.ChatCompletions,
		Owner: model.ModelOwnerCohere,
	},
}
View Source
var WebSearchConnector = Connector{ID: "web-search"}

Functions

func Handler

func Handler(c *gin.Context, resp *http.Response, _ 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) ConvertRequest

func (a *Adaptor) ConvertRequest(meta *meta.Meta, req *http.Request) (string, 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) GetBaseURL

func (a *Adaptor) GetBaseURL() string

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, _ *gin.Context, req *http.Request) 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 {
	Text        string   `json:"text"`
	DocumentIDs []string `json:"document_ids"`
	Start       int      `json:"start"`
	End         int      `json:"end"`
}

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 {
	P                *float64      `json:"p,omitempty"`
	Temperature      *float64      `json:"temperature,omitempty"`
	PresencePenalty  *float64      `json:"presence_penalty,omitempty"`
	FrequencyPenalty *float64      `json:"frequency_penalty,omitempty"`
	Model            string        `json:"model,omitempty"`
	Message          string        `json:"message"                     required:"true"`
	Preamble         string        `json:"preamble,omitempty"`
	PromptTruncation string        `json:"prompt_truncation,omitempty"`
	ConversationID   string        `json:"conversation_id,omitempty"`
	StopSequences    []string      `json:"stop_sequences,omitempty"`
	Tools            []Tool        `json:"tools,omitempty"`
	ToolResults      []ToolResult  `json:"tool_results,omitempty"`
	Documents        []Document    `json:"documents,omitempty"`
	Connectors       []Connector   `json:"connectors,omitempty"`
	ChatHistory      []ChatMessage `json:"chat_history,omitempty"`
	K                int           `json:"k,omitempty"`
	MaxInputTokens   int           `json:"max_input_tokens,omitempty"`
	Seed             int           `json:"seed,omitempty"`
	MaxTokens        int           `json:"max_tokens,omitempty"`
	Stream           bool          `json:"stream,omitempty"`
}

func ConvertRequest

func ConvertRequest(textRequest *model.GeneralOpenAIRequest) *Request

type Response

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

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"`
	Connector   *Connector   `json:"connector"`
	DocumentIDs []string     `json:"document_ids"`
}

type StreamResponse

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

type Tool

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

type ToolCall

type ToolCall struct {
	Parameters map[string]interface{} `json:"parameters" required:"true"`
	Name       string                 `json:"name"       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