Skip to content

Commit d49d5ca

Browse files
committed
Fix an error and add model info for the o1 model
1 parent 7339570 commit d49d5ca

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@ namespace AIShell.OpenAI.Agent;
55
internal class ModelInfo
66
{
77
// Models gpt4, gpt3.5, and the variants of them all use the 'cl100k_base' token encoding.
8-
// But the gpt-4o model uses the 'o200k_base' token encoding. For reference:
9-
// https://github.com/openai/tiktoken/blob/5d970c1100d3210b42497203d6b5c1e30cfda6cb/tiktoken/model.py#L7
10-
// https://github.com/dmitry-brazhenko/SharpToken/blob/main/SharpToken/Lib/Model.cs#L8
8+
// But gpt-4o and o1 models use the 'o200k_base' token encoding. For reference:
9+
// https://github.com/openai/tiktoken/blob/63527649963def8c759b0f91f2eb69a40934e468/tiktoken/model.py
1110
private const string Gpt4oEncoding = "o200k_base";
1211
private const string Gpt34Encoding = "cl100k_base";
1312

@@ -21,6 +20,7 @@ static ModelInfo()
2120
// https://github.com/openai/openai-cookbook/blob/main/examples/How_to_count_tokens_with_tiktoken.ipynb
2221
s_modelMap = new(StringComparer.OrdinalIgnoreCase)
2322
{
23+
["o1"] = new(tokenLimit: 200_000, encoding: Gpt4oEncoding),
2424
["gpt-4o"] = new(tokenLimit: 128_000, encoding: Gpt4oEncoding),
2525
["gpt-4"] = new(tokenLimit: 8_192),
2626
["gpt-4-32k"] = new(tokenLimit: 32_768),

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ internal void CalibrateChatHistory(ChatTokenUsage usage, AssistantChatMessage re
7878
// Every reply is primed with <|start|>assistant<|message|>, so we subtract 3 from the 'InputTokenCount'.
7979
int promptTokenCount = usage.InputTokenCount - 3;
8080
// 'ReasoningTokenCount' should be 0 for non-o1 models.
81-
int responseTokenCount = usage.OutputTokenCount - usage.OutputTokenDetails.ReasoningTokenCount;
81+
int reasoningTokenCount = usage.OutputTokenDetails is null ? 0 : usage.OutputTokenDetails.ReasoningTokenCount;
82+
int responseTokenCount = usage.OutputTokenCount - reasoningTokenCount;
8283

8384
if (_totalInputToken is 0)
8485
{

0 commit comments

Comments
 (0)