-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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
add your own LLM_api #1386
Conversation
add own_api.py to use your own LLM API
add you own LLMapi
metagpt/provider/own_api.py
Outdated
self.config = config | ||
self.use_system_prompt = False | ||
self.__init_ownapi() | ||
self.cost_manager = CostManager(token_costs=self.token_costs) |
There was a problem hiding this comment.
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.
metagpt/provider/own_api.py
Outdated
'Content-Type': 'application/json' | ||
} | ||
resp_json = None | ||
for i in range(666): |
There was a problem hiding this comment.
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): |
There was a problem hiding this comment.
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?
metagpt/provider/own_api.py
Outdated
|
||
|
||
def __init_ownapi(self): | ||
# finish your own init |
There was a problem hiding this comment.
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): |
There was a problem hiding this comment.
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): |
There was a problem hiding this comment.
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
修改了之前的问题
Here already has a qianfan provider, should we need to merge this PR? |
Since there is already a qianfan provider, this PR is closed |
在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_completion
和acompletion
:异步执行对话。_achat_completion_stream
:异步流式执行对话。主要功能
request_eb_dynamic_ppo
方法向ERNIE-Bot发送请求。结论
这段代码是一个复杂的Python模块,设计用于与百度智能云千帆大模型平台进行交互。它提供了配置初始化、请求发送、响应处理和异步支持等功能,适用于多种对话和续写任务。