File tree Expand file tree Collapse file tree
langfarm/hooks/langfuse/callback Expand file tree Collapse file tree Original file line number Diff line number Diff 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 # 调用找到使用原来的函数找。
Original file line number Diff line number Diff line change 11[tool .poetry ]
22name = " langfarm"
3- version = " 0.1.1 "
3+ version = " 0.1.2 "
44description = " LLM 相关工具集"
55authors = [" chenlb <chenlbphoto@163.com>" ]
66license = " MIT"
Original file line number Diff line number Diff line change 33set -e
44set -x
55
6- coverage run --source=langfarm,tests -m pytest
6+ coverage run --source=langfarm -m pytest
77coverage report --show-missing
88coverage html --title " ${@ -coverage} "
Original file line number Diff line number Diff line change 11import logging
2+ import os
23import time
34import 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 = []
You can’t perform that action at this time.
0 commit comments