Skip to content

Commit 78e51b9

Browse files
committed
Merge branch 'hotfix/remove-tongyi-usage-details'
2 parents 3f45dd5 + 3657a1a commit 78e51b9

4 files changed

Lines changed: 12 additions & 5 deletions

File tree

langfarm/hooks/langfuse/callback/langchain.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,15 @@ def _parse_usage(response: LLMResult):
3030
if generation_chunk.generation_info and (
3131
"token_usage" in generation_chunk.generation_info
3232
):
33-
llm_usage = _parse_usage_model(
33+
_usage = _parse_usage_model(
3434
generation_chunk.generation_info["token_usage"]
3535
)
36+
# 只上报3个字段
37+
llm_usage = {
38+
'input': _usage['input']
39+
, 'output': _usage['output']
40+
, 'total': _usage['total']
41+
}
3642
break
3743
if llm_usage is None:
3844
# 调用找到使用原来的函数找。

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 = "langfarm"
3-
version = "0.1.1"
3+
version = "0.1.2"
44
description = "LLM 相关工具集"
55
authors = ["chenlb <chenlbphoto@163.com>"]
66
license = "MIT"

scripts/test.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
set -e
44
set -x
55

6-
coverage run --source=langfarm,tests -m pytest
6+
coverage run --source=langfarm -m pytest
77
coverage report --show-missing
88
coverage html --title "${@-coverage}"

tests/test_hook_langfuse_callback.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import logging
2+
import os
23
import time
34
import unittest
45

@@ -15,7 +16,7 @@ class HookLangfuseCallbackTestCase(base.BaseTestCase):
1516

1617
def test_use_tongyi_with_langfuse_callback(self):
1718
query = '请用50个字描写春天的景色。'
18-
llm = Tongyi(model="qwen-plus")
19+
llm = Tongyi(model="qwen-plus", api_key=os.getenv('DASHSCOPE_API_KEY'))
1920
# base.BaseTestCase 的 setUpClass() 使用 load_dotenv() 加载了 .env 配置
2021
# LANGFUSE_PUBLIC_KEY
2122
# LANGFUSE_SECRET_KEY
@@ -52,7 +53,7 @@ def test_use_tongyi_with_langfuse_callback(self):
5253

5354
def test_use_tongyi_stream_with_langfuse_callback(self):
5455
query = '请用200个字描写春天的景色。'
55-
llm: BaseLLM = Tongyi(model="qwen-turbo")
56+
llm: BaseLLM = Tongyi(model="qwen-turbo", api_key=os.getenv('DASHSCOPE_API_KEY'))
5657
langfuse_handler = CallbackHandler(trace_name="Tongyi-stream")
5758
chunks = llm.stream(query, config={"callbacks": [langfuse_handler]})
5859
output_chunk = []

0 commit comments

Comments
 (0)