Skip to content

Commit

Permalink
Merge pull request #66 from hario90/TSG-for-endpoint-type-mismatch
Browse files Browse the repository at this point in the history
Add troubleshooting steps when endpoint type doesn't match model used
  • Loading branch information
hario90 authored Sep 5, 2023
2 parents 97e6706 + 6792cb7 commit 7e8baec
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 34 deletions.
22 changes: 18 additions & 4 deletions sk-csharp-azure-functions/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ Configure an OpenAI endpoint
```powershell
cd sk-csharp-azure-functions
dotnet user-secrets set "serviceType" "OpenAI"
dotnet user-secrets set "serviceId" "text-davinci-003"
dotnet user-secrets set "deploymentOrModelId" "text-davinci-003"
dotnet user-secrets set "serviceId" "gpt-3.5-turbo"
dotnet user-secrets set "deploymentOrModelId" "gpt-3.5-turbo"
dotnet user-secrets set "apiKey" "... your OpenAI key ..."
```

Expand All @@ -36,8 +36,8 @@ Configure an Azure OpenAI endpoint
```powershell
cd sk-csharp-azure-functions
dotnet user-secrets set "serviceType" "AzureOpenAI"
dotnet user-secrets set "serviceId" "text-davinci-003"
dotnet user-secrets set "deploymentOrModelId" "text-davinci-003"
dotnet user-secrets set "serviceId" "gpt-35-turbo"
dotnet user-secrets set "deploymentOrModelId" "gpt-35-turbo"
dotnet user-secrets set "endpoint" "https:// ... your endpoint ... .openai.azure.com/"
dotnet user-secrets set "apiKey" "... your Azure OpenAI key ..."
```
Expand Down Expand Up @@ -80,3 +80,17 @@ To build and run the Azure Functions application from a terminal use the followi
dotnet build
func start --csharp
```

## Troubleshooting

### Getting a 400 (BadRequest) and error "Azure.RequestFailedException: logprobs, best_of and echo parameters are not available on gpt-35-turbo model. Please remove the parameter and try again."

A chat completion model (gpt-35-turbo) was set in serviceId/deploymentOrModelId while the kernel was configured to use a text completion model. The type of model used by the kernel can be configured with the endpointType secret. To fix, you can either:

- change endpointType to chat-completion

```powershell
dotnet user-secrets set "endpointType" "chat-completion"
```

- change serviceId and deploymentOrModelId to a text completion service like "text-davinci-003": [See Using .NET Secret Manager](#using-net-secret-manager). Please note that the [text-davinci-003 model will be phased out in the future](https://techcommunity.microsoft.com/t5/azure-ai-services-blog/announcing-updates-to-azure-openai-service-models/ba-p/3866757).
5 changes: 5 additions & 0 deletions sk-csharp-azure-functions/config/EndpointTypes.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
internal static class EndpointTypes
{
internal const string TextCompletion = "text-completion";
internal const string ChatCompletion = "chat-completion";
}
12 changes: 8 additions & 4 deletions sk-csharp-azure-functions/config/KernelBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,18 @@ internal static KernelBuilder WithCompletionService(this KernelBuilder kernelBui
{
switch (kernelSettings.ServiceType.ToUpperInvariant())
{
case ServiceTypes.AzureOpenAI:
case ServiceTypes.AzureOpenAI when kernelSettings.EndpointType == EndpointTypes.TextCompletion:
kernelBuilder.WithAzureTextCompletionService(deploymentName: kernelSettings.DeploymentOrModelId, endpoint: kernelSettings.Endpoint, apiKey: kernelSettings.ApiKey, serviceId: kernelSettings.ServiceId);
break;

case ServiceTypes.OpenAI:
case ServiceTypes.AzureOpenAI when kernelSettings.EndpointType == EndpointTypes.ChatCompletion:
kernelBuilder.WithAzureChatCompletionService(deploymentName: kernelSettings.DeploymentOrModelId, endpoint: kernelSettings.Endpoint, apiKey: kernelSettings.ApiKey, serviceId: kernelSettings.ServiceId);
break;
case ServiceTypes.OpenAI when kernelSettings.EndpointType == EndpointTypes.TextCompletion:
kernelBuilder.WithOpenAITextCompletionService(modelId: kernelSettings.DeploymentOrModelId, apiKey: kernelSettings.ApiKey, orgId: kernelSettings.OrgId, serviceId: kernelSettings.ServiceId);
break;

case ServiceTypes.OpenAI when kernelSettings.EndpointType == EndpointTypes.ChatCompletion:
kernelBuilder.WithOpenAIChatCompletionService(modelId: kernelSettings.DeploymentOrModelId, apiKey: kernelSettings.ApiKey, orgId: kernelSettings.OrgId, serviceId: kernelSettings.ServiceId);
break;
default:
throw new ArgumentException($"Invalid service type value: {kernelSettings.ServiceType}");
}
Expand Down
3 changes: 3 additions & 0 deletions sk-csharp-azure-functions/config/KernelSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ internal class KernelSettings
{
public const string DefaultConfigFile = "config/appsettings.json";

[JsonPropertyName("endpointType")]
public string EndpointType { get; set; } = EndpointTypes.ChatCompletion;

[JsonPropertyName("serviceType")]
public string ServiceType { get; set; } = string.Empty;

Expand Down
2 changes: 1 addition & 1 deletion sk-csharp-chatgpt-plugin/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Semantic Kernel ChatGPT plugin starter

This project provides starter code to create a ChatGPT plugin. It includes the following components:

- An endpoint that serves up an ai-plugin.json file for ChatGPT to discover the plugin
- A generator that automatically converts prompts into semantic function endpoints
- The ability to add additional native functions as endpoints to the plugin
Expand All @@ -24,7 +25,6 @@ To configure the starter, you need to provide the following information:

For Debugging the console application alone, we suggest using .NET [Secret Manager](https://learn.microsoft.com/en-us/aspnet/core/security/app-secrets) to avoid the risk of leaking secrets into the repository, branches and pull requests.


### Using appsettings.json

Configure an OpenAI endpoint
Expand Down
22 changes: 18 additions & 4 deletions sk-csharp-hello-world/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ Configure an OpenAI endpoint
```powershell
cd sk-csharp-hello-world
dotnet user-secrets set "serviceType" "OpenAI"
dotnet user-secrets set "serviceId" "text-davinci-003"
dotnet user-secrets set "deploymentOrModelId" "text-davinci-003"
dotnet user-secrets set "serviceId" "gpt-3.5-turbo"
dotnet user-secrets set "deploymentOrModelId" "gpt-3.5-turbo"
dotnet user-secrets set "apiKey" "... your OpenAI key ..."
```

Expand All @@ -35,8 +35,8 @@ Configure an Azure OpenAI endpoint
```powershell
cd sk-csharp-hello-world
dotnet user-secrets set "serviceType" "AzureOpenAI"
dotnet user-secrets set "serviceId" "text-davinci-003"
dotnet user-secrets set "deploymentOrModelId" "text-davinci-003"
dotnet user-secrets set "serviceId" "gpt-35-turbo"
dotnet user-secrets set "deploymentOrModelId" "gpt-35-turbo"
dotnet user-secrets set "endpoint" "https:// ... your endpoint ... .openai.azure.com/"
dotnet user-secrets set "apiKey" "... your Azure OpenAI key ..."
```
Expand Down Expand Up @@ -79,3 +79,17 @@ To build and run the console application from the terminal use the following com
dotnet build
dotnet run
```

## Troubleshooting

### Getting a 400 (BadRequest) and error "Azure.RequestFailedException: logprobs, best_of and echo parameters are not available on gpt-35-turbo model. Please remove the parameter and try again."

A chat completion model (gpt-35-turbo) was set in serviceId/deploymentOrModelId while the kernel was configured to use a text completion model. The type of model used by the kernel can be configured with the endpointType secret. To fix, you can either:

- change endpointType to chat-completion

```powershell
dotnet user-secrets set "endpointType" "chat-completion"
```

- change serviceId and deploymentOrModelId to a text completion service like "text-davinci-003": [See Using .NET Secret Manager](#using-net-secret-manager). Please note that the [text-davinci-003 model will be phased out in the future](https://techcommunity.microsoft.com/t5/azure-ai-services-blog/announcing-updates-to-azure-openai-service-models/ba-p/3866757).
30 changes: 10 additions & 20 deletions sk-csharp-hello-world/config/KernelBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,18 @@ internal static KernelBuilder WithCompletionService(this KernelBuilder kernelBui
{
switch (kernelSettings.ServiceType.ToUpperInvariant())
{
case ServiceTypes.AzureOpenAI:
if (kernelSettings.EndpointType == EndpointTypes.TextCompletion)
{
kernelBuilder.WithAzureTextCompletionService(deploymentName: kernelSettings.DeploymentOrModelId, endpoint: kernelSettings.Endpoint, apiKey: kernelSettings.ApiKey, serviceId: kernelSettings.ServiceId);
}
else if (kernelSettings.EndpointType == EndpointTypes.ChatCompletion)
{
kernelBuilder.WithAzureChatCompletionService(deploymentName: kernelSettings.DeploymentOrModelId, endpoint: kernelSettings.Endpoint, apiKey: kernelSettings.ApiKey, serviceId: kernelSettings.ServiceId);
}
case ServiceTypes.AzureOpenAI when kernelSettings.EndpointType == EndpointTypes.TextCompletion:
kernelBuilder.WithAzureTextCompletionService(deploymentName: kernelSettings.DeploymentOrModelId, endpoint: kernelSettings.Endpoint, apiKey: kernelSettings.ApiKey, serviceId: kernelSettings.ServiceId);
break;

case ServiceTypes.OpenAI:
if (kernelSettings.EndpointType == EndpointTypes.TextCompletion)
{
kernelBuilder.WithOpenAITextCompletionService(modelId: kernelSettings.DeploymentOrModelId, apiKey: kernelSettings.ApiKey, orgId: kernelSettings.OrgId, serviceId: kernelSettings.ServiceId);
}
else if (kernelSettings.EndpointType == EndpointTypes.ChatCompletion)
{
kernelBuilder.WithOpenAIChatCompletionService(modelId: kernelSettings.DeploymentOrModelId, apiKey: kernelSettings.ApiKey, orgId: kernelSettings.OrgId, serviceId: kernelSettings.ServiceId);
}
case ServiceTypes.AzureOpenAI when kernelSettings.EndpointType == EndpointTypes.ChatCompletion:
kernelBuilder.WithAzureChatCompletionService(deploymentName: kernelSettings.DeploymentOrModelId, endpoint: kernelSettings.Endpoint, apiKey: kernelSettings.ApiKey, serviceId: kernelSettings.ServiceId);
break;
case ServiceTypes.OpenAI when kernelSettings.EndpointType == EndpointTypes.TextCompletion:
kernelBuilder.WithOpenAITextCompletionService(modelId: kernelSettings.DeploymentOrModelId, apiKey: kernelSettings.ApiKey, orgId: kernelSettings.OrgId, serviceId: kernelSettings.ServiceId);
break;
case ServiceTypes.OpenAI when kernelSettings.EndpointType == EndpointTypes.ChatCompletion:
kernelBuilder.WithOpenAIChatCompletionService(modelId: kernelSettings.DeploymentOrModelId, apiKey: kernelSettings.ApiKey, orgId: kernelSettings.OrgId, serviceId: kernelSettings.ServiceId);
break;

default:
throw new ArgumentException($"Invalid service type value: {kernelSettings.ServiceType}");
}
Expand Down
2 changes: 1 addition & 1 deletion sk-csharp-hello-world/config/KernelSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ internal class KernelSettings
public const string DefaultConfigFile = "config/appsettings.json";

[JsonPropertyName("endpointType")]
public string EndpointType { get; set; } = EndpointTypes.TextCompletion;
public string EndpointType { get; set; } = EndpointTypes.ChatCompletion;

[JsonPropertyName("serviceType")]
public string ServiceType { get; set; } = string.Empty;
Expand Down

0 comments on commit 7e8baec

Please sign in to comment.