Skip to content

Conversation

@antonmironovv
Copy link
Contributor

…lerik/kendo#24269

Copy link
Contributor

@eyupyusein eyupyusein left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Consider adding try/catch clause to ProcessAsync, too.
  2. In the Controllers, there is repeating code in the Actions - you can extract it to a common Method, e.g.:
                _http.DefaultRequestHeaders.Clear();
                _http.DefaultRequestHeaders.Add("api-key", _apiKey);

                var content = new StringContent(JsonConvert.SerializeObject(payload), Encoding.UTF8, "application/json");
                var response = await _http.PostAsync(url, content);
                var text = await response.Content.ReadAsStringAsync();

                if (!response.IsSuccessStatusCode)
                    return $"Azure OpenAI API error: {response.StatusCode}";

                var json = JObject.Parse(text);
                return json["choices"]?[0]?["message"]?["content"]?.ToString()?.Trim() ?? 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants