We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
public async Task StreamCompletionAsync(Action<ChatResponse> resultHandler, ChatRequest chatRequest, CancellationToken cancellationToken = default) { chatRequest.Stream = true; var jsonContent = JsonConvert.SerializeObject(chatRequest, Api.JsonSerializationOptions); using var request = new HttpRequestMessage(HttpMethod.Post, $"{GetEndpoint()}/completions") { Content = jsonContent.ToJsonStringContent() }; var response = await Api.Client.SendAsync(request, HttpCompletionOption.ResponseHeadersRead, cancellationToken); await response.CheckResponseAsync(cancellationToken); await using var stream = await response.Content.ReadAsStreamAsync(); using var reader = new StreamReader(stream); while (await reader.ReadLineAsync() is { } line) { if (line.StartsWith("data: ")) { line = line["data: ".Length..]; } if (line == "[DONE]") { return; } if (!string.IsNullOrWhiteSpace(line)) { resultHandler(DeserializeResult(response, line.Trim())); } } } private ChatResponse DeserializeResult(HttpResponseMessage response, string json) { var result = JsonConvert.DeserializeObject<ChatResponse>(json, Api.JsonSerializationOptions); if (result?.FirstChoice == null) { throw new HttpRequestException($"{nameof(DeserializeResult)} no completions! HTTP status code: {response.StatusCode}. Response body: {json}"); } result.SetResponseData(response.Headers); return result; }
The text was updated successfully, but these errors were encountered:
And make ChatResponse inherit BaseResponse :)
Sorry, something went wrong.
BTW, I found https://api.openai.com/v1/chat/completions will give us wrong data structure, According to the document it will send back "message" in "choice"
but we will get "delta" instead of "message" and make it deserialize wrong
com.openai.unity 3.1.1 (#43)
4264510
- refactored model validation - added additional default models - deprecate `OpenAIClient.DefaultModel` - closes #42
412273d
Successfully merging a pull request may close this issue.
The text was updated successfully, but these errors were encountered: