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

How do we pass file ids in message creation on asssistants now? #46012

Open
raysuelzer opened this issue Sep 17, 2024 · 2 comments
Open

How do we pass file ids in message creation on asssistants now? #46012

raysuelzer opened this issue Sep 17, 2024 · 2 comments
Labels
Client This issue points to a problem in the data-plane of the library. customer-reported Issues that are reported by GitHub users external to the Azure organization. needs-team-attention Workflow: This issue needs attention from Azure service team or SDK team OpenAI question The issue doesn't require a change to the product in order to be resolved. Most issues start as that Service Attention Workflow: This issue is responsible by Azure service team.

Comments

@raysuelzer
Copy link

Library name and version

Azure.AI.OpenAI 2.0.0-beta.5

Query/Question

In the Azure.AI.OpenAI.Assistants we were able to do this to attach the file to the message. I can find no documentation on the new process as I see no way to reference file IDs in a user message:

        private async Task<ThreadMessage> CreateMessage(string userMessage, string[] fileIds, AssistantThread thread)
        {
            var messageResponse = await _client.CreateMessageAsync(thread, MessageRole.User, userMessage, fileIds);
            var message = messageResponse.Value;
            return message;
        }

Environment

.NET Core 8
Visual Studio 2022 Preview
Windows

@github-actions github-actions bot added customer-reported Issues that are reported by GitHub users external to the Azure organization. needs-triage Workflow: This is a new issue that needs to be triaged to the appropriate team. question The issue doesn't require a change to the product in order to be resolved. Most issues start as that labels Sep 17, 2024
@jsquire jsquire added Service Attention Workflow: This issue is responsible by Azure service team. Client This issue points to a problem in the data-plane of the library. needs-team-attention Workflow: This issue needs attention from Azure service team or SDK team OpenAI labels Sep 17, 2024
@github-actions github-actions bot removed the needs-triage Workflow: This is a new issue that needs to be triaged to the appropriate team. label Sep 17, 2024
Copy link

Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @jpalvarezl @ralph-msft @trrwilson.

@trrwilson
Copy link
Member

Thank you for getting in touch, @raysuelzer!

You're absolutely right that this use of attachments with Assistants v2 and the new library is missing sample coverage at the moment; I'll ensure we get a work item filed to have the changes better documented.

As a direct answer, you can extend the pattern shown in this test code by using the Attachments property of MessageCreationOptions.

Here's a rough adaptation of the test to demonstrate:

[Test]
public void MessageWithAttachmentWorks()
{
    AssistantClient client = GetTestClient();

    FileClient fileClient = GetTestClient<FileClient>(TestScenario.Files);
    OpenAIFileInfo numbersFile = fileClient.UploadFile(
        BinaryData.FromString("""
        15
        20
        22
        12
        20
        """).ToStream(),
        "text/plain",
        FileUploadPurpose.Assistants);
    Validate(numbersFile);

    Assistant assistant = client.CreateAssistant(
        "gpt-4o",
        new AssistantCreationOptions()
        {
            Tools = { new CodeInterpreterToolDefinition() },
            ToolResources = new()
            {
                CodeInterpreter = new()
                {
                        FileIds = [numbersFile.Id],
                }
            }
        });

    AssistantThread thread = client.CreateThread();
    Validate(thread);

    ThreadMessage message = client.CreateMessage(
        thread.Id,
        MessageRole.User,
        content:
        [
            MessageContent.FromText("What's the standard deviation of the numbers in the attached file?"),
        ],
        new MessageCreationOptions()
        {
            Attachments =
            {
                new MessageCreationAttachment(
                    numbersFile.Id,
                    tools: [ new CodeInterpreterToolDefinition() ]),
            }
        });
    Validate(message);

    foreach (StreamingUpdate chunk in client.CreateRunStreaming(thread.Id, assistant.Id))
    {
        if (chunk is MessageContentUpdate contentUpdate)
        {
            Console.Write(contentUpdate.Text);
        }
    }
}

Which yields:

    It appears that the file contains a single column of numbers. To calculate the standard deviation of these numbers, we can proceed with the computation.The standard deviation of the numbers in the file is approximately \(4.43\).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Client This issue points to a problem in the data-plane of the library. customer-reported Issues that are reported by GitHub users external to the Azure organization. needs-team-attention Workflow: This issue needs attention from Azure service team or SDK team OpenAI question The issue doesn't require a change to the product in order to be resolved. Most issues start as that Service Attention Workflow: This issue is responsible by Azure service team.
Projects
None yet
Development

No branches or pull requests

3 participants