openai_response.go 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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. ReasoningContent *string `json:"reasoning_content,omitempty"`
  58. Role string `json:"role,omitempty"`
  59. ToolCalls []ToolCall `json:"tool_calls,omitempty"`
  60. }
  61. func (c *ChatCompletionsStreamResponseChoiceDelta) SetContentString(s string) {
  62. c.Content = &s
  63. }
  64. func (c *ChatCompletionsStreamResponseChoiceDelta) GetContentString() string {
  65. if c.Content == nil {
  66. return ""
  67. }
  68. return *c.Content
  69. }
  70. func (c *ChatCompletionsStreamResponseChoiceDelta) GetReasoningContent() string {
  71. if c.ReasoningContent == nil {
  72. return ""
  73. }
  74. return *c.ReasoningContent
  75. }
  76. type ToolCall struct {
  77. // Index is not nil only in chat completion chunk object
  78. Index *int `json:"index,omitempty"`
  79. ID string `json:"id,omitempty"`
  80. Type any `json:"type"`
  81. Function FunctionCall `json:"function"`
  82. }
  83. func (c *ToolCall) SetIndex(i int) {
  84. c.Index = &i
  85. }
  86. type FunctionCall struct {
  87. Description string `json:"description,omitempty"`
  88. Name string `json:"name,omitempty"`
  89. // call function with arguments in JSON format
  90. Parameters any `json:"parameters,omitempty"` // request
  91. Arguments string `json:"arguments,omitempty"`
  92. }
  93. type ChatCompletionsStreamResponse struct {
  94. Id string `json:"id"`
  95. Object string `json:"object"`
  96. Created int64 `json:"created"`
  97. Model string `json:"model"`
  98. SystemFingerprint *string `json:"system_fingerprint"`
  99. Choices []ChatCompletionsStreamResponseChoice `json:"choices"`
  100. Usage *Usage `json:"usage"`
  101. }
  102. func (c *ChatCompletionsStreamResponse) GetSystemFingerprint() string {
  103. if c.SystemFingerprint == nil {
  104. return ""
  105. }
  106. return *c.SystemFingerprint
  107. }
  108. func (c *ChatCompletionsStreamResponse) SetSystemFingerprint(s string) {
  109. c.SystemFingerprint = &s
  110. }
  111. type ChatCompletionsStreamResponseSimple struct {
  112. Choices []ChatCompletionsStreamResponseChoice `json:"choices"`
  113. Usage *Usage `json:"usage"`
  114. }
  115. type CompletionsStreamResponse struct {
  116. Choices []struct {
  117. Text string `json:"text"`
  118. FinishReason string `json:"finish_reason"`
  119. } `json:"choices"`
  120. }
  121. type Usage struct {
  122. PromptTokens int `json:"prompt_tokens"`
  123. CompletionTokens int `json:"completion_tokens"`
  124. TotalTokens int `json:"total_tokens"`
  125. PromptTokensDetails InputTokenDetails `json:"prompt_tokens_details"`
  126. CompletionTokenDetails OutputTokenDetails `json:"completion_tokens_details"`
  127. }