-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathtest_token_counting.py
More file actions
45 lines (39 loc) · 1.28 KB
/
Copy pathtest_token_counting.py
File metadata and controls
45 lines (39 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/usr/bin/env python3
from __future__ import annotations
import copy
import json
from agent_base.react_agent import MultiTurnReactAgent
def test_count_tokens_treats_special_token_literals_as_plain_text() -> None:
agent = MultiTurnReactAgent(
function_list=[],
llm={
"model": "fake-model",
"generate_cfg": {
"max_input_tokens": 32768,
"max_retries": 1,
"temperature": 0.0,
"top_p": 1.0,
"presence_penalty": 0.0,
},
},
)
messages = [
{"role": "tool", "content": "example text <|endoftext|> from a PDF"},
{
"role": "assistant",
"content": [{"type": "text", "text": "hello <|endoftext|>"}],
"tool_calls": [
{
"type": "function",
"function": {
"name": "Echo",
"arguments": json.dumps({"x": "<|endoftext|>"}),
},
}
],
"reasoning_content": {"note": "<|endoftext|>"},
},
]
original_messages = copy.deepcopy(messages)
assert agent.count_tokens(messages, include_tool_schema=False) > 0
assert messages == original_messages