Skip to content

Commit 9103bd8

Browse files
authored
Keep the original casing of model name for custom endpoint to enable Foundry Local (#413)
This PR contains the following 2 fixes: 1. Keep the original casing of the model's name for custom endpoint configuration. 2. Fix the error reporting to handle exception messages that already contains newline at the end. OpenAI models require lower case for their names, but the custom endpoint may be case-sensitive, such as the endpoint set up by Foundry Local. So, we should keep the original casing for custom endpoint configurations.
1 parent cc0eee8 commit 9103bd8

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

shell/AIShell.Kernel/Shell.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -694,7 +694,12 @@ internal async Task RunREPLAsync()
694694
while (ex.InnerException is { })
695695
{
696696
sb ??= new(message, capacity: message.Length * 3);
697-
sb.Append($"\n Inner -> {ex.InnerException.Message}");
697+
if (sb[^1] is not '\n')
698+
{
699+
sb.Append('\n');
700+
}
701+
702+
sb.Append($" Inner -> {ex.InnerException.Message}");
698703
ex = ex.InnerException;
699704
}
700705

@@ -703,8 +708,9 @@ internal async Task RunREPLAsync()
703708
message = sb.ToString();
704709
}
705710

711+
string separator = message.EndsWith('\n') ? "\n" : "\n\n";
706712
Host.WriteErrorLine()
707-
.WriteErrorLine($"Agent failed to generate a response: {message}\n\n{stackTrace}")
713+
.WriteErrorLine($"Agent failed to generate a response: {message}{separator}{stackTrace}")
708714
.WriteErrorLine();
709715
}
710716
}

shell/agents/AIShell.OpenAI.Agent/GPT.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,16 @@ public GPT(
5555
Description = description;
5656
Endpoint = endpoint?.Trim().TrimEnd('/');
5757
Deployment = deployment;
58-
ModelName = modelName.ToLowerInvariant();
5958
SystemPrompt = systemPrompt;
6059
Key = key;
6160
AuthType = authType;
6261

6362
Dirty = false;
64-
ModelInfo = ModelInfo.TryResolve(ModelName, out var model) ? model : null;
63+
ModelInfo = ModelInfo.TryResolve(modelName, out var model) ? model : null;
64+
65+
// OpenAI models require the model name to be lower case. e.g., 'gpt-4.1' works but not 'GPT-4.1'.
66+
// However, custom endpoint may be case-sensitive on the model name, such as Foundry Local.
67+
ModelName = ModelInfo is { } ? modelName.ToLowerInvariant() : modelName;
6568

6669
bool noEndpoint = string.IsNullOrEmpty(Endpoint);
6770
bool noDeployment = string.IsNullOrEmpty(Deployment);

0 commit comments

Comments
 (0)