text_response.go 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. package dto
  2. type TextResponseWithError struct {
  3. Id string `json:"id"`
  4. Object string `json:"object"`
  5. Created int64 `json:"created"`
  6. Choices []OpenAITextResponseChoice `json:"choices"`
  7. Data []OpenAIEmbeddingResponseItem `json:"data"`
  8. Model string `json:"model"`
  9. Usage `json:"usage"`
  10. Error OpenAIError `json:"error"`
  11. }
  12. type SimpleResponse struct {
  13. Usage `json:"usage"`
  14. Error OpenAIError `json:"error"`
  15. Choices []OpenAITextResponseChoice `json:"choices"`
  16. }
  17. type TextResponse struct {
  18. Id string `json:"id"`
  19. Object string `json:"object"`
  20. Created int64 `json:"created"`
  21. Model string `json:"model"`
  22. Choices []OpenAITextResponseChoice `json:"choices"`
  23. Usage `json:"usage"`
  24. }
  25. type OpenAITextResponseChoice struct {
  26. Index int `json:"index"`
  27. Message `json:"message"`
  28. FinishReason string `json:"finish_reason"`
  29. }
  30. type OpenAITextResponse struct {
  31. Id string `json:"id"`
  32. Object string `json:"object"`
  33. Created int64 `json:"created"`
  34. Choices []OpenAITextResponseChoice `json:"choices"`
  35. Usage `json:"usage"`
  36. }
  37. type OpenAIEmbeddingResponseItem struct {
  38. Object string `json:"object"`
  39. Index int `json:"index"`
  40. Embedding []float64 `json:"embedding"`
  41. }
  42. type OpenAIEmbeddingResponse struct {
  43. Object string `json:"object"`
  44. Data []OpenAIEmbeddingResponseItem `json:"data"`
  45. Model string `json:"model"`
  46. Usage `json:"usage"`
  47. }
  48. type ChatCompletionsStreamResponseChoice struct {
  49. Delta ChatCompletionsStreamResponseChoiceDelta `json:"delta,omitempty"`
  50. Logprobs *any `json:"logprobs"`
  51. FinishReason *string `json:"finish_reason"`
  52. Index int `json:"index"`
  53. }
  54. type ChatCompletionsStreamResponseChoiceDelta struct {
  55. Content *string `json:"content,omitempty"`
  56. Role string `json:"role,omitempty"`
  57. ToolCalls []ToolCall `json:"tool_calls,omitempty"`
  58. }
  59. func (c *ChatCompletionsStreamResponseChoiceDelta) IsEmpty() bool {
  60. return c.Content == nil && len(c.ToolCalls) == 0
  61. }
  62. func (c *ChatCompletionsStreamResponseChoiceDelta) SetContentString(s string) {
  63. c.Content = &s
  64. }
  65. func (c *ChatCompletionsStreamResponseChoiceDelta) GetContentString() string {
  66. if c.Content == nil {
  67. return ""
  68. }
  69. return *c.Content
  70. }
  71. type ToolCall struct {
  72. // Index is not nil only in chat completion chunk object
  73. Index *int `json:"index,omitempty"`
  74. ID string `json:"id"`
  75. Type any `json:"type"`
  76. Function FunctionCall `json:"function"`
  77. }
  78. type FunctionCall struct {
  79. Name string `json:"name,omitempty"`
  80. // call function with arguments in JSON format
  81. Arguments string `json:"arguments,omitempty"`
  82. }
  83. type ChatCompletionsStreamResponse struct {
  84. Id string `json:"id"`
  85. Object string `json:"object"`
  86. Created int64 `json:"created"`
  87. Model string `json:"model"`
  88. SystemFingerprint *string `json:"system_fingerprint"`
  89. Choices []ChatCompletionsStreamResponseChoice `json:"choices"`
  90. }
  91. type ChatCompletionsStreamResponseSimple struct {
  92. Choices []ChatCompletionsStreamResponseChoice `json:"choices"`
  93. }
  94. type CompletionsStreamResponse struct {
  95. Choices []struct {
  96. Text string `json:"text"`
  97. FinishReason string `json:"finish_reason"`
  98. } `json:"choices"`
  99. }
  100. type Usage struct {
  101. PromptTokens int `json:"prompt_tokens"`
  102. CompletionTokens int `json:"completion_tokens"`
  103. TotalTokens int `json:"total_tokens"`
  104. }