text_response.go 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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. Model string `json:"model"`
  33. Object string `json:"object"`
  34. Created int64 `json:"created"`
  35. Choices []OpenAITextResponseChoice `json:"choices"`
  36. Usage `json:"usage"`
  37. }
  38. type OpenAIEmbeddingResponseItem struct {
  39. Object string `json:"object"`
  40. Index int `json:"index"`
  41. Embedding []float64 `json:"embedding"`
  42. }
  43. type OpenAIEmbeddingResponse struct {
  44. Object string `json:"object"`
  45. Data []OpenAIEmbeddingResponseItem `json:"data"`
  46. Model string `json:"model"`
  47. Usage `json:"usage"`
  48. }
  49. type ChatCompletionsStreamResponseChoice struct {
  50. Delta ChatCompletionsStreamResponseChoiceDelta `json:"delta,omitempty"`
  51. Logprobs *any `json:"logprobs"`
  52. FinishReason *string `json:"finish_reason"`
  53. Index int `json:"index"`
  54. }
  55. type ChatCompletionsStreamResponseChoiceDelta struct {
  56. Content *string `json:"content,omitempty"`
  57. Role string `json:"role,omitempty"`
  58. ToolCalls []ToolCall `json:"tool_calls,omitempty"`
  59. }
  60. func (c *ChatCompletionsStreamResponseChoiceDelta) SetContentString(s string) {
  61. c.Content = &s
  62. }
  63. func (c *ChatCompletionsStreamResponseChoiceDelta) GetContentString() string {
  64. if c.Content == nil {
  65. return ""
  66. }
  67. return *c.Content
  68. }
  69. type ToolCall struct {
  70. // Index is not nil only in chat completion chunk object
  71. Index *int `json:"index,omitempty"`
  72. ID string `json:"id"`
  73. Type any `json:"type"`
  74. Function FunctionCall `json:"function"`
  75. }
  76. type FunctionCall struct {
  77. Description string `json:"description,omitempty"`
  78. Name string `json:"name,omitempty"`
  79. // call function with arguments in JSON format
  80. Parameters any `json:"parameters,omitempty"` // request
  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. Usage *Usage `json:"usage"`
  91. }
  92. func (c *ChatCompletionsStreamResponse) GetSystemFingerprint() string {
  93. if c.SystemFingerprint == nil {
  94. return ""
  95. }
  96. return *c.SystemFingerprint
  97. }
  98. func (c *ChatCompletionsStreamResponse) SetSystemFingerprint(s string) {
  99. c.SystemFingerprint = &s
  100. }
  101. type ChatCompletionsStreamResponseSimple struct {
  102. Choices []ChatCompletionsStreamResponseChoice `json:"choices"`
  103. Usage *Usage `json:"usage"`
  104. }
  105. type CompletionsStreamResponse struct {
  106. Choices []struct {
  107. Text string `json:"text"`
  108. FinishReason string `json:"finish_reason"`
  109. } `json:"choices"`
  110. }
  111. type Usage struct {
  112. PromptTokens int `json:"prompt_tokens"`
  113. CompletionTokens int `json:"completion_tokens"`
  114. TotalTokens int `json:"total_tokens"`
  115. }