diff --git a/README.md b/README.md index 03220c70a..2f533e57b 100644 --- a/README.md +++ b/README.md @@ -81,7 +81,8 @@ ERNIE-Bot 4.0, ERNIE-Bot-8K, ERNIE-Bot, ERNIE-Bot-turbo, EB-turbo-AppBuilder专 | ERNIE-Bot-8K | eb-8k | | ERNIE-Bot | eb | | ERNIE-Bot-turbo | eb-turbo | -| EB-turbo-AppBuilder专用版 | eb-turbo-appbuilder | +| EB-turbo-AppBuilder专用版 | ernie_speed_appbuilder | +| ERNIE Speed-AppBuilder | ernie_speed_appbuilder | ### 典型示例 @@ -94,7 +95,7 @@ import appbuilder # 空模版组件 template_str = "你扮演{role}, 请回答我的问题。\n\n问题:{question}。\n\n回答:" -playground = appbuilder.Playground(prompt_template=template_str, model="eb-turbo-appbuilder") +playground = appbuilder.Playground(prompt_template=template_str, model="ERNIE Speed-AppBuilder") # 定义输入,调用空模版组件 input = appbuilder.Message({"role": "java工程师", "question": "java语言的内存回收机制是什么"}) @@ -107,7 +108,7 @@ print(playground(input, stream=False, temperature=1e-10)) import appbuilder # 相似问生成组件 -similar_q = appbuilder.SimilarQuestion(model="eb-turbo-appbuilder") +similar_q = appbuilder.SimilarQuestion(model="ERNIE Speed-AppBuilder") # 定义输入,调用相似问生成 input = appbuilder.Message("我想吃冰淇淋,哪里的冰淇淋比较好吃?") @@ -149,7 +150,7 @@ import appbuilder # 空模版组件 playground = appbuilder.Playground( prompt_template="{query}", - model="eb-turbo-appbuilder" + model="ERNIE Speed-AppBuilder" ) # 使用 AgentRuntime 来服务化playground组件 @@ -196,7 +197,7 @@ class SimilarQuestion(CompletionBaseComponent): os.environ["APPBUILDER_TOKEN"] = "..." - qa_mining = appbuilder.SimilarQuestion(model="eb-turbo-appbuilder") + qa_mining = appbuilder.SimilarQuestion(model="ERNIE Speed-AppBuilder") msg = "我想吃冰淇淋,哪里的冰淇淋比较好吃?" msg = appbuilder.Message(msg) diff --git a/appbuilder/core/agent.py b/appbuilder/core/agent.py index c0f7fb288..d0efb11d9 100644 --- a/appbuilder/core/agent.py +++ b/appbuilder/core/agent.py @@ -104,7 +104,7 @@ class AgentRuntime(BaseModel): class PlaygroundWithHistory(Component): def __init__(self): super().__init__() - self.query_rewrite = QueryRewrite(model="eb-turbo-appbuilder") + self.query_rewrite = QueryRewrite(model="ERNIE Speed-AppBuilder") self.play = Playground( prompt_template="{query}", model="eb-4" diff --git a/appbuilder/core/components/gbi/basic.py b/appbuilder/core/components/gbi/basic.py index 28fa34b81..0a0b0d593 100644 --- a/appbuilder/core/components/gbi/basic.py +++ b/appbuilder/core/components/gbi/basic.py @@ -50,5 +50,5 @@ class ColumnItem(BaseModel): SUPPORTED_MODEL_NAME = { - "ERNIE-Bot 4.0", "ERNIE-Bot-8K", "ERNIE-Bot", "ERNIE-Bot-turbo", "EB-turbo-AppBuilder" + "ERNIE-Bot 4.0", "ERNIE-Bot-8K", "ERNIE-Bot", "ERNIE-Bot-turbo", "ERNIE Speed-AppBuilder" } diff --git a/appbuilder/core/components/gbi/nl2sql/README.md b/appbuilder/core/components/gbi/nl2sql/README.md index 763620119..b05eb817c 100644 --- a/appbuilder/core/components/gbi/nl2sql/README.md +++ b/appbuilder/core/components/gbi/nl2sql/README.md @@ -59,7 +59,7 @@ print(f"llm result: {nl2sql_result_message.content.llm_result}") ## 参数说明 ### 初始化参数 -- model_name: 支持的模型名字 ERNIE-Bot 4.0, ERNIE-Bot-8K, ERNIE-Bot, ERNIE-Bot-turbo, EB-turbo-AppBuilder" +- model_name: 支持的模型名字 ERNIE-Bot 4.0, ERNIE-Bot-8K, ERNIE-Bot, ERNIE-Bot-turbo, ERNIE Speed-AppBuilder - table_schemas: 表的 schema,例如: ``` diff --git a/appbuilder/core/components/gbi/nl2sql/component.py b/appbuilder/core/components/gbi/nl2sql/component.py index 9410a0067..e0c47ba9d 100644 --- a/appbuilder/core/components/gbi/nl2sql/component.py +++ b/appbuilder/core/components/gbi/nl2sql/component.py @@ -45,7 +45,7 @@ def __init__(self, model_name: str, table_schemas: List[str], knowledge: Dict = """ 创建 gbi nl2sql 对象 Args: - model_name: 支持的模型名字 ERNIE-Bot 4.0, ERNIE-Bot-8K, ERNIE-Bot, ERNIE-Bot-turbo, EB-turbo-AppBuilder + model_name: 支持的模型名字 ERNIE-Bot 4.0, ERNIE-Bot-8K, ERNIE-Bot, ERNIE-Bot-turbo, ERNIE Speed-AppBuilder table_schemas: 表的 schema 列表,例如: ``` CREATE TABLE `mytable` ( `d_year` COMMENT '年度,2019,2020..2022..', diff --git a/appbuilder/core/components/gbi/select_table/README.md b/appbuilder/core/components/gbi/select_table/README.md index 3d69be8f1..b5b0558e3 100644 --- a/appbuilder/core/components/gbi/select_table/README.md +++ b/appbuilder/core/components/gbi/select_table/README.md @@ -51,7 +51,7 @@ print(f"选的表是: {select_table_result_message.content}") ## 参数说明 ### 初始化参数 -- model_name: 支持的模型名字 ERNIE-Bot 4.0, ERNIE-Bot-8K, ERNIE-Bot, ERNIE-Bot-turbo, EB-turbo-AppBuilder +- model_name: 支持的模型名字 ERNIE-Bot 4.0, ERNIE-Bot-8K, ERNIE-Bot, ERNIE-Bot-turbo, ERNIE Speed-AppBuilder - table_descriptions: 表的描述是个字典,key: 是表的名字, value: 是表的描述,例如: ``` diff --git a/appbuilder/core/components/gbi/select_table/component.py b/appbuilder/core/components/gbi/select_table/component.py index 5bb0c5160..0dda8598f 100644 --- a/appbuilder/core/components/gbi/select_table/component.py +++ b/appbuilder/core/components/gbi/select_table/component.py @@ -41,7 +41,7 @@ def __init__(self, model_name: str, table_descriptions: Dict[str, str], """ 创建 GBI 选表对象 Args: - model_name: 支持的模型名字 ERNIE-Bot 4.0, ERNIE-Bot-8K, ERNIE-Bot, ERNIE-Bot-turbo, EB-turbo-AppBuilder + model_name: 支持的模型名字 ERNIE-Bot 4.0, ERNIE-Bot-8K, ERNIE-Bot, ERNIE-Bot-turbo, ERNIE Speed-AppBuilder table_descriptions: 表的描述是个字典,key: 是表的名字, value: 是表的描述,例如: { "超市营收明细表": "超市营收明细表,包含超市各种信息等", diff --git a/appbuilder/core/components/llms/dialog_summary/README.md b/appbuilder/core/components/llms/dialog_summary/README.md index d0a5783e1..303be03d6 100644 --- a/appbuilder/core/components/llms/dialog_summary/README.md +++ b/appbuilder/core/components/llms/dialog_summary/README.md @@ -23,7 +23,7 @@ import os # 请前往千帆AppBuilder官网创建密钥,流程详见:https://cloud.baidu.com/doc/AppBuilder/s/Olq6grrt6#1%E3%80%81%E5%88%9B%E5%BB%BA%E5%AF%86%E9%92%A5 os.environ["APPBUILDER_TOKEN"] = "bce-YOURTOKEN" -dialog_summary = appbuilder.DialogSummary("eb-turbo-appbuilder") +dialog_summary = appbuilder.DialogSummary("ERNIE Speed-AppBuilder") text = "用户:喂我想查一下我的话费\n坐席:好的女士您话费余的话还有87.49元钱\n用户:好的知道了谢谢\n坐席:嗯不客气祝您生活愉快再见" answer = dialog_summary(appbuilder.Message(text)) print(answer) diff --git a/appbuilder/core/components/llms/dialog_summary/component.py b/appbuilder/core/components/llms/dialog_summary/component.py index a34967b12..08d542ddf 100644 --- a/appbuilder/core/components/llms/dialog_summary/component.py +++ b/appbuilder/core/components/llms/dialog_summary/component.py @@ -44,7 +44,7 @@ class DialogSummary(CompletionBaseComponent): # 请前往千帆AppBuilder官网创建密钥,流程详见:https://cloud.baidu.com/doc/AppBuilder/s/Olq6grrt6#1%E3%80%81%E5%88%9B%E5%BB%BA%E5%AF%86%E9%92%A5 os.environ["APPBUILDER_TOKEN"] = '...' - dialog_summary = appbuilder.DialogSummary("eb-turbo-appbuilder") + dialog_summary = appbuilder.DialogSummary("ERNIE Speed-AppBuilder") text = "用户:喂我想查一下我的话费\n坐席:好的女士您话费余的话还有87.49元钱\n用户:好的知道了谢谢\n坐席:嗯不客气祝您生活愉快再见" answer = dialog_summary(appbuilder.Message(text)) print(answer) diff --git a/appbuilder/core/components/llms/is_complex_query/README.md b/appbuilder/core/components/llms/is_complex_query/README.md index f842b4e75..b3176fa7a 100644 --- a/appbuilder/core/components/llms/is_complex_query/README.md +++ b/appbuilder/core/components/llms/is_complex_query/README.md @@ -21,7 +21,7 @@ import appbuilder # 请前往千帆AppBuilder官网创建密钥,流程详见:https://cloud.baidu.com/doc/AppBuilder/s/Olq6grrt6#1%E3%80%81%E5%88%9B%E5%BB%BA%E5%AF%86%E9%92%A5 os.environ["APPBUILDER_TOKEN"] = "..." -is_complex_query = appbuilder.IsComplexQuery(model="eb-turbo-appbuilder") +is_complex_query = appbuilder.IsComplexQuery(model="ERNIE Speed-AppBuilder") msg = "吸塑包装盒在工业化生产和物流运输中分别有什么重要性?" msg = appbuilder.Message(msg) @@ -42,7 +42,7 @@ os.environ["APPBUILDER_TOKEN"] = "bce-YOURTOKEN" ### 初始化参数 |参数名称 |参数类型 |是否必须 |描述 |示例值| |--------|--------|--------|----|------| -|model |str |是 |模型名称,用于指定要使用的千帆模型|eb-turbo-appbuilder| +|model |str |是 |模型名称,用于指定要使用的千帆模型|ERNIE Speed-AppBuilder| ### 调用参数 |参数名称 |参数类型 |是否必须 |描述 |示例值| diff --git a/appbuilder/core/components/llms/is_complex_query/component.py b/appbuilder/core/components/llms/is_complex_query/component.py index 562835ada..f268d814d 100644 --- a/appbuilder/core/components/llms/is_complex_query/component.py +++ b/appbuilder/core/components/llms/is_complex_query/component.py @@ -42,7 +42,7 @@ class IsComplexQuery(CompletionBaseComponent): # 请前往千帆AppBuilder官网创建密钥,流程详见:https://cloud.baidu.com/doc/AppBuilder/s/Olq6grrt6#1%E3%80%81%E5%88%9B%E5%BB%BA%E5%AF%86%E9%92%A5 os.environ["APPBUILDER_TOKEN"] = "..." - is_complex_query = appbuilder.IsComplexQuery(model="eb-turbo-appbuilder") + is_complex_query = appbuilder.IsComplexQuery(model="ERNIE Speed-AppBuilder") msg = "吸塑包装盒在工业化生产和物流运输中分别有什么重要性?" msg = appbuilder.Message(msg) diff --git a/appbuilder/core/components/llms/mrc/README.md b/appbuilder/core/components/llms/mrc/README.md index 1a3f46964..c541ea427 100644 --- a/appbuilder/core/components/llms/mrc/README.md +++ b/appbuilder/core/components/llms/mrc/README.md @@ -9,7 +9,7 @@ MRC(阅读理解问答模块)是一项先进的自然语言处理功能, ### 特色优势 我们的MRC模块,基于百度自研的先进语言模型文新一言,提供了一系列强大的阅读理解问答功能。在保持文本理解和问题回答的高精度的同时, 我们特别强调了答案的质量和交互体验。以下是我们MRC模块的几个主要功能特色: - - 1.多版本模型支持:我们的MRC模块包括不同版本的文新一言大模型,Erniebot 4.0、EB-turbo-AppBuilder等,每个版本都针对特定的应用场景进行了优化。 用户可以根据自己的需求选择最适合的模型版本,以获得最佳的性能。 + - 1.多版本模型支持:我们的MRC模块包括不同版本的文新一言大模型,Erniebot 4.0、ERNIE Speed-AppBuilder等,每个版本都针对特定的应用场景进行了优化。 用户可以根据自己的需求选择最适合的模型版本,以获得最佳的性能。 - 2.答案格式的多样性: - 拒答功能:当问题超出模型知识范围或不具体时,模型可以选择不回答,避免提供误导性信息。 - 澄清功能:对于模棱两可或含糊的问题,模型可以请求更多信息或对问题进行澄清,以确保答案的准确性。 @@ -41,7 +41,7 @@ import os os.environ["APPBUILDER_TOKEN"] = "..." # 创建MRC对象 -mrc_component = appbuilder.MRC(model="eb-turbo-appbuilder") +mrc_component = appbuilder.MRC(model="ERNIE Speed-AppBuilder") # 初始化参数 msg = "残疾人怎么办相关证件" @@ -119,7 +119,7 @@ import os os.environ["APPBUILDER_TOKEN"] = '...' # 创建MRC对象 -mrc_component = appbuilder.MRC(model="eb-turbo-appbuilder") +mrc_component = appbuilder.MRC(model="ERNIE Speed-AppBuilder") # 初始化参数 msg = "残疾人怎么办相关证件" diff --git a/appbuilder/core/components/llms/nl2pandas/README.md b/appbuilder/core/components/llms/nl2pandas/README.md index cd7471856..e0a843f27 100644 --- a/appbuilder/core/components/llms/nl2pandas/README.md +++ b/appbuilder/core/components/llms/nl2pandas/README.md @@ -30,7 +30,7 @@ query = "海淀区有哪些学校" query = appbuilder.Message(query) #定义并运行Nl2pandas实例,得到结果 -nl2pandas = appbuilder.Nl2pandasComponent(model="eb-turbo-appbuilder") +nl2pandas = appbuilder.Nl2pandasComponent(model="ERNIE Speed-AppBuilder") answer = nl2pandas(query, table_info = table_info) ``` diff --git a/appbuilder/core/components/llms/nl2pandas/component.py b/appbuilder/core/components/llms/nl2pandas/component.py index 3fe14284f..ca4569ba7 100644 --- a/appbuilder/core/components/llms/nl2pandas/component.py +++ b/appbuilder/core/components/llms/nl2pandas/component.py @@ -55,7 +55,7 @@ class Nl2pandasComponent(CompletionBaseComponent): query = "海淀区有哪些学校" query = appbuilder.Message(query) - nl2pandas = appbuilder.Nl2pandasComponent(model="eb-turbo-appbuilder") + nl2pandas = appbuilder.Nl2pandasComponent(model="ERNIE Speed-AppBuilder") answer = nl2pandas(query, table_info = table_info) """ name = "nl2pandas" diff --git a/appbuilder/core/components/llms/oral_query_generation/README.md b/appbuilder/core/components/llms/oral_query_generation/README.md index 4989bfa5a..23a69e641 100644 --- a/appbuilder/core/components/llms/oral_query_generation/README.md +++ b/appbuilder/core/components/llms/oral_query_generation/README.md @@ -26,7 +26,7 @@ text = ('文档标题:在OPPO Reno5上使用视频超级防抖\n' '防抖 开启路径:打开「相机 > 视频 > 点击屏幕上方的“超级防抖”标识」 后置视频同时支持超级防抖和超级防抖Pro功能,开启超级' '防抖后手机屏幕将出现超级防抖Pro开关,点击即可开启或关闭。 除此之外,前置视频同样加持防抖算法,边走边拍也能稳定聚焦脸部' ',实时视频分享您的生活。') -oral_query_generation = appbuilder.OralQueryGeneration(model='eb-turbo-appbuilder') +oral_query_generation = appbuilder.OralQueryGeneration(model='ERNIE Speed-AppBuilder') result = oral_query_generation(appbuilder.Message(text)) print(result) ``` @@ -43,7 +43,7 @@ os.environ["APPBUILDER_TOKEN"] = "bce-YOURTOKEN" | 参数名称 | 参数类型 | 是否必须 | 描述 | 示例值 | | ------- | ------- | -------- | -------- | -------- | -| `model` | str | 否 | 模型名称,用于指定要使用的千帆模型。 | eb-turbo-appbuilder | +| `model` | str | 否 | 模型名称,用于指定要使用的千帆模型。 | ERNIE Speed-AppBuilder | | `secret_key` | str | 否 | 用户鉴权token,默认从环境变量中获取: `os.getenv("APPBUILDER_TOKEN", "")` | | | `gateway` | str | 否 | 后端网关服务地址,默认从环境变量中获取: `os.getenv("GATEWAY_URL", "")` | | | `lazy_certification` | bool | 否 | 延迟认证,为True时在第一次运行时认证。默认为False。 | False | diff --git a/appbuilder/core/components/llms/oral_query_generation/component.py b/appbuilder/core/components/llms/oral_query_generation/component.py index 65d48193d..8e45252aa 100644 --- a/appbuilder/core/components/llms/oral_query_generation/component.py +++ b/appbuilder/core/components/llms/oral_query_generation/component.py @@ -54,7 +54,7 @@ class OralQueryGeneration(CompletionBaseComponent): '防抖 开启路径:打开「相机 > 视频 > 点击屏幕上方的“超级防抖”标识」 后置视频同时支持超级防抖和超级防抖Pro功能,开启超级' '防抖后手机屏幕将出现超级防抖Pro开关,点击即可开启或关闭。 除此之外,前置视频同样加持防抖算法,边走边拍也能稳定聚焦脸部' ',实时视频分享您的生活。') - oral_query_generation = appbuilder.OralQueryGeneration(model='eb-turbo-appbuilder') + oral_query_generation = appbuilder.OralQueryGeneration(model='ERNIE Speed-AppBuilder') answer = oral_query_generation(appbuilder.Message(text)) print(answer.content) """ diff --git a/appbuilder/core/components/llms/playground/README.md b/appbuilder/core/components/llms/playground/README.md index 100afb7ed..f3c094701 100644 --- a/appbuilder/core/components/llms/playground/README.md +++ b/appbuilder/core/components/llms/playground/README.md @@ -26,7 +26,7 @@ os.environ["APPBUILDER_TOKEN"] = "..." play = appbuilder.Playground( prompt_template="你好,{name},我是{bot_name},{bot_name}是一个{bot_type},我可以{bot_function},你可以问我{bot_question}。", - model="eb-turbo-appbuilder" + model="ERNIE Speed-AppBuilder" ) play(appbuilder.Message({"name": "小明", "bot_name": "小红", "bot_type": "聊天机器人", "bot_function": "聊天", "bot_question": "你好吗?"}), stream=False) ``` diff --git a/appbuilder/core/components/llms/playground/component.py b/appbuilder/core/components/llms/playground/component.py index d27d2680f..c9a652d68 100644 --- a/appbuilder/core/components/llms/playground/component.py +++ b/appbuilder/core/components/llms/playground/component.py @@ -41,7 +41,7 @@ class Playground(CompletionBaseComponent): import appbuilder os.environ["APPBUILDER_TOKEN"] = "..." - play = appbuilder.Playground(prompt_template="你好,{name},我是{bot_name},{bot_name}是一个{bot_type},我可以{bot_function},你可以问我{bot_question}。", model="eb-turbo-appbuilder") + play = appbuilder.Playground(prompt_template="你好,{name},我是{bot_name},{bot_name}是一个{bot_type},我可以{bot_function},你可以问我{bot_question}。", model="ERNIE Speed-AppBuilder") play(appbuilder.Message({"name": "小明", "bot_name": "小红", "bot_type": "聊天机器人", "bot_function": "聊天", "bot_question": "你好吗?"}), stream=False) """ diff --git a/appbuilder/core/components/llms/qa_pair_mining/README.md b/appbuilder/core/components/llms/qa_pair_mining/README.md index 64e8cd03a..c2a575075 100644 --- a/appbuilder/core/components/llms/qa_pair_mining/README.md +++ b/appbuilder/core/components/llms/qa_pair_mining/README.md @@ -23,7 +23,7 @@ import appbuilder # 请前往千帆AppBuilder官网创建密钥,流程详见:https://cloud.baidu.com/doc/AppBuilder/s/Olq6grrt6#1%E3%80%81%E5%88%9B%E5%BB%BA%E5%AF%86%E9%92%A5 os.environ["APPBUILDER_TOKEN"] = "..." -qa_mining = appbuilder.QAPairMining(model="eb-turbo-appbuilder") +qa_mining = appbuilder.QAPairMining(model="ERNIE Speed-AppBuilder") # 输入文本(对此文本挖掘问答对) msg = '2017年,工商银行根据外部宏观环境变化,及时调整业务策略,优化资产负债结构,' + \ '保持存贷款业务协调发展,提升资产负债配置效率。' + \ @@ -110,7 +110,7 @@ split_result = splitter(parse_result) # 每个段落抽取问答对,并返回结果 for doc_segment in split_result.content["paragraphs"]: - qa_mining = QAPairMining(model="eb-turbo-appbuilder") + qa_mining = QAPairMining(model="ERNIE Speed-AppBuilder") text = doc_segment.get("text", "") if text == "": logger.error("Text is null. break") diff --git a/appbuilder/core/components/llms/qa_pair_mining/component.py b/appbuilder/core/components/llms/qa_pair_mining/component.py index a21496e1c..d68fde065 100644 --- a/appbuilder/core/components/llms/qa_pair_mining/component.py +++ b/appbuilder/core/components/llms/qa_pair_mining/component.py @@ -41,7 +41,7 @@ class QAPairMining(CompletionBaseComponent): os.environ["APPBUILDER_TOKEN"] = "..." - qa_mining = appbuilder.QAPairMining(model="eb-turbo-appbuilder") + qa_mining = appbuilder.QAPairMining(model="ERNIE Speed-AppBuilder") # 输入文本(对此文本挖掘问答对) msg = '2017年,工商银行根据外部宏观环境变化,及时调整业务策略,优化资产负债结构,' + \ '保持存贷款业务协调发展,提升资产负债配置效率。' + \ diff --git a/appbuilder/core/components/llms/query_decomposition/README.md b/appbuilder/core/components/llms/query_decomposition/README.md index f3c459aad..7a482b3cb 100644 --- a/appbuilder/core/components/llms/query_decomposition/README.md +++ b/appbuilder/core/components/llms/query_decomposition/README.md @@ -21,7 +21,7 @@ import appbuilder # 请前往千帆AppBuilder官网创建密钥,流程详见:https://cloud.baidu.com/doc/AppBuilder/s/Olq6grrt6#1%E3%80%81%E5%88%9B%E5%BB%BA%E5%AF%86%E9%92%A5 os.environ["APPBUILDER_TOKEN"] = "..." -query_decomposition = appbuilder.QueryDecomposition(model="eb-turbo-appbuilder") +query_decomposition = appbuilder.QueryDecomposition(model="ERNIE Speed-AppBuilder") msg = "吸塑包装盒在工业化生产和物流运输中分别有什么重要性?" msg = appbuilder.Message(msg) @@ -42,7 +42,7 @@ os.environ["APPBUILDER_TOKEN"] = "bce-YOURTOKEN" ### 初始化参数 |参数名称 |参数类型 |是否必须 |描述 |示例值| |--------|--------|--------|----|------| -|model |str |是 |模型名称,用于指定要使用的千帆模型|eb-turbo-appbuilder| +|model |str |是 |模型名称,用于指定要使用的千帆模型|ERNIE Speed-AppBuilder| ### 调用参数 |参数名称 |参数类型 |是否必须 |描述 |示例值| diff --git a/appbuilder/core/components/llms/query_decomposition/component.py b/appbuilder/core/components/llms/query_decomposition/component.py index e3f1a0e58..9bb54eb7b 100644 --- a/appbuilder/core/components/llms/query_decomposition/component.py +++ b/appbuilder/core/components/llms/query_decomposition/component.py @@ -42,7 +42,7 @@ class QueryDecomposition(CompletionBaseComponent): # 请前往千帆AppBuilder官网创建密钥,流程详见:https://cloud.baidu.com/doc/AppBuilder/s/Olq6grrt6#1%E3%80%81%E5%88%9B%E5%BB%BA%E5%AF%86%E9%92%A5 os.environ["APPBUILDER_TOKEN"] = "..." - query_decomposition = appbuilder.QueryDecomposition(model="eb-turbo-appbuilder") + query_decomposition = appbuilder.QueryDecomposition(model="ERNIE Speed-AppBuilder") msg = "吸塑包装盒在工业化生产和物流运输中分别有什么重要性?" msg = appbuilder.Message(msg) diff --git a/appbuilder/core/components/llms/query_rewrite/README.md b/appbuilder/core/components/llms/query_rewrite/README.md index a701beee1..cee4fe0ba 100644 --- a/appbuilder/core/components/llms/query_rewrite/README.md +++ b/appbuilder/core/components/llms/query_rewrite/README.md @@ -24,7 +24,7 @@ import appbuilder os.environ["APPBUILDER_TOKEN"] = '...' # 初始化并使用 QueryRewrite 组件 -query_rewrite = appbuilder.QueryRewrite(model="eb-turbo-appbuilder") +query_rewrite = appbuilder.QueryRewrite(model="ERNIE Speed-AppBuilder") answer = query_rewrite(appbuilder.Message(['我应该怎么办理护照?', '您可以查询官网或人工咨询', '我需要准备哪些材料?', '身份证、免冠照片一张以及填写完整的《中国公民因私出国(境)申请表》', '在哪里办']), rewrite_type="带机器人回复") print(answer) ``` diff --git a/appbuilder/core/components/llms/query_rewrite/component.py b/appbuilder/core/components/llms/query_rewrite/component.py index e4f061b77..3f84e7b17 100644 --- a/appbuilder/core/components/llms/query_rewrite/component.py +++ b/appbuilder/core/components/llms/query_rewrite/component.py @@ -71,7 +71,7 @@ class QueryRewrite(CompletionBaseComponent): import appbuilder os.environ["APPBUILDER_TOKEN"] = '...' - query_rewrite = appbuilder.QueryRewrite(model="eb-turbo-appbuilder") + query_rewrite = appbuilder.QueryRewrite(model="ERNIE Speed-AppBuilder") answer = query_rewrite(appbuilder.Message(['我应该怎么办理护照?', '您可以查询官网或人工咨询', '我需要准备哪些材料?', diff --git a/appbuilder/core/components/llms/similar_question/README.md b/appbuilder/core/components/llms/similar_question/README.md index a34d9f291..c7e46c0a4 100644 --- a/appbuilder/core/components/llms/similar_question/README.md +++ b/appbuilder/core/components/llms/similar_question/README.md @@ -23,7 +23,7 @@ import appbuilder # 请前往千帆AppBuilder官网创建密钥,流程详见:https://cloud.baidu.com/doc/AppBuilder/s/Olq6grrt6#1%E3%80%81%E5%88%9B%E5%BB%BA%E5%AF%86%E9%92%A5 os.environ["APPBUILDER_TOKEN"] = "..." -similar_question = appbuilder.SimilarQuestion(model="eb-turbo-appbuilder") +similar_question = appbuilder.SimilarQuestion(model="ERNIE Speed-AppBuilder") msg = "我想吃冰淇淋,哪里的冰淇淋比较好吃?" msg = appbuilder.Message(msg) diff --git a/appbuilder/core/components/llms/similar_question/component.py b/appbuilder/core/components/llms/similar_question/component.py index b813168de..70174cbe9 100644 --- a/appbuilder/core/components/llms/similar_question/component.py +++ b/appbuilder/core/components/llms/similar_question/component.py @@ -40,7 +40,7 @@ class SimilarQuestion(CompletionBaseComponent): os.environ["APPBUILDER_TOKEN"] = "..." - qa_mining = appbuilder.SimilarQuestion(model="eb-turbo-appbuilder") + qa_mining = appbuilder.SimilarQuestion(model="ERNIE Speed-AppBuilder") msg = "我想吃冰淇淋,哪里的冰淇淋比较好吃?" msg = appbuilder.Message(msg) diff --git a/appbuilder/core/components/llms/style_rewrite/README.md b/appbuilder/core/components/llms/style_rewrite/README.md index fa460bb35..cb0aaa7ba 100644 --- a/appbuilder/core/components/llms/style_rewrite/README.md +++ b/appbuilder/core/components/llms/style_rewrite/README.md @@ -33,7 +33,7 @@ import appbuilder os.environ["APPBUILDER_TOKEN"] = "..." # 初始化并使用 StyleRewrite 组件 -style_rewrite = appbuilder.StyleRewrite(model="eb-turbo-appbuilder") +style_rewrite = appbuilder.StyleRewrite(model="ERNIE Speed-AppBuilder") answer = style_rewrite(appbuilder.Message("文心大模型发布新版"), style="激励话术") ``` diff --git a/appbuilder/core/components/llms/style_rewrite/component.py b/appbuilder/core/components/llms/style_rewrite/component.py index 471f19d02..5c4f21dbd 100644 --- a/appbuilder/core/components/llms/style_rewrite/component.py +++ b/appbuilder/core/components/llms/style_rewrite/component.py @@ -77,7 +77,7 @@ class StyleRewrite(CompletionBaseComponent): import appbuilder os.environ["APPBUILDER_TOKEN"] = '...' - style_rewrite = appbuilder.StyleRewrite(model="eb-turbo-appbuilder") + style_rewrite = appbuilder.StyleRewrite(model="ERNIE Speed-AppBuilder") answer = style_rewrite(appbuilder.Message("文心大模型发布新版本"), style="激励话术") """ diff --git a/appbuilder/core/components/llms/style_writing/README.md b/appbuilder/core/components/llms/style_writing/README.md index b84817f92..44a11c8ef 100644 --- a/appbuilder/core/components/llms/style_writing/README.md +++ b/appbuilder/core/components/llms/style_writing/README.md @@ -26,7 +26,7 @@ import os # 请前往千帆AppBuilder官网创建密钥,流程详见:https://cloud.baidu.com/doc/AppBuilder/s/Olq6grrt6#1%E3%80%81%E5%88%9B%E5%BB%BA%E5%AF%86%E9%92%A5 os.environ["APPBUILDER_TOKEN"] = "..." -model = "eb-turbo-appbuilder" +model = "ERNIE Speed-AppBuilder" style_writing = appbuilder.StyleWriting(model) query = "帮我写一篇关于人体工学椅的文案" diff --git a/appbuilder/core/components/llms/style_writing/component.py b/appbuilder/core/components/llms/style_writing/component.py index 150e61fef..1f944363e 100644 --- a/appbuilder/core/components/llms/style_writing/component.py +++ b/appbuilder/core/components/llms/style_writing/component.py @@ -98,7 +98,7 @@ class StyleWriting(CompletionBaseComponent): # 请前往千帆AppBuilder官网创建密钥,流程详见:https://cloud.baidu.com/doc/AppBuilder/s/Olq6grrt6#1%E3%80%81%E5%88%9B%E5%BB%BA%E5%AF%86%E9%92%A5 os.environ["APPBUILDER_TOKEN"] = '...' - style_writing = appbuilder.StyleWriting(model="eb-turbo-appbuilder") + style_writing = appbuilder.StyleWriting(model="ERNIE Speed-AppBuilder") answer = style_writing(appbuilder.Message("帮我写一篇关于人体工学椅的文案"), style_query="小红书", length=100) """ diff --git a/appbuilder/core/components/llms/tag_extraction/README.md b/appbuilder/core/components/llms/tag_extraction/README.md index 34a348d06..2c40df958 100644 --- a/appbuilder/core/components/llms/tag_extraction/README.md +++ b/appbuilder/core/components/llms/tag_extraction/README.md @@ -31,7 +31,7 @@ import appbuilder # 请前往千帆AppBuilder官网创建密钥,流程详见:https://cloud.baidu.com/doc/AppBuilder/s/Olq6grrt6#1%E3%80%81%E5%88%9B%E5%BB%BA%E5%AF%86%E9%92%A5 os.environ["APPBUILDER_TOKEN"] = '...' -tag_extraction = appbuilder.TagExtraction(model="eb-turbo-appbuilder") +tag_extraction = appbuilder.TagExtraction(model="ERNIE Speed-AppBuilder") result = tag_extraction(appbuilder.Message("从这段文本中抽取关键标签")) ``` diff --git a/appbuilder/core/components/llms/tag_extraction/component.py b/appbuilder/core/components/llms/tag_extraction/component.py index 21af22f49..a69c4be2a 100644 --- a/appbuilder/core/components/llms/tag_extraction/component.py +++ b/appbuilder/core/components/llms/tag_extraction/component.py @@ -41,7 +41,7 @@ class TagExtraction(CompletionBaseComponent): # 请前往千帆AppBuilder官网创建密钥,流程详见:https://cloud.baidu.com/doc/AppBuilder/s/Olq6grrt6#1%E3%80%81%E5%88%9B%E5%BB%BA%E5%AF%86%E9%92%A5 os.environ["APPBUILDER_TOKEN"] = '...' - tag_extraction = appbuilder.TagExtraction(model="eb-turbo-appbuilder") + tag_extraction = appbuilder.TagExtraction(model="ERNIE Speed-AppBuilder") answer = tag_extraction(appbuilder.Message("从这段文本中抽取关键标签")) """ diff --git a/appbuilder/core/components/rag_with_baidu_search/README.md b/appbuilder/core/components/rag_with_baidu_search/README.md index 0ddbc9688..8d3ca4e1b 100644 --- a/appbuilder/core/components/rag_with_baidu_search/README.md +++ b/appbuilder/core/components/rag_with_baidu_search/README.md @@ -28,7 +28,7 @@ import os os.environ["APPBUILDER_TOKEN"] = '...' # 创建rag_with_baidusearch对象 -rag_with_baidusearch_component = appbuilder.RAGWithBaiduSearch(model="eb-turbo-appbuilder") +rag_with_baidusearch_component = appbuilder.RAGWithBaiduSearch(model="ERNIE Speed-AppBuilder") # 运行rag_with_baidusearch基本组件 msg = appbuilder.Message("残疾人怎么办相关证件") @@ -101,7 +101,7 @@ os.environ["APPBUILDER_TOKEN"] = '...' # 创建rag_with_baidusearch对象, 并初始化人设指令 rag_with_baidusearch_component = appbuilder.RAGWithBaiduSearch( - model="eb-turbo-appbuilder", + model="ERNIE Speed-AppBuilder", instruction=appbuilder.Message("你是问答助手,在回答问题前需要加上: 很高兴为您解答")) diff --git a/appbuilder/core/utils.py b/appbuilder/core/utils.py index 8b6c40859..ad7f40932 100644 --- a/appbuilder/core/utils.py +++ b/appbuilder/core/utils.py @@ -16,13 +16,15 @@ from urllib.parse import urlparse from appbuilder.core._client import HTTPClient from appbuilder.core._exception import TypeNotSupportedException, ModelNotSupportedException -from appbuilder.utils.model_util import GetModelListRequest, Models, model_name_mapping +from appbuilder.utils.model_util import GetModelListRequest, Models, RemoteModelCollector def utils_get_user_agent(): return 'appbuilder-sdk-python/{}'.format("__version__") - +# Todo(chengmo): 此处返回的模型名称为原始名称,并非推荐使用的short name +# 应当返回一个详细的列表,告知用户原始名 + 对应的short名 +# 同时考虑是否返回每个模型可用的余额 def get_model_list(secret_key: str = "", api_type_filter: List[str] = [], is_available: bool = False) -> list: """ 返回用户的模型列表。 @@ -85,10 +87,8 @@ def __init__(self, client: HTTPClient): def get_model_url(self, model_name: str) -> str: """获取模型在工作台网关的请求url""" origin_name = model_name - for key, value in model_name_mapping.items(): - if origin_name == value: - origin_name = key - break + remote_model_name_collector = RemoteModelCollector() + origin_name = remote_model_name_collector.get_remote_name_by_short_name(origin_name) for model in self.model_list: if model.name == origin_name: return convert_cloudhub_url(self.client, model.url) @@ -98,10 +98,8 @@ def get_model_url(self, model_name: str) -> str: def get_model_type(self, model_name: str) -> str: """获取模型类型""" origin_name = model_name - for key, value in model_name_mapping.items(): - if origin_name == value: - origin_name = key - break + remote_model_name_collector = RemoteModelCollector() + origin_name = remote_model_name_collector.get_remote_name_by_short_name(origin_name) for model in self.model_list: if model.name == origin_name: return model.apiType diff --git a/appbuilder/tests/test_dialog_summary.py b/appbuilder/tests/test_dialog_summary.py index 20a57bf85..96a63592d 100644 --- a/appbuilder/tests/test_dialog_summary.py +++ b/appbuilder/tests/test_dialog_summary.py @@ -28,7 +28,7 @@ def setUp(self): Returns: 无返回值,方法中执行了环境变量的赋值操作。 """ - self.model_name = "eb-turbo-appbuilder" + self.model_name = "ERNIE Speed-AppBuilder" self.node = appbuilder.DialogSummary(model=self.model_name) def test_run_with_default_params(self): @@ -49,12 +49,12 @@ def test_run_with_model_names(self): """测试不同的 stream 和 temperature 参数值""" chats = appbuilder.get_model_list(api_type_filter=["chat"]) - self.assertTrue("EB-turbo-AppBuilder专用版" in chats) + self.assertTrue("ERNIE Speed-AppBuilder专用版" in chats) - appbuilder.DialogSummary(model="EB-turbo-AppBuilder专用版") + appbuilder.DialogSummary(model="ERNIE Speed-AppBuilder专用版") with self.assertRaises(Exception): - appbuilder.DialogSummary(model="EB-turbo-AppBuilder-None") + appbuilder.DialogSummary(model="ERNIE Speed-AppBuilder-None") if __name__ == '__main__': diff --git a/appbuilder/tests/test_is_complex_query.py b/appbuilder/tests/test_is_complex_query.py index 1cc42d52d..2afe988bb 100644 --- a/appbuilder/tests/test_is_complex_query.py +++ b/appbuilder/tests/test_is_complex_query.py @@ -29,7 +29,7 @@ def setUp(self): Returns: 无返回值,方法中执行了环境变量的赋值操作。 """ - self.model_name = "eb-turbo-appbuilder" + self.model_name = "ERNIE Speed-AppBuilder" self.node = appbuilder.IsComplexQuery(model=self.model_name) def test_run_with_default_params(self): diff --git a/appbuilder/tests/test_mrc.py b/appbuilder/tests/test_mrc.py index 8e940f4a0..467ebbf9a 100644 --- a/appbuilder/tests/test_mrc.py +++ b/appbuilder/tests/test_mrc.py @@ -24,7 +24,7 @@ def setUp(self): return mrc class ''' # 设置环境变量和初始化TestMRCComponent实例 - self.model_name = "eb-turbo-appbuilder" + self.model_name = "ERNIE Speed-AppBuilder" self.mrc = appbuilder.MRC(model=self.model_name) def test_mrc_with_default_params(self): diff --git a/appbuilder/tests/test_nl2pandas.py b/appbuilder/tests/test_nl2pandas.py index 2b8bf03d9..470987d47 100644 --- a/appbuilder/tests/test_nl2pandas.py +++ b/appbuilder/tests/test_nl2pandas.py @@ -25,7 +25,7 @@ def setUp(self): """ 设置环境变量及必要数据。 """ - self.model_name = "eb-turbo-appbuilder" + self.model_name = "ERNIE Speed-AppBuilder" self.node = appbuilder.Nl2pandasComponent(model=self.model_name) self.table_info = '''表格列信息如下: 学校名 : 清华附小 , 字符串类型,代表小学学校的名称 diff --git a/appbuilder/tests/test_oral_query_generation.py b/appbuilder/tests/test_oral_query_generation.py index b9156ef5e..54da94218 100644 --- a/appbuilder/tests/test_oral_query_generation.py +++ b/appbuilder/tests/test_oral_query_generation.py @@ -38,7 +38,7 @@ def setUp(self): 无返回值,方法中执行了环境变量的赋值操作。 """ - self.model_name = 'eb-turbo-appbuilder' + self.model_name = 'ERNIE Speed-AppBuilder' self.node = appbuilder.OralQueryGeneration(model=self.model_name) def test_run_with_default_params(self): diff --git a/appbuilder/tests/test_qa_pair_mining.py b/appbuilder/tests/test_qa_pair_mining.py index fb1f6d390..d343e09b8 100644 --- a/appbuilder/tests/test_qa_pair_mining.py +++ b/appbuilder/tests/test_qa_pair_mining.py @@ -30,7 +30,7 @@ def setUp(self): Returns: 无返回值,方法中执行了环境变量的赋值操作。 """ - self.model_name = "eb-turbo-appbuilder" + self.model_name = "ERNIE Speed-AppBuilder" self.node = appbuilder.QAPairMining(model=self.model_name) def test_run_with_default_params(self): diff --git a/appbuilder/tests/test_query_decomposition.py b/appbuilder/tests/test_query_decomposition.py index 497e7e4e4..5baeff09d 100644 --- a/appbuilder/tests/test_query_decomposition.py +++ b/appbuilder/tests/test_query_decomposition.py @@ -29,7 +29,7 @@ def setUp(self): Returns: 无返回值,方法中执行了环境变量的赋值操作。 """ - self.model_name = "eb-turbo-appbuilder" + self.model_name = "ERNIE Speed-AppBuilder" self.node = appbuilder.QueryDecomposition(model=self.model_name) def test_run_with_default_params(self): diff --git a/appbuilder/tests/test_query_rewrite.py b/appbuilder/tests/test_query_rewrite.py index 20bf150b3..e7f90721e 100644 --- a/appbuilder/tests/test_query_rewrite.py +++ b/appbuilder/tests/test_query_rewrite.py @@ -32,7 +32,7 @@ def setUp(self): 无返回值。 """ # 设置环境变量和初始化TranslateComponent实例 - self.model_name = "eb-turbo-appbuilder" + self.model_name = "ERNIE Speed-AppBuilder" self.node = appbuilder.QueryRewrite(model=self.model_name) def test_run_with_default_params(self): @@ -54,7 +54,7 @@ def test_run_with_custom_params(self): def test_run_with_stream_and_temperature(self): """测试不同的 stream 和 temperature 参数值""" - node = appbuilder.QueryRewrite("eb-turbo-appbuilder") + node = appbuilder.QueryRewrite("ERNIE Speed-AppBuilder") query = ['我应该怎么办理护照?', '您可以查询官网或人工咨询', '我需要准备哪些材料?', '身份证、免冠照片一张以及填写完整的《中国公民因私出国(境)申请表》', '在哪里办'] msg = appbuilder.Message(query) answer = node(msg, rewrite_type="带机器人回复", stream=False, temperature=0.5) diff --git a/appbuilder/tests/test_rag_baidu_search.py b/appbuilder/tests/test_rag_baidu_search.py index 98321d8d8..d6042c494 100644 --- a/appbuilder/tests/test_rag_baidu_search.py +++ b/appbuilder/tests/test_rag_baidu_search.py @@ -11,7 +11,7 @@ def setUp(self): return rag_with_baidu_search class """ # 设置环境变量和初始化TestMRCComponent实例 - self.model_name = "eb-turbo-appbuilder" + self.model_name = "ERNIE Speed-AppBuilder" self.rag_with_baidu_search = appbuilder.RAGWithBaiduSearch(model=self.model_name) def test_rag_with_baidu_search(self): diff --git a/appbuilder/tests/test_similar_question.py b/appbuilder/tests/test_similar_question.py index aeb351232..a8e2d45f4 100644 --- a/appbuilder/tests/test_similar_question.py +++ b/appbuilder/tests/test_similar_question.py @@ -30,7 +30,7 @@ def setUp(self): 无返回值,方法中执行了环境变量的赋值操作。 """ - self.model_name = "eb-turbo-appbuilder" + self.model_name = "ERNIE Speed-AppBuilder" self.node = appbuilder.SimilarQuestion(model=self.model_name) def test_run_with_default_params(self): diff --git a/appbuilder/tests/test_style_rewrite.py b/appbuilder/tests/test_style_rewrite.py index 50fb1415d..243b3376e 100644 --- a/appbuilder/tests/test_style_rewrite.py +++ b/appbuilder/tests/test_style_rewrite.py @@ -31,7 +31,7 @@ def setUp(self): Returns: 无返回值,方法中执行了环境变量的赋值操作。 """ - self.model_name = "eb-turbo-appbuilder" + self.model_name = "ERNIE Speed-AppBuilder" self.node = appbuilder.StyleRewrite(model=self.model_name) def test_run_with_default_params(self): @@ -61,7 +61,7 @@ def test_run_with_invalid_params(self): def test_run_with_different_style(self): """测试不同的 style 参数值""" - node = appbuilder.StyleRewrite("eb-turbo-appbuilder") + node = appbuilder.StyleRewrite("ERNIE Speed-AppBuilder") msg = appbuilder.Message("测试消息") for style in StyleChoices: with self.subTest(style=style): @@ -70,7 +70,7 @@ def test_run_with_different_style(self): def test_run_with_stream_and_temperature(self): """测试不同的 stream 和 temperature 参数值""" - node = appbuilder.StyleRewrite("eb-turbo-appbuilder") + node = appbuilder.StyleRewrite("ERNIE Speed-AppBuilder") msg = appbuilder.Message("测试消息") answer = node(msg, style="激励话术", stream=False, temperature=0.5) self.assertIsNotNone(answer) diff --git a/appbuilder/tests/test_style_writing.py b/appbuilder/tests/test_style_writing.py index 0961018fa..7d9570b50 100644 --- a/appbuilder/tests/test_style_writing.py +++ b/appbuilder/tests/test_style_writing.py @@ -30,7 +30,7 @@ def setUp(self): Returns: 无返回值,方法中执行了环境变量的赋值操作。 """ - self.model_name = "eb-turbo-appbuilder" + self.model_name = "ERNIE Speed-AppBuilder" self.node = appbuilder.StyleWriting(model=self.model_name) def test_run_with_default_params(self): @@ -61,7 +61,7 @@ def test_run_with_invalid_params(self): def test_run_with_different_style_query(self): """测试不同的 style_query 参数值""" - node = appbuilder.StyleWriting("eb-turbo-appbuilder") + node = appbuilder.StyleWriting("ERNIE Speed-AppBuilder") msg = appbuilder.Message("测试消息") for style_query in StyleQueryChoices: with self.subTest(style_query=style_query): @@ -70,7 +70,7 @@ def test_run_with_different_style_query(self): def test_run_with_different_length(self): """测试不同的 length 参数值""" - node = appbuilder.StyleWriting("eb-turbo-appbuilder") + node = appbuilder.StyleWriting("ERNIE Speed-AppBuilder") msg = appbuilder.Message("测试消息") for length in LengthChoices: with self.subTest(length=length): @@ -79,7 +79,7 @@ def test_run_with_different_length(self): def test_run_with_stream_and_temperature(self): """测试不同的 stream 和 temperature 参数值""" - node = appbuilder.StyleWriting("eb-turbo-appbuilder") + node = appbuilder.StyleWriting("ERNIE Speed-AppBuilder") msg = appbuilder.Message("测试消息") answer = node(msg, style_query="通用", length=100, stream=False, temperature=0.5) self.assertIsNotNone(answer) diff --git a/appbuilder/tests/test_tag_extraction.py b/appbuilder/tests/test_tag_extraction.py index 87084d4ca..6224fa9e3 100644 --- a/appbuilder/tests/test_tag_extraction.py +++ b/appbuilder/tests/test_tag_extraction.py @@ -25,7 +25,7 @@ def setUp(self): Returns: 无返回值,方法中执行了环境变量的赋值操作。 """ - self.model_name = "eb-turbo-appbuilder" + self.model_name = "ERNIE Speed-AppBuilder" self.tag_extraction = appbuilder.TagExtraction(model=self.model_name) def test_run_with_default_params(self): diff --git a/appbuilder/utils/model_util.py b/appbuilder/utils/model_util.py index 91270594b..f7576c399 100644 --- a/appbuilder/utils/model_util.py +++ b/appbuilder/utils/model_util.py @@ -21,14 +21,106 @@ r"""模型名称到简称的映射. """ -model_name_mapping = { - "ERNIE-Bot 4.0": "eb-4", - "ERNIE-Bot-8K": "eb-8k", - "ERNIE-Bot": "eb", - "ERNIE-Bot-turbo": "eb-turbo", - "EB-turbo-AppBuilder专用版": "eb-turbo-appbuilder", -} +# Note(chengmo): 模型名称到简称的映射,是一个1:n的映射关系,之前的假设是模型与简称一一对应 +# 实际上,模型名称和简称之间存在多对一的关系,因此这里不能仅使用一个字典来存储名称映射信息 +model_name_mapping = [ + ("ERNIE-Bot 4.0", "eb-4"), + ("ERNIE-Bot-8K", "eb-8k"), + ("ERNIE-Bot", "eb"), + ("ERNIE-Bot-turbo", "eb-turbo"), + ("EB-turbo-AppBuilder专用版", "eb-turbo-appbuilder"), + ("EB-turbo-AppBuilder专用版", "ernie_speed_appbuilder"), + ("EB-turbo-AppBuilder专用版", "ERNIE Speed-AppBuilder"), +] + +class RemoteModel(object): + r"""远程模型类,用于封装远程模型的名称信息. + 参数: + name(str): + 模型名称。 + short_name(str): + 模型简称, 可能存在多个 + """ + def __init__(self, remote_name: str): + self.remote_name = remote_name + self.short_names = [] + + def register_short_name(self, short_name: str): + r"""注册模型简称. + 参数: + short_name(str): + 模型简称。 + """ + if short_name not in self.short_names: + self.short_names.append(short_name) + + def get_remote_name_by_short_name(self, short_name: str) -> Optional[str]: + r"""根据模型简称获取模型名称. + 参数: + short_name(str): + 模型简称。 + """ + # TODO(chengmo): 使用logging 替换 print,解决print多次的问题 + if short_name == "eb-turbo-appbuilder": + print("Deprecate warning: model [eb-turbo-appbuilder] is deprecated, please use [ERNIE Speed-AppBuilder]") + + if short_name in self.short_names: + return self.remote_name + return None + +class RemoteModelCollector(): + r"""远程模型收集器,用于收集远程模型信息. 是一个全局单例 + 有两个核心功能: + 1、注册远程模型名和本地short_name + 2、根据short_name获取远程模型名 + """ + _instance = None + _initialized = False + def __init__(self): + if self._initialized: + return + self._initialized = True + self.remote_models = {} + + def __new__(cls, *args, **kwargs): + """ + 单例模式 + """ + if cls._instance is None: + cls._instance = object.__new__(cls) + return cls._instance + + def register_remote_model_name(self, remote_name: str, short_name: str): + r"""注册远程模型名和本地short_name. + 参数: + remote_name(str): + 远程模型名称。 + short_name(str): + 模型简称。 + """ + if remote_name not in self.remote_models: + self.remote_models[remote_name] = RemoteModel(remote_name) + + self.remote_models[remote_name].register_short_name(short_name) + + def get_remote_name_by_short_name(self, short_name: str) -> Optional[str]: + r"""根据short_name获取远程模型名. + 参数: + short_name(str): + 模型简称。 + """ + for remote_model in self.remote_models.values(): + remote_name = remote_model.get_remote_name_by_short_name(short_name) + if remote_name is not None: + return remote_name + + return None + + +remote_model_collector = RemoteModelCollector() +for remote_name, short_name in model_name_mapping: + remote_model_collector.register_remote_model_name(remote_name, short_name) class GetModelListRequest(proto.Message): r"""获取模型列表请求体 @@ -253,14 +345,3 @@ def _check_service_error(request_id: str, data: dict): request_id=request_id, service_err_code=data["error_code"], service_err_message=data["error_msg"]) - - -def map_model_name(model_name: str) -> str: - r"""模型名称映射函数 - - 参数: - model_name (str) : 模型名称 - 返回: - str: 映射后的模型名称 - """ - return model_name_mapping.get(model_name, model_name) diff --git a/cookbooks/agent_runtime.ipynb b/cookbooks/agent_runtime.ipynb index 289006f25..1760bb52d 100644 --- a/cookbooks/agent_runtime.ipynb +++ b/cookbooks/agent_runtime.ipynb @@ -383,7 +383,7 @@ "class PlaygroundWithHistory(Component):\n", " def __init__(self):\n", " super().__init__()\n", - " self.query_rewrite = QueryRewrite(model=\"EB-turbo-AppBuilder专用版\")\n", + " self.query_rewrite = QueryRewrite(model=\"ERNIE Speed-AppBuilder\")\n", " self.playground = Playground(\n", " prompt_template=\"{query}\",\n", " model=\"ERNIE-Bot\"\n", diff --git a/cookbooks/rag.ipynb b/cookbooks/rag.ipynb index c71f49d66..07d5cb378 100644 --- a/cookbooks/rag.ipynb +++ b/cookbooks/rag.ipynb @@ -171,7 +171,7 @@ "具备团队协作精神,能够与团队成员有效沟通,共同推进项目进展。'''\n", "\n", "# 标签抽取的组件\n", - "tagger = appbuilder.TagExtraction(model=\"eb-turbo-appbuilder\")\n", + "tagger = appbuilder.TagExtraction(model=\"ERNIE Speed-AppBuilder\")\n", "\n", "# 从JD抽取标签并打印\n", "tags = tagger(appbuilder.Message(job_desc))\n", @@ -234,7 +234,7 @@ "\n", "play = appbuilder.Playground(\n", " prompt_template=\"基于候选人姓名、职责描述和简历内容,概括一下{name}的推荐理由。\\n候选人姓名: {name}\\n职责描述: {JD}\\n简历内容: {resume}\\n推荐理由: \",\n", - " model=\"eb-turbo-appbuilder\"\n", + " model=\"ERNIE Speed-AppBuilder\"\n", ")\n", "\n", "resume_summary = play(appbuilder.Message({\"JD\": job_desc, \"name\": sorted_resumes[0][0], \"resume\": \"\\n\".join(list(resume_content[sorted_resumes[0][0]]))}))\n", diff --git a/cookbooks/rag_with_baidusearch.ipynb b/cookbooks/rag_with_baidusearch.ipynb index f137b1fb4..8af26086b 100644 --- a/cookbooks/rag_with_baidusearch.ipynb +++ b/cookbooks/rag_with_baidusearch.ipynb @@ -82,8 +82,8 @@ "friendly = False # 友好度提升\n", "cite = True # 溯源\n", "\n", - "# 使用 eb-turbo-appbuilder 模型\n", - "component = appbuilder.RAGWithBaiduSearch(model=\"eb-turbo-appbuilder\")\n", + "# 使用 ERNIE Speed-AppBuilderder 模型\n", + "component = appbuilder.RAGWithBaiduSearch(model=\"ERNIE Speed-AppBuilderder\")\n", "query = appbuilder.Message(\"海淀区的面积是多少\")\n", "\n", "answer = component.run(\n", diff --git a/cookbooks/text_generation.ipynb b/cookbooks/text_generation.ipynb index e05143ce4..f9dd3d5f1 100644 --- a/cookbooks/text_generation.ipynb +++ b/cookbooks/text_generation.ipynb @@ -101,7 +101,7 @@ "商品信息:\n", "'''\n", "# 创建商品信息生成组件\n", - "product_information_generation = Playground(prompt_template=prompt_template, model='eb-turbo-appbuilder')\n", + "product_information_generation = Playground(prompt_template=prompt_template, model='ERNIE Speed-AppBuilder')\n", "\n", "# 获取商品信息\n", "# 填充prompt_template参数的参数映射表,需要与prompt_template对应\n", @@ -152,7 +152,7 @@ "from appbuilder import QAPairMining\n", "\n", "# 初始化问答对生成组件\n", - "qa_pair_mining = QAPairMining(model='eb-turbo-appbuilder')\n", + "qa_pair_mining = QAPairMining(model='ERNIE Speed-AppBuilder')\n", "\n", "# 获取问答对\n", "response = qa_pair_mining(Message(product_information), stream=False, temperature=1e-10)\n", @@ -210,7 +210,7 @@ "'''\n", "\n", "# 初始化风格写作组件\n", - "style_writing = StyleWriting(model='eb-turbo-appbuilder')\n", + "style_writing = StyleWriting(model='ERNIE Speed-AppBuilder')\n", "\n", "# 获取小红书文案\n", "response = style_writing(Message(query), style_query='小红书', length=300)\n", @@ -260,7 +260,7 @@ "from appbuilder import TagExtraction\n", "\n", "# 初始化标签抽取组件\n", - "tag_extraction = TagExtraction(model='eb-turbo-appbuilder')\n", + "tag_extraction = TagExtraction(model='ERNIE Speed-AppBuilder')\n", "\n", "# 获取标签\n", "response = tag_extraction(Message(copywriting), stream=False, temperature=1e-10)\n",