model-ratio.go 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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.05,
  33. "text-search-ada-doc-001": 10,
  34. "text-moderation-stable": 0.1,
  35. "text-moderation-latest": 0.1,
  36. "dall-e": 8,
  37. "claude-instant-1": 0.75,
  38. "claude-2": 30,
  39. }
  40. func ModelRatio2JSONString() string {
  41. jsonBytes, err := json.Marshal(ModelRatio)
  42. if err != nil {
  43. SysError("error marshalling model ratio: " + err.Error())
  44. }
  45. return string(jsonBytes)
  46. }
  47. func UpdateModelRatioByJSONString(jsonStr string) error {
  48. ModelRatio = make(map[string]float64)
  49. return json.Unmarshal([]byte(jsonStr), &ModelRatio)
  50. }
  51. func GetModelRatio(name string) float64 {
  52. ratio, ok := ModelRatio[name]
  53. if !ok {
  54. SysError("model ratio not found: " + name)
  55. return 30
  56. }
  57. return ratio
  58. }