endpoint_defaults.go 1.3 KB

1234567891011121314151617181920212223242526272829303132
  1. package common
  2. import "one-api/constant"
  3. // EndpointInfo 描述单个端点的默认请求信息
  4. // path: 上游路径
  5. // method: HTTP 请求方式,例如 POST/GET
  6. // 目前均为 POST,后续可扩展
  7. //
  8. // json 标签用于直接序列化到 API 输出
  9. // 例如:{"path":"/v1/chat/completions","method":"POST"}
  10. type EndpointInfo struct {
  11. Path string `json:"path"`
  12. Method string `json:"method"`
  13. }
  14. // defaultEndpointInfoMap 保存内置端点的默认 Path 与 Method
  15. var defaultEndpointInfoMap = map[constant.EndpointType]EndpointInfo{
  16. constant.EndpointTypeOpenAI: {Path: "/v1/chat/completions", Method: "POST"},
  17. constant.EndpointTypeOpenAIResponse: {Path: "/v1/responses", Method: "POST"},
  18. constant.EndpointTypeAnthropic: {Path: "/v1/messages", Method: "POST"},
  19. constant.EndpointTypeGemini: {Path: "/v1beta/models/{model}:generateContent", Method: "POST"},
  20. constant.EndpointTypeJinaRerank: {Path: "/rerank", Method: "POST"},
  21. constant.EndpointTypeImageGeneration: {Path: "/v1/images/generations", Method: "POST"},
  22. }
  23. // GetDefaultEndpointInfo 返回指定端点类型的默认信息以及是否存在
  24. func GetDefaultEndpointInfo(et constant.EndpointType) (EndpointInfo, bool) {
  25. info, ok := defaultEndpointInfoMap[et]
  26. return info, ok
  27. }