model-ratio.go 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. package common
  2. import "encoding/json"
  3. // ModelRatio
  4. // https://platform.openai.com/docs/models/model-endpoint-compatibility
  5. // https://openai.com/pricing
  6. // TODO: when a new api is enabled, check the pricing here
  7. // 1 === $0.002 / 1K tokens
  8. var ModelRatio = map[string]float64{
  9. "gpt-4": 15,
  10. "gpt-4-0314": 15,
  11. "gpt-4-0613": 15,
  12. "gpt-4-32k": 30,
  13. "gpt-4-32k-0314": 30,
  14. "gpt-4-32k-0613": 30,
  15. "gpt-3.5-turbo": 0.75, // $0.0015 / 1K tokens
  16. "gpt-3.5-turbo-0301": 0.75,
  17. "gpt-3.5-turbo-0613": 0.75,
  18. "gpt-3.5-turbo-16k": 1.5, // $0.003 / 1K tokens
  19. "gpt-3.5-turbo-16k-0613": 1.5,
  20. "text-ada-001": 0.2,
  21. "text-babbage-001": 0.25,
  22. "text-curie-001": 1,
  23. "text-davinci-002": 10,
  24. "text-davinci-003": 10,
  25. "text-davinci-edit-001": 10,
  26. "code-davinci-edit-001": 10,
  27. "whisper-1": 10,
  28. "davinci": 10,
  29. "curie": 10,
  30. "babbage": 10,
  31. "ada": 10,
  32. "text-embedding-ada-002": 0.2,
  33. "text-search-ada-doc-001": 10,
  34. "text-moderation-stable": 0.1,
  35. "text-moderation-latest": 0.1,
  36. }
  37. func ModelRatio2JSONString() string {
  38. jsonBytes, err := json.Marshal(ModelRatio)
  39. if err != nil {
  40. SysError("Error marshalling model ratio: " + err.Error())
  41. }
  42. return string(jsonBytes)
  43. }
  44. func UpdateModelRatioByJSONString(jsonStr string) error {
  45. ModelRatio = make(map[string]float64)
  46. return json.Unmarshal([]byte(jsonStr), &ModelRatio)
  47. }
  48. func GetModelRatio(name string) float64 {
  49. ratio, ok := ModelRatio[name]
  50. if !ok {
  51. SysError("Model ratio not found: " + name)
  52. return 1
  53. }
  54. return ratio
  55. }