Skip to content

Commit b70cd88

Browse files
authored
Merge pull request #630 from springasa/main
[Bugfix] Set openai proxy for class ZhiPuAPTAPI
2 parents 4f52b47 + a87b505 commit b70cd88

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

metagpt/provider/zhipuai_api.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ def __init_zhipuai(self, config: CONFIG):
5050
assert config.zhipuai_api_key
5151
zhipuai.api_key = config.zhipuai_api_key
5252
openai.api_key = zhipuai.api_key # due to use openai sdk, set the api_key but it will't be used.
53+
if config.openai_proxy:
54+
openai.proxy = config.openai_proxy
5355

5456
def _const_kwargs(self, messages: list[dict]) -> dict:
5557
kwargs = {"model": self.model, "prompt": messages, "temperature": 0.3}

tests/metagpt/provider/test_zhipuai_api.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,10 @@ async def test_zhipuai_acompletion(mocker):
3535

3636
assert resp["code"] == 200
3737
assert "chatglm-turbo" in resp["data"]["choices"][0]["content"]
38+
39+
def test_zhipuai_proxy(mocker):
40+
import openai
41+
from metagpt.config import CONFIG
42+
CONFIG.openai_proxy = 'http://127.0.0.1:8080'
43+
_ = ZhiPuAIGPTAPI()
44+
assert openai.proxy == CONFIG.openai_proxy

0 commit comments

Comments
 (0)