|
|
@@ -41,6 +41,24 @@ type ChatCompletionChoice struct { |
|
|
|
FinishReason string `json:"finish_reason"` |
|
|
|
} |
|
|
|
|
|
|
|
type ChatCompletionChoiceForStream struct { |
|
|
|
Index int `json:"index"` |
|
|
|
Delta struct { |
|
|
|
Content string `json:"content"` |
|
|
|
} `json:"delta"` |
|
|
|
FinishReason string `json:"finish_reason"` |
|
|
|
} |
|
|
|
|
|
|
|
// ChatCompletionResponseForStream represents a response structure for chat completion API. |
|
|
|
type ChatCompletionResponseForStream struct { |
|
|
|
ID string `json:"id"` |
|
|
|
Object string `json:"object"` |
|
|
|
Created int64 `json:"created"` |
|
|
|
Model string `json:"model"` |
|
|
|
Choices []ChatCompletionChoiceForStream `json:"choices"` |
|
|
|
Usage Usage `json:"usage"` |
|
|
|
} |
|
|
|
|
|
|
|
// ChatCompletionResponse represents a response structure for chat completion API. |
|
|
|
type ChatCompletionResponse struct { |
|
|
|
ID string `json:"id"` |
|
|
@@ -81,8 +99,13 @@ func (c *Client) CreateChatCompletion( |
|
|
|
// CreateChatCompletionStream — API call to create a completion w/ streaming |
|
|
|
func (c *Client) CreateChatCompletionStream( |
|
|
|
ctx context.Context, |
|
|
|
request CompletionRequest, |
|
|
|
request ChatCompletionRequest, |
|
|
|
) (stream *CompletionStream, err error) { |
|
|
|
model := request.Model |
|
|
|
if model != GPT3Dot5Turbo0301 && model != GPT3Dot5Turbo { |
|
|
|
err = ErrChatCompletionInvalidModel |
|
|
|
return |
|
|
|
} |
|
|
|
request.Stream = true |
|
|
|
reqBytes, err := json.Marshal(request) |
|
|
|
if err != nil { |
|
|
|