Merge pull request #498 from better629/feat_chatglm

fix zhipuapi's key to init openai api_key when using openai sdk
This commit is contained in:
better629 2023-11-21 19:38:22 +08:00 committed by GitHub
commit b17846401e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 1 deletions

View file

@ -24,7 +24,7 @@ def LLM() -> "BaseGPTAPI":
llm = Claude()
elif CONFIG.spark_api_key:
llm = SparkAPI()
elif CONFIG.zhipuai_api_key and CONFIG.zhipuai_api_key != "YOUR_API_KEY":
elif CONFIG.zhipuai_api_key:
llm = ZhiPuAIGPTAPI()
else:
raise RuntimeError("You should config a LLM configuration first")

View file

@ -13,6 +13,7 @@ from tenacity import (
)
from requests import ConnectionError
import openai
import zhipuai
from metagpt.config import CONFIG
@ -46,6 +47,7 @@ class ZhiPuAIGPTAPI(BaseGPTAPI):
def __init_zhipuai(self, config: CONFIG):
assert config.zhipuai_api_key
zhipuai.api_key = config.zhipuai_api_key
openai.api_key = zhipuai.api_key # due to use openai sdk, set the api_key but it will't be used.
def _const_kwargs(self, messages: list[dict]) -> dict:
kwargs = {