model-ratio.go 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. var ModelRatio = map[string]float64{
  10. "gpt-4": 15,
  11. "gpt-4-0314": 15,
  12. "gpt-4-0613": 15,
  13. "gpt-4-32k": 30,
  14. "gpt-4-32k-0314": 30,
  15. "gpt-4-32k-0613": 30,
  16. "gpt-3.5-turbo": 0.75, // $0.0015 / 1K tokens
  17. "gpt-3.5-turbo-0301": 0.75,
  18. "gpt-3.5-turbo-0613": 0.75,
  19. "gpt-3.5-turbo-16k": 1.5, // $0.003 / 1K tokens
  20. "gpt-3.5-turbo-16k-0613": 1.5,
  21. "text-ada-001": 0.2,
  22. "text-babbage-001": 0.25,
  23. "text-curie-001": 1,
  24. "text-davinci-002": 10,
  25. "text-davinci-003": 10,
  26. "text-davinci-edit-001": 10,
  27. "code-davinci-edit-001": 10,
  28. "whisper-1": 10,
  29. "davinci": 10,
  30. "curie": 10,
  31. "babbage": 10,
  32. "ada": 10,
  33. "text-embedding-ada-002": 0.05,
  34. "text-search-ada-doc-001": 10,
  35. "text-moderation-stable": 0.1,
  36. "text-moderation-latest": 0.1,
  37. "dall-e": 8,
  38. "claude-instant-1": 0.75,
  39. "claude-2": 30,
  40. "ERNIE-Bot": 1, // 0.012元/千tokens
  41. "ERNIE-Bot-turbo": 0.67, // 0.008元/千tokens
  42. "PaLM-2": 1,
  43. }
  44. func ModelRatio2JSONString() string {
  45. jsonBytes, err := json.Marshal(ModelRatio)
  46. if err != nil {
  47. SysError("error marshalling model ratio: " + err.Error())
  48. }
  49. return string(jsonBytes)
  50. }
  51. func UpdateModelRatioByJSONString(jsonStr string) error {
  52. ModelRatio = make(map[string]float64)
  53. return json.Unmarshal([]byte(jsonStr), &ModelRatio)
  54. }
  55. func GetModelRatio(name string) float64 {
  56. ratio, ok := ModelRatio[name]
  57. if !ok {
  58. SysError("model ratio not found: " + name)
  59. return 30
  60. }
  61. return ratio
  62. }