fix zhipuapi's key to init openai api_key when using openai sdk

This commit is contained in:
better629 2023-11-21 19:24:57 +08:00
parent f57355c889
commit 322aef6f1d
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 = {