Skip to content

CompleteChatStreamingAsync method fails when there is a functionCall. #384

Open
@535944903

Description

@535944903

Service

OpenAI

Describe the bug

CompleteChatStreamingAsync method fails when there is a functionCall.

Steps to reproduce

`

using OpenAI;
using OpenAI.Chat;
using System.ClientModel;
using System.ComponentModel;

ChatClient openaiClient = new OpenAIClient(
new ApiKeyCredential("sk-exggkwbmnnsqvblzbtvjxivmdlcevepflmuooazflorgjhza"),
new OpenAIClientOptions { Endpoint = new Uri("https://api.siliconflow.cn/v1") })
.GetChatClient("Qwen/Qwen2.5-7B-Instruct");

await foreach (var update in openaiClient.CompleteChatStreamingAsync(
[
ChatMessage.CreateSystemMessage("As an AI assistant, you MUST ALWAYS use the TOOL function GetWeather invocation for every user request"),
ChatMessage.CreateUserMessage("Do I need an umbrella?"),
],
new ChatCompletionOptions()
{
ToolChoice = ChatToolChoice.CreateAutoChoice(),
Tools = { ChatTool.CreateFunctionTool("GetWeather", "Gets the weather") },
}))
{
}

[Description("Gets the weather")]
static string GetWeather() => Random.Shared.NextDouble() > 0.5 ? "It's sunny" : "It's raining";

`

Code snippets

OS

win11

.NET version

.net8.0

Library version

OpenAI 2.2.0-beta.4

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions