microsoft / semantic-kernel

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

.Net: 07-DALL-E-2 Notebook in dotnet contains error in code when creating Kernel #2839

Closed Roybott closed 1 year ago

Roybott commented 1 year ago

The dotnet code to create the kernel in the 07-DALL-E-2 notebook has an error when using OpenAI (not Azure), which results in the following error message:

Error: System.ArgumentException: The value cannot be an empty string or composed entirely of whitespace. (Parameter 'apiKey') at Microsoft.SemanticKernel.Diagnostics.Verify.ThrowArgumentWhiteSpaceException(String paramName) at Microsoft.SemanticKernel.Connectors.AI.OpenAI.AzureSdk.OpenAIClientBase..ctor(String modelId, String apiKey, String organization, HttpClient httpClient, ILoggerFactory loggerFactory) at Microsoft.SemanticKernel.Connectors.AI.OpenAI.TextEmbedding.OpenAITextEmbeddingGeneration..ctor(String modelId, String apiKey, String organization, HttpClient httpClient, ILoggerFactory loggerFactory) at Microsoft.SemanticKernel.OpenAIKernelBuilderExtensions.<>cDisplayClass6_0.b0(ILoggerFactory loggerFactory, KernelConfig config) at Microsoft.SemanticKernel.KernelBuilder.<>cDisplayClass21_0`1.b0() at Microsoft.SemanticKernel.Services.NamedServiceProvider1.GetService[T](String name) at Microsoft.SemanticKernel.Kernel.GetService[T](String name) at Submission#10.<<Initialize>>d__0.MoveNext() --- End of stack trace from previous location --- at Microsoft.CodeAnalysis.Scripting.ScriptExecutionState.RunSubmissionsAsync[TResult](ImmutableArray1 precedingExecutors, Func2 currentExecutor, StrongBox1 exceptionHolderOpt, Func`2 catchExceptionOpt, CancellationToken cancellationToken)

due to the code:

else { builder.WithOpenAITextEmbeddingGenerationService("text-embedding-ada-002", orgId); builder.WithOpenAITextCompletionService("gpt-3.5-turbo", orgId); builder.WithOpenAIImageGenerationService(apiKey, orgId); }

image

The issue is the 'orgId' is passed in as the second parameter for the first two lines rather than the apiKey, the correct code should be:

else { builder.WithOpenAITextEmbeddingGenerationService("text-embedding-ada-002", apiKey, orgId); builder.WithOpenAITextCompletionService("gpt-3.5-turbo", apiKey, orgId); builder.WithOpenAIImageGenerationService(apiKey, orgId); }

image
Roybott commented 1 year ago

It also seems like other parts of this notebook are broken and it should be fully reviewed.

For example, when running the next code block that generates an image, I got an error about the model not being supported on the text completion endpoint and that it suggested calling the Chat completion service instead.

This can be fixed by changing the code in the kernel setup code block to use builder.WithOpenAIChatCompletionService instead of WithOpenAITextCompletionService.

evchaki commented 1 year ago

@Roybott - thanks for finding this. Feel free to do a PR if you can on this.

Roybott commented 1 year ago

@Roybott - thanks for finding this. Feel free to do a PR if you can on this.

@evchaki I created a PR here: https://github.com/microsoft/semantic-kernel/pull/3065