OpenAINonStreamingResponse creates a non-streaming response with the given text.
(text string)
| 843 | |
| 844 | // OpenAINonStreamingResponse creates a non-streaming response with the given text. |
| 845 | func OpenAINonStreamingResponse(text string) OpenAIResponse { |
| 846 | return OpenAIResponse{ |
| 847 | Response: &OpenAICompletion{ |
| 848 | ID: fmt.Sprintf("chatcmpl-%s", uuid.New().String()[:8]), |
| 849 | Object: "chat.completion", |
| 850 | Created: time.Now().Unix(), |
| 851 | Model: "gpt-4", |
| 852 | Choices: []OpenAICompletionChoice{ |
| 853 | { |
| 854 | Index: 0, |
| 855 | Message: OpenAIMessage{ |
| 856 | Role: "assistant", |
| 857 | Content: text, |
| 858 | }, |
| 859 | FinishReason: "stop", |
| 860 | }, |
| 861 | }, |
| 862 | Usage: OpenAICompletionUsage{ |
| 863 | PromptTokens: 10, |
| 864 | CompletionTokens: 5, |
| 865 | TotalTokens: 15, |
| 866 | }, |
| 867 | }, |
| 868 | } |
| 869 | } |
| 870 | |
| 871 | // OpenAITextChunks creates streaming chunks with text deltas. |
| 872 | // Each delta string becomes a separate chunk with a single choice. |