mirror of
https://github.com/songquanpeng/one-api.git
synced 2025-11-10 02:23:43 +08:00
fix: translate error messages and comments to English for consistency
This commit is contained in:
@@ -38,7 +38,7 @@ func aiProxyDocuments2Markdown(documents []LibraryDocument) string {
|
||||
if len(documents) == 0 {
|
||||
return ""
|
||||
}
|
||||
content := "\n\n参考文档:\n"
|
||||
content := "\n\nReference Documents:\n"
|
||||
for i, document := range documents {
|
||||
content += fmt.Sprintf("%d. [%s](%s)\n", i+1, document.Title, document.URL)
|
||||
}
|
||||
|
||||
@@ -148,18 +148,18 @@ func responseAli2OpenAIImage(response *TaskResponse, responseFormat string) *ope
|
||||
for _, data := range response.Output.Results {
|
||||
var b64Json string
|
||||
if responseFormat == "b64_json" {
|
||||
// 读取 data.Url 的图片数据并转存到 b64Json
|
||||
// Read the image data from data.Url and store it in b64Json
|
||||
imageData, err := getImageData(data.Url)
|
||||
if err != nil {
|
||||
// 处理获取图片数据失败的情况
|
||||
// Handle the case where getting image data fails
|
||||
logger.SysError("getImageData Error getting image data: " + err.Error())
|
||||
continue
|
||||
}
|
||||
|
||||
// 将图片数据转为 Base64 编码的字符串
|
||||
// Convert the image data to a Base64 encoded string
|
||||
b64Json = Base64Encode(imageData)
|
||||
} else {
|
||||
// 如果 responseFormat 不是 "b64_json",则直接使用 data.B64Image
|
||||
// If responseFormat is not "b64_json", use data.B64Image directly
|
||||
b64Json = data.B64Image
|
||||
}
|
||||
|
||||
|
||||
@@ -2,23 +2,23 @@ package cohere
|
||||
|
||||
type Request struct {
|
||||
Message string `json:"message" required:"true"`
|
||||
Model string `json:"model,omitempty"` // Default值为"command-r"
|
||||
Stream bool `json:"stream,omitempty"` // Default值为false
|
||||
Model string `json:"model,omitempty"` // default to "command-r"
|
||||
Stream bool `json:"stream,omitempty"` // default to false
|
||||
Preamble string `json:"preamble,omitempty"`
|
||||
ChatHistory []ChatMessage `json:"chat_history,omitempty"`
|
||||
ConversationID string `json:"conversation_id,omitempty"`
|
||||
PromptTruncation string `json:"prompt_truncation,omitempty"` // Default值为"AUTO"
|
||||
PromptTruncation string `json:"prompt_truncation,omitempty"` // default to "AUTO"
|
||||
Connectors []Connector `json:"connectors,omitempty"`
|
||||
Documents []Document `json:"documents,omitempty"`
|
||||
Temperature *float64 `json:"temperature,omitempty"` // Default值为0.3
|
||||
Temperature *float64 `json:"temperature,omitempty"` // default to 0.3
|
||||
MaxTokens int `json:"max_tokens,omitempty"`
|
||||
MaxInputTokens int `json:"max_input_tokens,omitempty"`
|
||||
K int `json:"k,omitempty"` // Default值为0
|
||||
P *float64 `json:"p,omitempty"` // Default值为0.75
|
||||
K int `json:"k,omitempty"` // default to 0
|
||||
P *float64 `json:"p,omitempty"` // default to 0.75
|
||||
Seed int `json:"seed,omitempty"`
|
||||
StopSequences []string `json:"stop_sequences,omitempty"`
|
||||
FrequencyPenalty *float64 `json:"frequency_penalty,omitempty"` // Default值为0.0
|
||||
PresencePenalty *float64 `json:"presence_penalty,omitempty"` // Default值为0.0
|
||||
FrequencyPenalty *float64 `json:"frequency_penalty,omitempty"` // default to 0.0
|
||||
PresencePenalty *float64 `json:"presence_penalty,omitempty"` // default to 0.0
|
||||
Tools []Tool `json:"tools,omitempty"`
|
||||
ToolResults []ToolResult `json:"tool_results,omitempty"`
|
||||
}
|
||||
|
||||
@@ -6,40 +6,46 @@ type Message struct {
|
||||
}
|
||||
|
||||
type ChatRequest struct {
|
||||
// Model name,Optional values包括 hunyuan-lite、hunyuan-standard、hunyuan-standard-256K、hunyuan-pro。
|
||||
// 各Model介绍请阅读 [产品概述](https://cloud.tencent.com/document/product/1729/104753) 中的说明。
|
||||
// Model name, optional values include hunyuan-lite, hunyuan-standard, hunyuan-standard-256K, hunyuan-pro.
|
||||
// For descriptions of each model, please read the [Product Overview](https://cloud.tencent.com/document/product/1729/104753).
|
||||
//
|
||||
// Note:
|
||||
// 不同的Model计费不同,请根据 [购买指南](https://cloud.tencent.com/document/product/1729/97731) 按需调用。
|
||||
// Note:
|
||||
// Different models have different pricing. Please refer to the [Purchase Guide](https://cloud.tencent.com/document/product/1729/97731) for details.
|
||||
Model *string `json:"Model"`
|
||||
// Chat上下文信息。
|
||||
// 说明:
|
||||
// 1. 长度最多为 40,按对话Time从旧到新在数Group中排列。
|
||||
// 2. Message.Role Optional values:system、user、assistant。
|
||||
// 其中,system 角色可选,如存在则必须位于列表的最开始。user 和 assistant 需交替出现(一问一答),以 user 提问开始和结束,且 Content 不能为空。Role 的顺序示例:[system(可选) user assistant user assistant user ...]。
|
||||
// 3. Messages 中 Content 总长度不能超过ModelEnter长度上限(可参考 [产品概述](https://cloud.tencent.com/document/product/1729/104753) 文档),超过则会截断最前面的内容,只保留尾部内容。
|
||||
// Chat context information.
|
||||
// Description:
|
||||
// 1. The maximum length is 40, arranged in the array in chronological order from oldest to newest.
|
||||
// 2. Message.Role optional values: system, user, assistant.
|
||||
// Among them, the system role is optional. If it exists, it must be at the beginning of the list.
|
||||
// User and assistant must alternate (one question and one answer), starting and ending with user,
|
||||
// and Content cannot be empty. The order of roles is as follows: [system (optional) user assistant user assistant user ...].
|
||||
// 3. The total length of Content in Messages cannot exceed the model's length limit
|
||||
// (refer to the [Product Overview](https://cloud.tencent.com/document/product/1729/104753) document).
|
||||
// If it exceeds, the earliest content will be truncated, leaving only the latest content.
|
||||
Messages []*Message `json:"Messages"`
|
||||
// 流式调用开关。
|
||||
// 说明:
|
||||
// 1. 未传值时Default为非流式调用(false)。
|
||||
// 2. 流式调用时以 SSE 协议增量返回结果(返回值取 Choices[n].Delta 中的值,需要拼接增量数据才能获得完整结果)。
|
||||
// 3. 非流式调用时:
|
||||
// 调用方式与普通 HTTP 请求None异。
|
||||
// 接口响应耗时较长,**如需更低时延建议Settings为 true**。
|
||||
// 只返回一次最终结果(返回值取 Choices[n].Message 中的值)。
|
||||
// Stream call switch.
|
||||
// Description:
|
||||
// 1. If not provided, the default is non-streaming call (false).
|
||||
// 2. In streaming calls, results are returned incrementally using the SSE protocol
|
||||
// (the return value is taken from Choices[n].Delta, and incremental data needs to be concatenated to obtain the complete result).
|
||||
// 3. In non-streaming calls:
|
||||
// The call method is the same as a regular HTTP request.
|
||||
// The interface response time is relatively long. **If lower latency is required, it is recommended to set this to true**.
|
||||
// Only the final result is returned once (the return value is taken from Choices[n].Message).
|
||||
//
|
||||
// Note:
|
||||
// 通过 SDK 调用时,流式和非流式调用需用**不同的方式**获取返回值,具体参考 SDK 中的注释或示例(在各语言 SDK 代码仓库的 examples/hunyuan/v20230901/ 目录中)。
|
||||
// Note:
|
||||
// When calling through the SDK, different methods are required to obtain return values for streaming and non-streaming calls.
|
||||
// Refer to the comments or examples in the SDK (in the examples/hunyuan/v20230901/ directory of each language SDK code repository).
|
||||
Stream *bool `json:"Stream"`
|
||||
// 说明:
|
||||
// 1. 影响输出文本的多样性,取值越大,生成文本的多样性越强。
|
||||
// 2. 取值区间为 [0.0, 1.0],未传值时使用各Model推荐值。
|
||||
// 3. 非必要不建议使用,不合理的取值会影响效果。
|
||||
// Description:
|
||||
// 1. Affects the diversity of the output text. The larger the value, the more diverse the generated text.
|
||||
// 2. The value range is [0.0, 1.0]. If not provided, the recommended value for each model is used.
|
||||
// 3. It is not recommended to use this unless necessary, as unreasonable values can affect the results.
|
||||
TopP *float64 `json:"TopP"`
|
||||
// 说明:
|
||||
// 1. 较高的数值会使输出更加随机,而较低的数值会使其更加集中和确定。
|
||||
// 2. 取值区间为 [0.0, 2.0],未传值时使用各Model推荐值。
|
||||
// 3. 非必要不建议使用,不合理的取值会影响效果。
|
||||
// Description:
|
||||
// 1. Higher values make the output more random, while lower values make it more focused and deterministic.
|
||||
// 2. The value range is [0.0, 2.0]. If not provided, the recommended value for each model is used.
|
||||
// 3. It is not recommended to use this unless necessary, as unreasonable values can affect the results.
|
||||
Temperature *float64 `json:"Temperature"`
|
||||
}
|
||||
|
||||
@@ -55,19 +61,19 @@ type Usage struct {
|
||||
}
|
||||
|
||||
type ResponseChoices struct {
|
||||
FinishReason string `json:"FinishReason,omitempty"` // 流式结束标志位,为 stop 则表示尾包
|
||||
Messages Message `json:"Message,omitempty"` // 内容,同步模式返回内容,流模式为 null 输出 content 内容总数最多支持 1024token。
|
||||
Delta Message `json:"Delta,omitempty"` // 内容,流模式返回内容,同步模式为 null 输出 content 内容总数最多支持 1024token。
|
||||
FinishReason string `json:"FinishReason,omitempty"` // Stream end flag, "stop" indicates the end packet
|
||||
Messages Message `json:"Message,omitempty"` // Content, returned in synchronous mode, null in stream mode. The total content supports up to 1024 tokens.
|
||||
Delta Message `json:"Delta,omitempty"` // Content, returned in stream mode, null in synchronous mode. The total content supports up to 1024 tokens.
|
||||
}
|
||||
|
||||
type ChatResponse struct {
|
||||
Choices []ResponseChoices `json:"Choices,omitempty"` // 结果
|
||||
Created int64 `json:"Created,omitempty"` // unix Time戳的字符串
|
||||
Id string `json:"Id,omitempty"` // 会话 id
|
||||
Usage Usage `json:"Usage,omitempty"` // token 数量
|
||||
Error Error `json:"Error,omitempty"` // 错误信息 Note:此字段可能返回 null,表示取不到有效值
|
||||
Note string `json:"Note,omitempty"` // 注释
|
||||
ReqID string `json:"Req_id,omitempty"` // 唯一请求 Id,每次请求都会返回。用于反馈接口入参
|
||||
Choices []ResponseChoices `json:"Choices,omitempty"` // Results
|
||||
Created int64 `json:"Created,omitempty"` // Unix timestamp string
|
||||
Id string `json:"Id,omitempty"` // Session ID
|
||||
Usage Usage `json:"Usage,omitempty"` // Token count
|
||||
Error Error `json:"Error,omitempty"` // Error information. Note: This field may return null, indicating that no valid value was found.
|
||||
Note string `json:"Note,omitempty"` // Note
|
||||
ReqID string `json:"Req_id,omitempty"` // Unique request ID, returned with each request. Used for feedback on interface input parameters.
|
||||
}
|
||||
|
||||
type ChatResponseP struct {
|
||||
|
||||
@@ -385,8 +385,9 @@ func GetAudioCompletionRatio(actualModelName string) float64 {
|
||||
|
||||
// AudioTokensPerSecond is the number of audio tokens per second for each model.
|
||||
var AudioPromptTokensPerSecond = map[string]float64{
|
||||
// whisper 的 API 价格是 $0.0001/sec。one-api 的历史倍率为 15,对应 $0.03/kilo_tokens。
|
||||
// 那么换算后可得,每秒的 tokens 应该为 0.0001/0.03*1000 = 3.3333
|
||||
// Whisper API price is $0.0001/sec. One-api's historical ratio is 15,
|
||||
// corresponding to $0.03/kilo_tokens.
|
||||
// After conversion, tokens per second should be 0.0001/0.03*1000 = 3.3333.
|
||||
"whisper-1": 0.0001 / 0.03 * 1000,
|
||||
// gpt-4o-audio series processes 10 tokens per second
|
||||
"gpt-4o-audio-preview": 10,
|
||||
|
||||
@@ -125,7 +125,7 @@ func postConsumeQuota(ctx context.Context, usage *relaymodel.Usage, meta *meta.M
|
||||
}
|
||||
var extraLog string
|
||||
if systemPromptReset {
|
||||
extraLog = " (NoteSystemPrompt词已被重置)"
|
||||
extraLog = " (Note: System prompt has been reset)"
|
||||
}
|
||||
logContent := fmt.Sprintf("model rate %.2f, group rate %.2f, completion rate %.2f%s", modelRatio, groupRatio, completionRatio, extraLog)
|
||||
model.RecordConsumeLog(ctx, meta.UserId, meta.ChannelId, promptTokens, completionTokens, textRequest.Model, meta.TokenName, quota, logContent)
|
||||
|
||||
Reference in New Issue
Block a user