feat: add ask code via function.

This commit is contained in:
刘棒棒 2023-11-18 16:09:56 +08:00
parent adf40e6783
commit 0153bb5416
4 changed files with 120 additions and 6 deletions

View file

@ -0,0 +1,22 @@
import pytest
from metagpt.provider.openai_api import OpenAIGPTAPI
@pytest.mark.asyncio
async def test_aask_code():
llm = OpenAIGPTAPI()
msg = [{"role": "user", "content": "Write a python hello world code."}]
rsp = await llm.aask_code(msg) # -> {'language': 'python', 'code': "print('Hello, World!')"}
assert "language" in rsp
assert "code" in rsp
assert len(rsp["code"]) > 0
def test_ask_code():
llm = OpenAIGPTAPI()
msg = [{"role": "user", "content": "Write a python hello world code."}]
rsp = llm.ask_code(msg) # -> {'language': 'python', 'code': "print('Hello, World!')"}
assert "language" in rsp
assert "code" in rsp
assert len(rsp["code"]) > 0