dto.go 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. package tencent
  2. import "one-api/dto"
  3. type TencentMessage struct {
  4. Role string `json:"role"`
  5. Content string `json:"content"`
  6. }
  7. type TencentChatRequest struct {
  8. AppId int64 `json:"app_id"` // 腾讯云账号的 APPID
  9. SecretId string `json:"secret_id"` // 官网 SecretId
  10. // Timestamp当前 UNIX 时间戳,单位为秒,可记录发起 API 请求的时间。
  11. // 例如1529223702,如果与当前时间相差过大,会引起签名过期错误
  12. Timestamp int64 `json:"timestamp"`
  13. // Expired 签名的有效期,是一个符合 UNIX Epoch 时间戳规范的数值,
  14. // 单位为秒;Expired 必须大于 Timestamp 且 Expired-Timestamp 小于90天
  15. Expired int64 `json:"expired"`
  16. QueryID string `json:"query_id"` //请求 Id,用于问题排查
  17. // Temperature 较高的数值会使输出更加随机,而较低的数值会使其更加集中和确定
  18. // 默认 1.0,取值区间为[0.0,2.0],非必要不建议使用,不合理的取值会影响效果
  19. // 建议该参数和 top_p 只设置1个,不要同时更改 top_p
  20. Temperature float64 `json:"temperature"`
  21. // TopP 影响输出文本的多样性,取值越大,生成文本的多样性越强
  22. // 默认1.0,取值区间为[0.0, 1.0],非必要不建议使用, 不合理的取值会影响效果
  23. // 建议该参数和 temperature 只设置1个,不要同时更改
  24. TopP float64 `json:"top_p"`
  25. // Stream 0:同步,1:流式 (默认,协议:SSE)
  26. // 同步请求超时:60s,如果内容较长建议使用流式
  27. Stream int `json:"stream"`
  28. // Messages 会话内容, 长度最多为40, 按对话时间从旧到新在数组中排列
  29. // 输入 content 总数最大支持 3000 token。
  30. Messages []TencentMessage `json:"messages"`
  31. }
  32. type TencentError struct {
  33. Code int `json:"code"`
  34. Message string `json:"message"`
  35. }
  36. type TencentUsage struct {
  37. InputTokens int `json:"input_tokens"`
  38. OutputTokens int `json:"output_tokens"`
  39. TotalTokens int `json:"total_tokens"`
  40. }
  41. type TencentResponseChoices struct {
  42. FinishReason string `json:"finish_reason,omitempty"` // 流式结束标志位,为 stop 则表示尾包
  43. Messages TencentMessage `json:"messages,omitempty"` // 内容,同步模式返回内容,流模式为 null 输出 content 内容总数最多支持 1024token。
  44. Delta TencentMessage `json:"delta,omitempty"` // 内容,流模式返回内容,同步模式为 null 输出 content 内容总数最多支持 1024token。
  45. }
  46. type TencentChatResponse struct {
  47. Choices []TencentResponseChoices `json:"choices,omitempty"` // 结果
  48. Created string `json:"created,omitempty"` // unix 时间戳的字符串
  49. Id string `json:"id,omitempty"` // 会话 id
  50. Usage dto.Usage `json:"usage,omitempty"` // token 数量
  51. Error TencentError `json:"error,omitempty"` // 错误信息 注意:此字段可能返回 null,表示取不到有效值
  52. Note string `json:"note,omitempty"` // 注释
  53. ReqID string `json:"req_id,omitempty"` // 唯一请求 Id,每次请求都会返回。用于反馈接口入参
  54. }