Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions shell/agents/AIShell.OpenAI.Agent/ModelInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ static ModelInfo()
// https://github.com/openai/openai-cookbook/blob/main/examples/How_to_count_tokens_with_tiktoken.ipynb
s_modelMap = new(StringComparer.OrdinalIgnoreCase)
{
["o1"] = new(tokenLimit: 200_000, encoding: Gpt4oEncoding),
["o1"] = new(tokenLimit: 200_000, encoding: Gpt4oEncoding, reasoning: true),
["o3"] = new(tokenLimit: 200_000, encoding: Gpt4oEncoding, reasoning: true),
["o4-mini"] = new(tokenLimit: 200_000, encoding: Gpt4oEncoding, reasoning: true),
["gpt-4.1"] = new(tokenLimit: 1_047_576, encoding: Gpt4oEncoding),
["gpt-4o"] = new(tokenLimit: 128_000, encoding: Gpt4oEncoding),
["gpt-4"] = new(tokenLimit: 8_192),
["gpt-4-32k"] = new(tokenLimit: 32_768),
Expand All @@ -45,7 +48,7 @@ static ModelInfo()
};
}

private ModelInfo(int tokenLimit, string encoding = null)
private ModelInfo(int tokenLimit, string encoding = null, bool reasoning = false)
{
TokenLimit = tokenLimit;
_encodingName = encoding ?? Gpt34Encoding;
Expand All @@ -54,6 +57,7 @@ private ModelInfo(int tokenLimit, string encoding = null)
// See https://github.com/openai/openai-cookbook/blob/main/examples/How_to_count_tokens_with_tiktoken.ipynb
TokensPerMessage = 3;
TokensPerName = 1;
Reasoning = reasoning;
}

private readonly string _encodingName;
Expand All @@ -62,6 +66,7 @@ private ModelInfo(int tokenLimit, string encoding = null)
internal int TokenLimit { get; }
internal int TokensPerMessage { get; }
internal int TokensPerName { get; }
internal bool Reasoning { get; }
internal Tokenizer Encoding
{
get {
Expand Down
3 changes: 2 additions & 1 deletion shell/agents/AIShell.OpenAI.Agent/Service.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ internal ChatService(string historyRoot, Settings settings)

_chatOptions = new ChatCompletionOptions()
{
Temperature = 0,
MaxOutputTokenCount = MaxResponseToken,
};
}
Expand Down Expand Up @@ -126,6 +125,8 @@ private void RefreshOpenAIClient()
}

EndpointType type = _gptToUse.Type;
// Reasoning models do not support the temperature setting.
_chatOptions.Temperature = _gptToUse.ModelInfo.Reasoning ? null : 0;

if (type is EndpointType.AzureOpenAI)
{
Expand Down