Skip to content
New issue

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

Tools from Streaming Chat Completion not triggering #313

Open
RichOwenMercury opened this issue Dec 23, 2024 · 0 comments
Open

Tools from Streaming Chat Completion not triggering #313

RichOwenMercury opened this issue Dec 23, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@RichOwenMercury
Copy link

RichOwenMercury commented Dec 23, 2024

Service

Azure OpenAI

Describe the bug

When using the CompleteChatStreamingAsync method on the ChatClient. I have tools configured with the ToolChoice set to Auto. However, whenever I send a user message that should trigger the tool, the TooCallUpdates against the StreamingChatCompletionUpdate is always empty.

To test this I have a simple get_today tool that when executed the function will return the formatted datetime. I have provide the code below.

Not sure if this is something worng with

Steps to reproduce

  1. Send a User Message "What is today's date?"

Expected:
Will raise the ToolCallUpdate that will then allow me to call the required method.

Actual:
No ToolCallUpdate are raised so the chat returns the text '{get_today}'

Code snippets

// Main Code

var endpoint = "":
var apiKey = "";
var deployment = "";

var creds = new AzureKeyCredential(apiKey);
var client = new AzureOpenAIClient(endpoint, creds);
var chatClient = client.GetChatClient(deployment);

var tools = GetTools(); // Returns Dictionary<string, ITool>

var options = new ChatCompletionOptions();
if (tools.Any())
{
    options.ToolChoice = ChatToolChoice.CreateAutoChoice();
    
    foreach (var toolData in tools)
    {
        var tool = toolData.Value;

        options.Tools.Add(ChatTool.CreateFunctionTool(tool.Name, tool.Description, tool.Parameters));
    }
}

var messages = new List<ChatMessage>
{
    new SystemChatMessage("You are a helpful assistant. Always lookup the current date and/or time using the tool 'get_today' when required."),
    new UserChatMessage("What is today's date?")
};

var completionUpdates = chatClient.CompleteChatStreamingAsync(messages, options);

await foreach (var update in completionUpdates)
{
    Console.WriteLine("Finish Reason: {0}", update.FinishReason);
    if (update.FinishReason == ChatFinishReason.FunctionCall)
    {
        // Would expect here to be hit (1/2)
    }

    foreach (var toolCall in update.ToolCallUpdates)
    {
        // Would expect here to be hit (2/2)
    }
    
    foreach (var contentPart in update.ContentUpdate)
    {
        Console.WriteLine(contentPart.Text);
    }
}

// ITool
public interface ITool
{
    public string Name { get; }
    public string Description { get; }
    public BinaryData Parameters { get; }

    Task<string> RunAsync(string args);
}

// GetTodayTool
public class GetTodayTool : ITool
{
    public string Name => "get_today";
    public string Description => "Know the date and time of today. Will return in format dd/MM/yyyy HH:mm:ss";
    public BinaryData Parameters => BinaryData.FromString("{}");

    public Task<string> RunAsync(string args)
    {
        return Task.FromResult(DateTime.Now.ToString("dd//MM/yyyy HH:mm:ss"));
    }
}

OS

winOS

.NET version

8

Library version

2.1.0

@RichOwenMercury RichOwenMercury added the bug Something isn't working label Dec 23, 2024
@RichOwenMercury RichOwenMercury changed the title Calling Tools from Streaming Chat Completion not triggering Tools from Streaming Chat Completion not triggering Dec 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant