Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add your own LLM_api #1386

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open

add your own LLM_api #1386

wants to merge 5 commits into from

Conversation

xinyuzhidad
Copy link

在provider增加了own_api.py
这段代码是一个用于调用百度智能云千帆大模型平台API服务的Python模块。它定义了一个名为 ShaheLLM 的类,该类继承自 BaseLLM,并通过 register_provider 装饰器注册为语言模型提供者。以下是代码的功能和主要部分的介绍:

导入模块

代码首先导入了多个标准库和第三方库,包括 qianfan 库以及自定义的 metagpt 模块。

注册提供者

通过 register_provider 装饰器将 ShaheLLM 类注册为 LLMType.SHAHE 类型的提供者。类的文档字符串包含了一些参考链接,指向百度智能云千帆大模型平台的相关文档。

初始化方法

__init____init_shahe 方法负责初始化配置,包括设置环境变量、验证配置中的模型和端点、更新token费用、以及初始化 ChatCompletion 对象。

辅助方法

  • _const_kwargs:构建请求参数。
  • _update_costs:更新每次请求的token费用。
  • get_choice_text:从响应中获取结果文本。
  • request_eb_dynamic_ppo:向ERNIE-Bot发送请求并获取响应。
  • completion:执行一次对话并返回结果。
  • _achat_completionacompletion:异步执行对话。
  • _achat_completion_stream:异步流式执行对话。

主要功能

  • 初始化配置:通过环境变量或参数设置API Key和Secret Key。
  • 发送请求:通过 request_eb_dynamic_ppo 方法向ERNIE-Bot发送请求。
  • 处理响应:从响应中提取结果并更新token费用。
  • 支持异步操作:包括异步对话和流式对话。

结论

这段代码是一个复杂的Python模块,设计用于与百度智能云千帆大模型平台进行交互。它提供了配置初始化、请求发送、响应处理和异步支持等功能,适用于多种对话和续写任务。

add own_api.py to use your own LLM API
add you own LLMapi
self.config = config
self.use_system_prompt = False
self.__init_ownapi()
self.cost_manager = CostManager(token_costs=self.token_costs)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

refs to https://docs.deepwisdom.ai/main/en/guide/contribute/contribute_guide.html#before-submission to use pre-commit before commit.

'Content-Type': 'application/json'
}
resp_json = None
for i in range(666):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why 666?

)

@register_provider(LLMType.SHAHE)
class OwnLLM(BaseLLM):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why another own_api.py?



def __init_ownapi(self):
# finish your own init
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems not a complete code

)

@register_provider(LLMType.SHAHE)
class OwnLLM(BaseLLM):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should add unit-test code

)

@register_provider(LLMType.SHAHE)
class OwnLLM(BaseLLM):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's the difference with https://github.com/geekan/MetaGPT/blob/main/metagpt/provider/qianfan_api.py

修改了之前的问题
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants