model-ratio.go 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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-0613": 15,
  10. "gpt-4-32k": 30,
  11. "gpt-4-32k-0314": 30,
  12. "gpt-4-32k-0613": 30,
  13. "gpt-3.5-turbo": 1, // $0.002 / 1K tokens
  14. "gpt-3.5-turbo-0301": 1,
  15. "gpt-3.5-turbo-0613": 1,
  16. "gpt-3.5-turbo-16k": 2, // $0.004 / 1K tokens
  17. "gpt-3.5-turbo-16k-0613": 2,
  18. "text-ada-001": 0.2,
  19. "text-babbage-001": 0.25,
  20. "text-curie-001": 1,
  21. "text-davinci-002": 10,
  22. "text-davinci-003": 10,
  23. "text-davinci-edit-001": 10,
  24. "code-davinci-edit-001": 10,
  25. "whisper-1": 10,
  26. "davinci": 10,
  27. "curie": 10,
  28. "babbage": 10,
  29. "ada": 10,
  30. "text-embedding-ada-002": 0.2,
  31. "text-search-ada-doc-001": 10,
  32. "text-moderation-stable": 0.1,
  33. "text-moderation-latest": 0.1,
  34. }
  35. func ModelRatio2JSONString() string {
  36. jsonBytes, err := json.Marshal(ModelRatio)
  37. if err != nil {
  38. SysError("Error marshalling model ratio: " + err.Error())
  39. }
  40. return string(jsonBytes)
  41. }
  42. func UpdateModelRatioByJSONString(jsonStr string) error {
  43. ModelRatio = make(map[string]float64)
  44. return json.Unmarshal([]byte(jsonStr), &ModelRatio)
  45. }
  46. func GetModelRatio(name string) float64 {
  47. ratio, ok := ModelRatio[name]
  48. if !ok {
  49. SysError("Model ratio not found: " + name)
  50. return 1
  51. }
  52. return ratio
  53. }