baidubce / app-builder

appbuilder-sdk, 千帆AppBuilder-SDK帮助开发者灵活、快速的搭建AI原生应用
https://appbuilder.cloud.baidu.com/
Apache License 2.0
439 stars 113 forks source link

python3.9.7 示例代码运行出错:Interval() takes no arguments #413

Closed xueyayang closed 1 month ago

xueyayang commented 1 month ago
import appbuilder
import os

# 设置环境中的TOKEN,以下TOKEN为访问和QPS受限的试用TOKEN,正式使用请替换为您的个人TOKEN
os.environ["APPBUILDER_TOKEN"] = "bce-v3/ALTAK-n5AYUIUJMarF7F7iFXVeK/1bf65eed7c8c7efef9b11388524fa1087f90ea58"

# 从AppBuilder网页获取并传入应用ID,以下为地理小达人应用ID
app_id = "42eb211a-14b9-43d2-9fae-193c8760ef26"

app_builder_client = appbuilder.AppBuilderClient(app_id)
conversation_id = app_builder_client.create_conversation()

answer = app_builder_client.run(conversation_id, "中国的首都在哪里?春季天气怎么样?有什么适合玩的景点?")
print(answer.content)

输出:

c:\ATemp>python test.py Traceback (most recent call last): File "c:\ATemp\test.py", line 2, in import appbuilder File "C:\Python39\lib\site-packages\appbuilder__init.py", line 60, in from .core.components.rag_with_baidu_search_pro import RagWithBaiduSearchPro File "C:\Python39\lib\site-packages\appbuilder\core\components\rag_with_baidu_search_pro\init__.py", line 20, in from .component import RagWithBaiduSearchPro File "C:\Python39\lib\site-packages\appbuilder\core\components\rag_with_baidu_search_pro\component.py", line 21, in from appbuilder.core.components.rag_with_baidu_search_pro.parse_rag_pro_response import ParseRagProResponse File "C:\Python39\lib\site-packages\appbuilder\core\components\rag_with_baidu_search_pro\parse_rag_pro_response.py", line 16, in from appbuilder.core.components.llms.base import CompletionResponse File "C:\Python39\lib\site-packages\appbuilder\core\components\llms\base.py", line 69, in class ModelArgsConfig(BaseModel): File "C:\Python39\lib\site-packages\appbuilder\core\components\llms\base.py", line 71, in ModelArgsConfig temperature: confloat(gt=0.0, le=1.0) = Field(default=1e-10, description="模型的温度参数,范围从 0.0 到 1.0。") File "C:\Python39\lib\site-packages\pydantic\types.py", line 475, in confloat annotated_types.Interval(gt=gt, ge=ge, lt=lt, le=le), TypeError: Interval() takes no arguments

userpj commented 1 month ago

python --version看一下呢。pydantic有issue提到python 3.9.7有可能会报这个问题:https://github.com/pydantic/pydantic/issues/7544

xueyayang commented 1 month ago

python --version看一下呢。pydantic有issue提到python 3.9.7有可能会报这个问题:pydantic/pydantic#7544

c:\Python39>python --version Python 3.9.7

使用的是3.9.7. 升级3.12 后好了。谢谢。

c:\XueTest\QianFan>python --version Python 3.12.4

c:\XueTest\QianFan>python test.py answer='中国的首都是北京。\n\n北京的春季天气舒适,气温适中,雨水较少,适合出行^[1]^。\n\n北京春季适合玩的景点有很多 ,以下为您推荐:\n\n 天坛公园:了解古代皇帝祭祀的神圣场所^[1]^。\n 颐和园:欣赏皇家园林的瑰丽风光^[1]^。\n 圆明园:感受历史事件的震撼,见证遗址的独特魅力^[1]^。\n 南锣鼓巷:品味老北京的风土人情,感受独特的胡同文化^[1]^。\n 故宫博物院:城墙建筑,院落布局,都包含了古代人民的巧夺天工^[1]^。\n\n此外,还有八达岭长城、中国国家博物馆、国家 大剧院、北京环球度假区等著名景点,您可以根据自己的兴趣选择游玩地^[1]^。' events=[Event(code=0, message='', status='done', event_type='function_call', content_type='function_call', detail={'text': {'arguments': {'origin_query': '中国的首都在哪里?春季天气怎么样?有什么适合玩的景点?'}, 'component_code': 'RAGAgent', 'component_name': '知识问答'}}, usage=None), Event(code=0, message='', status='preparing', event_type='RAGAgent', content_type='status', detail={}, usage=None), Event(code=0, message='', status='done', event_type='RAGAgent', content_type='rag', detail={'name_cn': '网页搜索', 'references': [{'id': '1', 'content': '到北京旅游什么季节最好,北京必游景点,小...', 'type': 'web', 'from': 'search_baidu', 'title': '到北京旅游什么季节最好,北京必游景点,小白可直接冲!', 'url': 'https://baijiahao.baidu.com/s?id=1793663827757997486&wfr=spider&for=pc', 'resource_type': 'web'}, {'id': '2', 'content': ' 总之,三月份的北京是一个充满魅力的地方...', 'type': 'web', 'from': 'search_baidu', 'title': '春季来临,北京的魅力之旅', 'url': 'https://haokan.baidu.com/v?pd=wisenatural&vid=8205375580422526429', 'resource_type': 'video', 'video_url': 'https://vd3.bdstatic.com/mda-qdhfndq1px2k6ar4/hd/cae_h264/1713482096386312473/mda-qdhfndq1px2k6ar4.mp4'}], 'text': ''}, usage=None), Event(code=0, message='', status='done', event_type='RAGAgent', content_type='rag', detail={'name_cn': '网页搜索', 'text': '中国的首都是北京。\n\n北京的春季天气舒适,气温适中,雨水较少,适合出行^[1]^。\n\n北京春季适合玩的景点有很多,以下为您推荐:\n\n 天坛公园:了解古代皇帝 祭祀的神圣场所^[1]^。\n 颐和园:欣赏皇家园林的瑰丽风光^[1]^。\n 圆明园:感受历史事件的震撼,见证遗址的独特魅力^[1]^。\n 南锣鼓巷:品味老北京的风土人情,感受独特的胡同文化^[1]^。\n 故宫博物院:城墙建筑,院落布局,都包含了古代人民的巧夺天工^[1]^。\n\n此外,还有八达岭长城、中国国家博物馆、国家大剧院、北京环球度假区等著名景点,您可以根据自己 的兴趣选择游玩地^[1]^。', 'references': []}, usage=Usage(prompt_tokens=1084, completion_tokens=171, total_tokens=1255, name='ERNIE-4.0-8K')), Event(code=0, message='', status='success', event_type='RAGAgent', content_type='status', detail={}, usage=None)]