text_response.go 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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. Description string `json:"description,omitempty"`
  77. Name string `json:"name,omitempty"`
  78. // call function with arguments in JSON format
  79. Parameters any `json:"parameters,omitempty"` // request
  80. Arguments string `json:"arguments,omitempty"`
  81. }
  82. type ChatCompletionsStreamResponse struct {
  83. Id string `json:"id"`
  84. Object string `json:"object"`
  85. Created int64 `json:"created"`
  86. Model string `json:"model"`
  87. SystemFingerprint *string `json:"system_fingerprint"`
  88. Choices []ChatCompletionsStreamResponseChoice `json:"choices"`
  89. Usage *Usage `json:"usage"`
  90. }
  91. func (c *ChatCompletionsStreamResponse) GetSystemFingerprint() string {
  92. if c.SystemFingerprint == nil {
  93. return ""
  94. }
  95. return *c.SystemFingerprint
  96. }
  97. func (c *ChatCompletionsStreamResponse) SetSystemFingerprint(s string) {
  98. c.SystemFingerprint = &s
  99. }
  100. type ChatCompletionsStreamResponseSimple struct {
  101. Choices []ChatCompletionsStreamResponseChoice `json:"choices"`
  102. Usage *Usage `json:"usage"`
  103. }
  104. type CompletionsStreamResponse struct {
  105. Choices []struct {
  106. Text string `json:"text"`
  107. FinishReason string `json:"finish_reason"`
  108. } `json:"choices"`
  109. }
  110. type Usage struct {
  111. PromptTokens int `json:"prompt_tokens"`
  112. CompletionTokens int `json:"completion_tokens"`
  113. TotalTokens int `json:"total_tokens"`
  114. }