Azure / azure-sdk-for-net

This repository is for active development of the Azure SDK for .NET. For consumers of the SDK we recommend visiting our public developer docs at https://learn.microsoft.com/dotnet/azure/ or our versioned developer docs at https://azure.github.io/azure-sdk-for-net.
MIT License
5.49k stars 4.81k forks source link

uploading files for use in latest fileAssitant #47121

Open JohnTranstel opened 1 week ago

JohnTranstel commented 1 week ago

Library name and version

azure.ai.openai.assistants\1.0.0-beta.4\

Query/Question

    I am creating an assistant as below.

I upload a file and get a valid looking fileId of the form file-IEhMNtaYJdLreZ53HdyqRyJL

When I then step into var fileUploadResponse = await vectorStore.AddFileToVectorStoreAsync(operation.VectorStoreId, fileId, true);

It fails, System.ClientModel.ClientResultException: 'HTTP 404 (invalid_request_error: ) Files [file-IEhMNtaYJdLreZ53HdyqRyJL] were not found'

What am I doing wrong?

public static async Task CreateFileAssistant(OpenAIFileAssistant fileAssistant) { AzureOpenAIClient azureClient = new( new Uri("uri"), new ApiKeyCredential(apikey));

         var assistantClient = azureClient.GetAssistantClient();

        assistantCreationOptions = new AssistantCreationOptions()
        {
            Name = "File Analysis",
            Instructions = fileAssistant.Instruction,
            Tools = { ToolDefinition.CreateFileSearch() },
        };

        var assistant = await assistantClient.CreateAssistantAsync("gpt-4-PRMagic", assistantCreationOptions);
         var vectorStore = azureClient.GetVectorStoreClient();
        var operation = vectorStore.CreateVectorStore(true);

        string fullfilepath = fileAssistant.FilePath;
        string fileId = "";
        Files localFile = new Files("uri", apiKey);
        var uploadResponse = await localFile.UploadAsync(Files.Purpose.assistants, fullfilepath);
        if (uploadResponse is Files.FileResponse)
        {
            Files.FileResponse fileResponse = (Files.FileResponse)uploadResponse;
            fileId = fileResponse.id;
        }

        var fileUploadResponse = await vectorStore.AddFileToVectorStoreAsync(operation.VectorStoreId,   fileId, true);

        OpenAIFileAssistant response = new OpenAIFileAssistant();
        var thread = await assistantClient.CreateThreadAsync();
        response.FilePath = fileAssistant.FilePath;
        response.Question = "";
        response.Reply = "file uploaded with filename of" + fileUploadResponse.Value.ToString();
        response.AssistantValueId = assistant.Value.Id;
        response.ThreadValueId = thread.Value.Id;
        response.FileValueId = fileUploadResponse.Value.FileId;
        return response;
    }

Environment

Microsoft Visual Studio Community 2022 Version 17.7.3 VisualStudio.17.Release/17.11.4+35312.102 Microsoft .NET Framework Version 4.8.09037

Installed Version: Community

ASP.NET and Web Tools 17.7.273.65229 ASP.NET and Web Tools

Azure App Service Tools v3.0.0 17.7.273.65229 Azure App Service Tools v3.0.0

Azure Functions and Web Jobs Tools 17.7.273.65229 Azure Functions and Web Jobs Tools

C# Tools 4.7.0-3.23416.8+43b0b05cc4f492fd5de00f6f6717409091df8daa C# components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Common Azure Tools 1.10 Provides common services for use by Azure Mobile Services and Microsoft Azure Tools.

Microsoft JVM Debugger 1.0 Provides support for connecting the Visual Studio debugger to JDWP compatible Java Virtual Machines

NuGet Package Manager 6.7.0 NuGet Package Manager in Visual Studio. For more information about NuGet, visit https://docs.nuget.org/

Razor (ASP.NET Core) 17.7.3.2333001+0ab18affdf2a37647768d0e25f5f021bee6257a1 Provides languages services for ASP.NET Core Razor.

SQL Server Data Tools 17.7.10.1 Microsoft SQL Server Data Tools

TypeScript Tools 17.0.20628.2001 TypeScript Tools for Microsoft Visual Studio

Visual Basic Tools 4.7.0-3.23416.8+43b0b05cc4f492fd5de00f6f6717409091df8daa Visual Basic components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Visual F# Tools 17.7.0-beta.23314.10+e612cf93b989503c89e3a5830090062b7ab5e143 Microsoft Visual F# Tools

Visual Studio IntelliCode 2.2 AI-assisted development for Visual Studio.

WiX Toolset Visual Studio Extension 1.0.0.18 WiX Toolset Visual Studio Extension version 1.0.0.18 Copyright (c) .NET Foundation and contributors. All rights reserved.

github-actions[bot] commented 1 week ago

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