mirror of
https://github.com/FoundationAgents/MetaGPT.git
synced 2026-06-20 15:38:09 +02:00
fixbug: Fix the confusion caused by the merging of _client, client, and async_client in the openai_api.py;Split Azure LLM and MetaGPT LLM from OpenAI LLM to reduce the number of variables defined in the Config class for compatibility.
This commit is contained in:
parent
4b4ccc60fc
commit
a90f52d4b6
8 changed files with 143 additions and 161 deletions
|
|
@ -15,15 +15,15 @@ import pytest
|
|||
|
||||
from metagpt.config import CONFIG, Config
|
||||
from metagpt.const import DEFAULT_WORKSPACE_ROOT
|
||||
from metagpt.llm import LLM
|
||||
from metagpt.logs import logger
|
||||
from metagpt.provider.openai_api import OpenAIGPTAPI as GPTAPI
|
||||
from metagpt.utils.git_repository import GitRepository
|
||||
|
||||
|
||||
class Context:
|
||||
def __init__(self):
|
||||
self._llm_ui = None
|
||||
self._llm_api = GPTAPI()
|
||||
self._llm_api = LLM(provider=CONFIG.get_default_llm_provider_enum())
|
||||
|
||||
@property
|
||||
def llm_api(self):
|
||||
|
|
|
|||
|
|
@ -5,47 +5,47 @@
|
|||
@Author : mashenquan
|
||||
@File : test_brain_memory.py
|
||||
"""
|
||||
import json
|
||||
from typing import List
|
||||
|
||||
import pydantic
|
||||
|
||||
from metagpt.memory.brain_memory import BrainMemory
|
||||
from metagpt.schema import Message
|
||||
|
||||
|
||||
def test_json():
|
||||
class Input(pydantic.BaseModel):
|
||||
history: List[str]
|
||||
solution: List[str]
|
||||
knowledge: List[str]
|
||||
stack: List[str]
|
||||
|
||||
inputs = [{"history": ["a", "b"], "solution": ["c"], "knowledge": ["d", "e"], "stack": ["f"]}]
|
||||
|
||||
for i in inputs:
|
||||
v = Input(**i)
|
||||
bm = BrainMemory()
|
||||
for h in v.history:
|
||||
msg = Message(content=h)
|
||||
bm.history.append(msg.dict())
|
||||
for h in v.solution:
|
||||
msg = Message(content=h)
|
||||
bm.solution.append(msg.dict())
|
||||
for h in v.knowledge:
|
||||
msg = Message(content=h)
|
||||
bm.knowledge.append(msg.dict())
|
||||
for h in v.stack:
|
||||
msg = Message(content=h)
|
||||
bm.stack.append(msg.dict())
|
||||
s = bm.json()
|
||||
m = json.loads(s)
|
||||
bm = BrainMemory(**m)
|
||||
assert bm
|
||||
for v in bm.history:
|
||||
msg = Message(**v)
|
||||
assert msg
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
test_json()
|
||||
# import json
|
||||
# from typing import List
|
||||
#
|
||||
# import pydantic
|
||||
#
|
||||
# from metagpt.memory.brain_memory import BrainMemory
|
||||
# from metagpt.schema import Message
|
||||
#
|
||||
#
|
||||
# def test_json():
|
||||
# class Input(pydantic.BaseModel):
|
||||
# history: List[str]
|
||||
# solution: List[str]
|
||||
# knowledge: List[str]
|
||||
# stack: List[str]
|
||||
#
|
||||
# inputs = [{"history": ["a", "b"], "solution": ["c"], "knowledge": ["d", "e"], "stack": ["f"]}]
|
||||
#
|
||||
# for i in inputs:
|
||||
# v = Input(**i)
|
||||
# bm = BrainMemory()
|
||||
# for h in v.history:
|
||||
# msg = Message(content=h)
|
||||
# bm.history.append(msg.dict())
|
||||
# for h in v.solution:
|
||||
# msg = Message(content=h)
|
||||
# bm.solution.append(msg.dict())
|
||||
# for h in v.knowledge:
|
||||
# msg = Message(content=h)
|
||||
# bm.knowledge.append(msg.dict())
|
||||
# for h in v.stack:
|
||||
# msg = Message(content=h)
|
||||
# bm.stack.append(msg.dict())
|
||||
# s = bm.json()
|
||||
# m = json.loads(s)
|
||||
# bm = BrainMemory(**m)
|
||||
# assert bm
|
||||
# for v in bm.history:
|
||||
# msg = Message(**v)
|
||||
# assert msg
|
||||
#
|
||||
#
|
||||
# if __name__ == "__main__":
|
||||
# test_json()
|
||||
|
|
|
|||
|
|
@ -28,27 +28,31 @@ class TestGPT:
|
|||
answer = llm_api.ask_code(["请扮演一个Google Python专家工程师,如果理解,回复明白", "写一个hello world"])
|
||||
logger.info(answer)
|
||||
assert len(answer) > 0
|
||||
except openai.NotFoundError:
|
||||
assert CONFIG.openai_api_type == "azure"
|
||||
except openai.BadRequestError:
|
||||
assert CONFIG.OPENAI_API_TYPE == "azure"
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_llm_api_aask(self, llm_api):
|
||||
answer = await llm_api.aask("hello chatgpt")
|
||||
answer = await llm_api.aask("hello chatgpt", stream=False)
|
||||
logger.info(answer)
|
||||
assert len(answer) > 0
|
||||
|
||||
answer = await llm_api.aask("hello chatgpt", stream=True)
|
||||
logger.info(answer)
|
||||
assert len(answer) > 0
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_llm_api_aask_code(self, llm_api):
|
||||
try:
|
||||
answer = await llm_api.aask_code(["请扮演一个Google Python专家工程师,如果理解,回复明白", "写一个hello world"])
|
||||
answer = await llm_api.aask_code(["请扮演一个Google Python专家工程师,如果理解,回复明白", "写一个hello world"], timeout=60)
|
||||
logger.info(answer)
|
||||
assert len(answer) > 0
|
||||
except openai.NotFoundError:
|
||||
assert CONFIG.openai_api_type == "azure"
|
||||
except openai.BadRequestError:
|
||||
assert CONFIG.OPENAI_API_TYPE == "azure"
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_llm_api_costs(self, llm_api):
|
||||
await llm_api.aask("hello chatgpt")
|
||||
await llm_api.aask("hello chatgpt", stream=False)
|
||||
costs = llm_api.get_costs()
|
||||
logger.info(costs)
|
||||
assert costs.total_cost > 0
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue