Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
D
dify
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ai-tech
dify
Commits
14910292
Unverified
Commit
14910292
authored
Jan 14, 2024
by
Yeuoly
Committed by
GitHub
Jan 14, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: openai tool tokens (#2026)
parent
d8c0d722
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
2 deletions
+26
-2
llm.py
api/core/model_runtime/model_providers/openai/llm/llm.py
+0
-1
test_llm.py
api/tests/integration_tests/model_runtime/openai/test_llm.py
+26
-1
No files found.
api/core/model_runtime/model_providers/openai/llm/llm.py
View file @
14910292
...
...
@@ -765,7 +765,6 @@ class OpenAILargeLanguageModel(_CommonOpenAI, LargeLanguageModel):
num_tokens
=
0
for
tool
in
tools
:
num_tokens
+=
len
(
encoding
.
encode
(
'type'
))
num_tokens
+=
len
(
encoding
.
encode
(
tool
.
get
(
"type"
)))
num_tokens
+=
len
(
encoding
.
encode
(
'function'
))
# calculate num tokens for function object
...
...
api/tests/integration_tests/model_runtime/openai/test_llm.py
View file @
14910292
...
...
@@ -327,10 +327,35 @@ def test_get_num_tokens():
UserPromptMessage
(
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
)
def
test_fine_tuned_models
(
setup_openai_mock
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment