Skip to content

Commit 5ab6dfc

Browse files
committed
remove tiktoken and lcc support reasoning
1 parent 983b038 commit 5ab6dfc

5 files changed

Lines changed: 10 additions & 66 deletions

File tree

CHANGLOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## [0.1.27] - 2026-03-18
2+
### Fixed
3+
- remove tiktoken
4+
- lcc support reasoning
5+
16
## [0.1.26] - 2026-03-18
27
### Fixed
38
- update tiktoken to a weak dependency

cozeloop/integration/langchain/trace_callback.py

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
from cozeloop.integration.langchain.trace_model.llm_model import ModelTraceInput, ModelMeta, ModelTraceOutput, Message
2424
from cozeloop.integration.langchain.trace_model.prompt_template import PromptTraceOutput, Argument, PromptTraceInput
2525
from cozeloop.integration.langchain.trace_model.runtime import RuntimeInfo
26-
from cozeloop.integration.langchain.util import calc_token_usage, get_prompt_tag
26+
from cozeloop.integration.langchain.util import get_prompt_tag
2727

2828

2929
class LoopTracer:
@@ -291,21 +291,7 @@ def _get_model_token_tags(self, response: LLMResult, **kwargs: Any) -> Dict[str,
291291
if is_get_from_langchain:
292292
return result
293293
else:
294-
try:
295-
run_info = self.run_map[str(kwargs['run_id'])]
296-
if run_info is not None and run_info.model_meta is not None:
297-
model_name = run_info.model_meta.model_name
298-
input_messages = run_info.model_meta.message
299-
token_usage = {
300-
'input_tokens': calc_token_usage(input_messages, model_name),
301-
'output_tokens': calc_token_usage(response, model_name),
302-
'tokens': 0
303-
}
304-
token_usage['tokens'] = token_usage['input_tokens'] + token_usage['output_tokens']
305-
return token_usage
306-
except Exception as e:
307-
span_tags = {'error_info': repr(e), 'error_trace': traceback.format_exc()}
308-
return span_tags
294+
return {}
309295

310296
def _on_prompt_start(self, flow_span, serialized: Dict[str, Any], inputs: (Dict[str, Any], str),
311297
**kwargs: Any) -> None:

cozeloop/integration/langchain/util.py

Lines changed: 1 addition & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,7 @@
11
# Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
22
# SPDX-License-Identifier: MIT
33

4-
from typing import List, Dict, Union, Any, Optional
5-
from langchain_core.outputs import LLMResult, Generation, ChatGeneration
6-
7-
try:
8-
import tiktoken
9-
_cl100k_base_encoding = tiktoken.get_encoding('cl100k_base')
10-
except Exception:
11-
tiktoken = None # type: ignore[assignment]
12-
_cl100k_base_encoding = None
13-
14-
15-
def calc_token_usage(inputs: Union[List[Dict], LLMResult], model: str = 'gpt-3.5-turbo-0613'):
16-
"""Return the number of tokens used by a list of messages."""
17-
if tiktoken is None:
18-
return 0
19-
try:
20-
encoding = tiktoken.encoding_for_model(model)
21-
except KeyError:
22-
print('Warning: model not found. Using cl100k_base encoding.')
23-
encoding = _cl100k_base_encoding
24-
if model == 'gpt-3.5-turbo-0301':
25-
tokens_per_message = 4 # every message follows <|start|>{role/name}\n{content}<|end|>\n
26-
tokens_per_name = -1 # if there's a name, the role is omitted
27-
elif model.startswith(('gpt-3.5', 'gpt-35', 'gpt-4')):
28-
tokens_per_message = 3
29-
tokens_per_name = 1
30-
else:
31-
tokens_per_message = 3
32-
tokens_per_name = 1
33-
num_tokens = 0
34-
if isinstance(inputs, List):
35-
for message in inputs:
36-
num_tokens += tokens_per_message
37-
for key, value in message.items():
38-
num_tokens += len(encoding.encode(value))
39-
if key == 'name':
40-
num_tokens += tokens_per_name
41-
elif isinstance(inputs, LLMResult):
42-
for inner_generations in inputs.generations:
43-
for generation in inner_generations:
44-
if isinstance(generation, ChatGeneration):
45-
num_tokens += len(encoding.encode(generation.message.type)) + len(encoding.encode(generation.message.content))
46-
elif isinstance(generation, Generation):
47-
num_tokens += len(encoding.encode('ai')) + len(encoding.encode(generation.text))
48-
num_tokens += 3 # every reply is primed with <|start|>assistant<|message|>
49-
return num_tokens
50-
51-
4+
from typing import List
525

536
_startswith = 'fornax_prompt_tag'
547

cozeloop/internal/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
# Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
22
# SPDX-License-Identifier: MIT
33

4-
VERSION = 'v0.1.26'
4+
VERSION = 'v0.1.27'

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "cozeloop"
3-
version = "0.1.26"
3+
version = "0.1.27"
44
description = "coze loop sdk"
55
authors = ["JiangQi715 <jiangqi.rrt@bytedance.com>"]
66
license = "MIT"

0 commit comments

Comments
 (0)