model-ratio.go 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. package common
  2. import "encoding/json"
  3. // ModelRatio
  4. // https://platform.openai.com/docs/models/model-endpoint-compatibility
  5. // https://cloud.baidu.com/doc/WENXINWORKSHOP/s/Blfmc9dlf
  6. // https://openai.com/pricing
  7. // TODO: when a new api is enabled, check the pricing here
  8. // 1 === $0.002 / 1K tokens
  9. // 1 === ¥0.014 / 1k tokens
  10. var ModelRatio = map[string]float64{
  11. "gpt-4": 15,
  12. "gpt-4-0314": 15,
  13. "gpt-4-0613": 15,
  14. "gpt-4-32k": 30,
  15. "gpt-4-32k-0314": 30,
  16. "gpt-4-32k-0613": 30,
  17. "gpt-3.5-turbo": 0.75, // $0.0015 / 1K tokens
  18. "gpt-3.5-turbo-0301": 0.75,
  19. "gpt-3.5-turbo-0613": 0.75,
  20. "gpt-3.5-turbo-16k": 1.5, // $0.003 / 1K tokens
  21. "gpt-3.5-turbo-16k-0613": 1.5,
  22. "text-ada-001": 0.2,
  23. "text-babbage-001": 0.25,
  24. "text-curie-001": 1,
  25. "text-davinci-002": 10,
  26. "text-davinci-003": 10,
  27. "text-davinci-edit-001": 10,
  28. "code-davinci-edit-001": 10,
  29. "whisper-1": 10,
  30. "davinci": 10,
  31. "curie": 10,
  32. "babbage": 10,
  33. "ada": 10,
  34. "text-embedding-ada-002": 0.05,
  35. "text-search-ada-doc-001": 10,
  36. "text-moderation-stable": 0.1,
  37. "text-moderation-latest": 0.1,
  38. "dall-e": 8,
  39. "claude-instant-1": 0.75,
  40. "claude-2": 30,
  41. "ERNIE-Bot": 0.8572, // ¥0.012 / 1k tokens
  42. "ERNIE-Bot-turbo": 0.5715, // ¥0.008 / 1k tokens
  43. "PaLM-2": 1,
  44. "chatglm_pro": 0.7143, // ¥0.01 / 1k tokens
  45. "chatglm_std": 0.3572, // ¥0.005 / 1k tokens
  46. "chatglm_lite": 0.1429, // ¥0.002 / 1k tokens
  47. }
  48. func ModelRatio2JSONString() string {
  49. jsonBytes, err := json.Marshal(ModelRatio)
  50. if err != nil {
  51. SysError("error marshalling model ratio: " + err.Error())
  52. }
  53. return string(jsonBytes)
  54. }
  55. func UpdateModelRatioByJSONString(jsonStr string) error {
  56. ModelRatio = make(map[string]float64)
  57. return json.Unmarshal([]byte(jsonStr), &ModelRatio)
  58. }
  59. func GetModelRatio(name string) float64 {
  60. ratio, ok := ModelRatio[name]
  61. if !ok {
  62. SysError("model ratio not found: " + name)
  63. return 30
  64. }
  65. return ratio
  66. }