model-ratio.go 1.4 KB

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