Unverified Commit 14910292 authored by Yeuoly's avatar Yeuoly Committed by GitHub

fix: openai tool tokens (#2026)

parent d8c0d722
...@@ -765,7 +765,6 @@ class OpenAILargeLanguageModel(_CommonOpenAI, LargeLanguageModel): ...@@ -765,7 +765,6 @@ class OpenAILargeLanguageModel(_CommonOpenAI, LargeLanguageModel):
num_tokens = 0 num_tokens = 0
for tool in tools: for tool in tools:
num_tokens += len(encoding.encode('type')) num_tokens += len(encoding.encode('type'))
num_tokens += len(encoding.encode(tool.get("type")))
num_tokens += len(encoding.encode('function')) num_tokens += len(encoding.encode('function'))
# calculate num tokens for function object # calculate num tokens for function object
......
...@@ -327,10 +327,35 @@ def test_get_num_tokens(): ...@@ -327,10 +327,35 @@ def test_get_num_tokens():
UserPromptMessage( UserPromptMessage(
content='Hello World!' content='Hello World!'
) )
],
tools=[
PromptMessageTool(
name='get_weather',
description='Determine weather in my location',
parameters={
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "The city and state e.g. San Francisco, CA"
},
"unit": {
"type": "string",
"enum": [
"c",
"f"
]
}
},
"required": [
"location"
]
}
),
] ]
) )
assert num_tokens == 21 assert num_tokens == 72
@pytest.mark.parametrize('setup_openai_mock', [['chat', 'remote']], indirect=True) @pytest.mark.parametrize('setup_openai_mock', [['chat', 'remote']], indirect=True)
def test_fine_tuned_models(setup_openai_mock): def test_fine_tuned_models(setup_openai_mock):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment