microsoft / semantic-kernel

Integrate cutting-edge LLM technology quickly and easily into your apps
https://aka.ms/semantic-kernel
MIT License
21.15k stars 3.1k forks source link

HttpOperationException: Response status code does not indicate success: 401 (Unauthorized). -> OpenAi assitant generated file #7253

Closed JP-droidic closed 1 month ago

JP-droidic commented 1 month ago

I get a file generated by OpenAi assistant:

 OpenAIAssistantAgent agent =
        await OpenAIAssistantAgent.CreateAsync(
            kernel: _semanticKernelHelper.BuildKernel(AIConfg.OpenAiChatGpt_4_0),
            config: new(_configuration.GetSection("AzureAi_4_5_Turbo")["ApiKey"], _configuration.GetSection("AzureAi_4_5_Turbo")["Endpoint"]),
            new()
            {
                //Instructions = AgentInstructions,
                Name = "coder",
                EnableCodeInterpreter = true,
                ModelId = "gpt-4o",
            });

and then for

    OpenAIFileService fileService = new(_configuration.GetSection("AzureAi_4_5_Turbo")["ApiKey"]);
foreach (FileReferenceContent fileReference in message.Items.OfType<FileReferenceContent>())
{
                Console.WriteLine($"# {message.Role} - {message.AuthorName ?? "*"}: @{fileReference.FileId}");

                BinaryContent content = await fileService.GetFileContentAsync(fileReference.FileId);

I get the following error message:

HttpOperationException: Response status code does not indicate success: 401 (Unauthorized).
Microsoft.SemanticKernel.Http.HttpClientExtensions.SendWithSuccessCheckAsync(HttpClient client, HttpRequestMessage request, HttpCompletionOption completionOption, CancellationToken cancellationToken)
Microsoft.SemanticKernel.Http.HttpClientExtensions.SendWithSuccessCheckAsync(HttpClient client, HttpRequestMessage request, CancellationToken cancellationToken)
Microsoft.SemanticKernel.Connectors.OpenAI.OpenAIFileService.StreamGetRequestAsync(string url, CancellationToken cancellationToken)
Microsoft.SemanticKernel.Connectors.OpenAI.OpenAIFileService.GetFileContentAsync(string id, CancellationToken cancellationToken)
AiEngine.SemanticKernel.SemanticKernelService+<>c__DisplayClass27_0+<<Agent>g__InvokeAgentAsync|0>d.MoveNext() in SemanticKernelService.cs
+
                        BinaryContent content = await fileService.GetFileContentAsync(fileReference.FileId);
AiEngine.SemanticKernel.SemanticKernelService+<>c__DisplayClass27_0+<<Agent>g__InvokeAgentAsync|0>d.MoveNext() in SemanticKernelService.cs
moonbox3 commented 1 month ago

@JP-droidic if you make an API call directly to the File Service, with the same API key, is it successful?

matthewbolanos commented 1 month ago

Going to go ahead and close this out since we didn't hear back. Feel free to reopen the issue.