text_response.go 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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) SetContentString(s string) {
  60. c.Content = &s
  61. }
  62. func (c *ChatCompletionsStreamResponseChoiceDelta) GetContentString() string {
  63. if c.Content == nil {
  64. return ""
  65. }
  66. return *c.Content
  67. }
  68. type ToolCall struct {
  69. // Index is not nil only in chat completion chunk object
  70. Index *int `json:"index,omitempty"`
  71. ID string `json:"id"`
  72. Type any `json:"type"`
  73. Function FunctionCall `json:"function"`
  74. }
  75. type FunctionCall struct {
  76. Name string `json:"name,omitempty"`
  77. // call function with arguments in JSON format
  78. Arguments string `json:"arguments,omitempty"`
  79. }
  80. type ChatCompletionsStreamResponse struct {
  81. Id string `json:"id"`
  82. Object string `json:"object"`
  83. Created int64 `json:"created"`
  84. Model string `json:"model"`
  85. SystemFingerprint *string `json:"system_fingerprint"`
  86. Choices []ChatCompletionsStreamResponseChoice `json:"choices"`
  87. Usage *Usage `json:"usage"`
  88. }
  89. func (c *ChatCompletionsStreamResponse) GetSystemFingerprint() string {
  90. if c.SystemFingerprint == nil {
  91. return ""
  92. }
  93. return *c.SystemFingerprint
  94. }
  95. func (c *ChatCompletionsStreamResponse) SetSystemFingerprint(s string) {
  96. c.SystemFingerprint = &s
  97. }
  98. type ChatCompletionsStreamResponseSimple struct {
  99. Choices []ChatCompletionsStreamResponseChoice `json:"choices"`
  100. Usage *Usage `json:"usage"`
  101. }
  102. type CompletionsStreamResponse struct {
  103. Choices []struct {
  104. Text string `json:"text"`
  105. FinishReason string `json:"finish_reason"`
  106. } `json:"choices"`
  107. }
  108. type Usage struct {
  109. PromptTokens int `json:"prompt_tokens"`
  110. CompletionTokens int `json:"completion_tokens"`
  111. TotalTokens int `json:"total_tokens"`
  112. }