chat.api 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. import "../base.api"
  2. import "../wechat/wxhook.api"
  3. type (
  4. //add_friend_by_phone api接口请求值
  5. AddFriendByPhoneReq {
  6. Type int `json:"type,options=1|3,default=1"`
  7. WeChatIds []string `json:"wechat_ids,optional,omitempty"`
  8. Phones []string `json:"phones"`
  9. Message string `json:"message"`
  10. CallbackURL string `json:"callback_url,optional"`
  11. }
  12. NullReq {
  13. }
  14. //以下是API请求类型
  15. CompApiReq {
  16. CompCtlReq
  17. StdCompApiReq
  18. FastGptSpecReq
  19. }
  20. //FastGpt Completions请求信息
  21. FastGptApiReq {
  22. StdCompApiReq
  23. FastGptSpecReq
  24. }
  25. //标准Completions请求信息
  26. StdCompApiReq {
  27. //model,like 'gpt-4o'
  28. Model string `json:"model,optional"`
  29. //Message list
  30. Messages []StdCompMessage `json:"messages"`
  31. //Stream 是否流式输出
  32. Stream bool `json:"stream,default=false"`
  33. //格式化输出定义
  34. ResponseFormat interface{} `json:"response_format,omitempty"`
  35. }
  36. //关于工作流配置的请求信息
  37. CompCtlReq {
  38. //EventType事件类型
  39. EventType string `json:"event_type,default=fastgpt"`
  40. //WorkId工作流ID
  41. WorkId string `json:"work_id,optional,omitempty"`
  42. //IsBatch 是同步还是异步,默认及取值false表明同步
  43. IsBatch bool `json:"is_batch,default=false"`
  44. //异步回调地址
  45. Callback string `json:"callback,optional,omitempty"`
  46. }
  47. FastGptSpecReq {
  48. //ChatId
  49. ChatId string `json:"chat_id,optional,omitempty"`
  50. //FastgptChatId
  51. FastgptChatId string `json:"chatId,optional,omitempty"`
  52. //ResponseChatItemId
  53. ResponseChatItemId string `json:"response_chat_item_id,optional,omitempty"`
  54. //Detail 详情开关
  55. Detail bool `json:"detail,default=false"`
  56. //Variables
  57. Variables map[string]string `json:"variables,optional,omitempty"`
  58. }
  59. StdCompMessage {
  60. Role string `json:"role"`
  61. Content interface{} `json:"content"`
  62. //Content string `json:"content"`
  63. }
  64. //以下是API响应类型
  65. CompOpenApiResp {
  66. StdCompApiResp
  67. FastgptSpecResp
  68. FastgptErrResp
  69. }
  70. StdCompApiResp {
  71. // A unique identifier for the chat completion.
  72. ID string `json:"id"`
  73. // A list of chat completion choices. Can be more than one if `n` is greater
  74. // than 1.
  75. Choices []ChatCompletionChoice `json:"choices"`
  76. // The Unix timestamp (in seconds) of when the chat completion was created.
  77. Created int64 `json:"created"`
  78. // The model used for the chat completion.
  79. Model string `json:"model"`
  80. // The object type, which is always `chat.completion`.
  81. Object string `json:"object"`
  82. // The service tier used for processing the request.
  83. ServiceTier string `json:"service_tier,omitempty"`
  84. // This fingerprint represents the backend configuration that the model runs with.
  85. //
  86. // Can be used in conjunction with the `seed` request parameter to understand when
  87. // backend changes have been made that might impact determinism.
  88. SystemFingerprint string `json:"system_fingerprint"`
  89. // Usage statistics for the completion request.
  90. Usage CompletionUsage `json:"usage,omitempty"`
  91. }
  92. FastgptSpecResp {
  93. ResponseData []map[string]interface{} `json:"responseData,omitempty"`
  94. NewVariables map[string]interface{} `json:"newVariables,omitempty"`
  95. }
  96. FastgptErrResp {
  97. FgtErrCode *int `json:"code,omitempty"`
  98. FgtErrStatusTxt *string `json:"statusText,omitempty"`
  99. FgtErrMessage *string `json:"message,omitempty"`
  100. }
  101. DeepseekErrResp {
  102. DSErr DeepseekErrInfo `json:"error,omitempty"`
  103. }
  104. DeepseekErrInfo {
  105. Message string `json:"message,omitempty"`
  106. Type string `json:"type,omitempty"`
  107. Code string `json:"code,omitempty"`
  108. Param interface{} `json:"param,omitempty"`
  109. }
  110. ChatCompletionAudio {
  111. // Unique identifier for this audio response.
  112. ID string `json:"id"`
  113. //TODO
  114. }
  115. ChatCompletionMessage {
  116. // The contents of the message.
  117. Content string `json:"content"`
  118. //The contents of the reasoning message
  119. ReasoningContent string `json:"reasoning_content,omitempty"`
  120. // The refusal message generated by the model.
  121. Refusal string `json:"refusal"`
  122. // The role of the author of this message.
  123. Role string `json:"role"`
  124. // If the audio output modality is requested, this object contains data about the
  125. // audio response from the model.
  126. // [Learn more](https://platform.openai.com/docs/guides/audio).
  127. Audio ChatCompletionAudio `json:"audio,omitempty"`
  128. }
  129. ChatCompletionChoice {
  130. // The reason the model stopped generating tokens. This will be `stop` if the model
  131. // hit a natural stop point or a provided stop sequence, `length` if the maximum
  132. // number of tokens specified in the request was reached, `content_filter` if
  133. // content was omitted due to a flag from our content filters, `tool_calls` if the
  134. // model called a tool, or `function_call` (deprecated) if the model called a
  135. // function.
  136. FinishReason string `json:"finish_reason"`
  137. // The index of the choice in the list of choices.
  138. Index int64 `json:"index"`
  139. // A chat completion message generated by the model.
  140. Message ChatCompletionMessage `json:"message,omitempty"`
  141. // A chat completion message generated by the model stream mode.
  142. Delta ChatCompletionMessage `json:"delta,omitempty"`
  143. //
  144. Logprobs string `json:"logprobs"`
  145. }
  146. CompletionUsageCompletionTokensDetails {
  147. // When using Predicted Outputs, the number of tokens in the prediction that
  148. // appeared in the completion.
  149. AcceptedPredictionTokens int64 `json:"accepted_prediction_tokens"`
  150. // Audio input tokens generated by the model.
  151. AudioTokens int64 `json:"audio_tokens"`
  152. // Tokens generated by the model for reasoning.
  153. ReasoningTokens int64 `json:"reasoning_tokens"`
  154. // When using Predicted Outputs, the number of tokens in the prediction that did
  155. // not appear in the completion. However, like reasoning tokens, these tokens are
  156. // still counted in the total completion tokens for purposes of billing, output,
  157. // and context window limits.
  158. RejectedPredictionTokens int64 `json:"rejected_prediction_tokens"`
  159. }
  160. CompletionUsagePromptTokensDetails {
  161. // Audio input tokens present in the prompt.
  162. AudioTokens int64 `json:"audio_tokens"`
  163. // Cached tokens present in the prompt.
  164. CachedTokens int64 `json:"cached_tokens"`
  165. }
  166. CompletionUsage {
  167. // Number of tokens in the generated completion.
  168. CompletionTokens int64 `json:"completion_tokens,required"`
  169. // Number of tokens in the prompt.
  170. PromptTokens int64 `json:"prompt_tokens,required"`
  171. // Total number of tokens used in the request (prompt + completion).
  172. TotalTokens int64 `json:"total_tokens,required"`
  173. // Breakdown of tokens used in a completion.
  174. CompletionTokensDetails CompletionUsageCompletionTokensDetails `json:"completion_tokens_details"`
  175. // Breakdown of tokens used in the prompt.
  176. PromptTokensDetails CompletionUsagePromptTokensDetails `json:"prompt_tokens_details"`
  177. }
  178. )
  179. @server(
  180. group: chat
  181. prefix: /v1
  182. )
  183. service Wechat {
  184. @handler getAuth
  185. get /chat/getauth (NullReq) returns (BaseMsgResp)
  186. }
  187. @server(
  188. group: chat
  189. prefix: /v1
  190. //jwt: Auth
  191. middleware: OpenAuthority
  192. )
  193. service Wechat {
  194. @handler chatCompletions
  195. post /chat/completions (CompApiReq) returns (CompOpenApiResp)
  196. }
  197. @server(
  198. group: chat
  199. middleware: OpenAuthority
  200. )
  201. service Wechat {
  202. @handler sendTextMsg
  203. post /wx/sendTextMsg (SendTextMsgReq) returns (BaseMsgResp)
  204. @handler AddFriendByPhone
  205. post /wx/add_friend_by_phone (AddFriendByPhoneReq) returns (BaseMsgResp)
  206. }