async Task ConvertCoreAsync()

in src/WebJobs.Extensions.OpenAI/TextCompletionConverter.cs [42:63]


    async Task<TextCompletionResponse> ConvertCoreAsync(
        TextCompletionAttribute attribute,
        CancellationToken cancellationToken)
    {
        ChatCompletionOptions options = attribute.BuildRequest();
        this.logger.LogInformation("Sending OpenAI completion request with prompt: {request}", attribute.Prompt);

        IList<ChatMessage> chatMessages = new List<ChatMessage>()
        {
            new UserChatMessage(attribute.Prompt)
        };

        ClientResult<ChatCompletion> response = await this.openAIClientFactory.GetChatClient(
            attribute.AIConnectionName,
            attribute.ChatModel).CompleteChatAsync(chatMessages, options, cancellationToken: cancellationToken);

        string text = string.Join(
            Environment.NewLine + Environment.NewLine,
            response.Value.Content[0].Text);
        TextCompletionResponse textCompletionResponse = new(text, response.Value.Usage.TotalTokenCount);
        return textCompletionResponse;
    }