mirror of
https://github.com/FoundationAgents/MetaGPT.git
synced 2026-07-02 16:01:04 +02:00
Merge branch 'main' into feature-invoice-ocr-assistant
This commit is contained in:
commit
96d4f3b7e4
8 changed files with 109 additions and 21 deletions
|
|
@ -207,5 +207,11 @@ class WriteDesign(Action):
|
|||
prompt = prompt_template.format(context=context, format_example=format_example)
|
||||
# system_design = await self._aask(prompt)
|
||||
system_design = await self._aask_v1(prompt, "system_design", OUTPUT_MAPPING, format=format)
|
||||
# fix Python package name, we can't system_design.instruct_content.python_package_name = "xxx" since "Python package name" contain space, have to use setattr
|
||||
setattr(
|
||||
system_design.instruct_content,
|
||||
"Python package name",
|
||||
system_design.instruct_content.dict()["Python package name"].strip().strip("'").strip('"'),
|
||||
)
|
||||
await self._save(context, system_design)
|
||||
return system_design
|
||||
|
|
|
|||
40
metagpt/tools/moderation.py
Normal file
40
metagpt/tools/moderation.py
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
@Time : 2023/9/26 14:27
|
||||
@Author : zhanglei
|
||||
@File : moderation.py
|
||||
"""
|
||||
from typing import Union
|
||||
|
||||
from metagpt.llm import LLM
|
||||
|
||||
|
||||
class Moderation:
|
||||
def __init__(self):
|
||||
self.llm = LLM()
|
||||
|
||||
def moderation(self, content: Union[str, list[str]]):
|
||||
resp = []
|
||||
if content:
|
||||
moderation_results = self.llm.moderation(content=content)
|
||||
results = moderation_results.results
|
||||
for item in results:
|
||||
resp.append(item.flagged)
|
||||
|
||||
return resp
|
||||
|
||||
async def amoderation(self, content: Union[str, list[str]]):
|
||||
resp = []
|
||||
if content:
|
||||
moderation_results = await self.llm.amoderation(content=content)
|
||||
results = moderation_results.results
|
||||
for item in results:
|
||||
resp.append(item.flagged)
|
||||
|
||||
return resp
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
moderation = Moderation()
|
||||
print(moderation.moderation(content=["I will kill you", "The weather is really nice today", "I want to hit you"]))
|
||||
|
|
@ -180,7 +180,7 @@ class OutputParser:
|
|||
|
||||
if start_index != -1 and end_index != -1:
|
||||
# Extract the structure part
|
||||
structure_text = text[start_index:end_index + 1]
|
||||
structure_text = text[start_index : end_index + 1]
|
||||
|
||||
try:
|
||||
# Attempt to convert the text to a Python data type using ast.literal_eval
|
||||
|
|
@ -238,7 +238,7 @@ class CodeParser:
|
|||
logger.error(f"{pattern} not match following text:")
|
||||
logger.error(text)
|
||||
# raise Exception
|
||||
return ""
|
||||
return text # just assume original text is code
|
||||
return code
|
||||
|
||||
@classmethod
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
import copy
|
||||
import pickle
|
||||
from typing import Dict, List, Tuple
|
||||
from typing import Dict, List
|
||||
|
||||
from metagpt.actions.action_output import ActionOutput
|
||||
from metagpt.schema import Message
|
||||
|
|
@ -37,8 +37,8 @@ def actionoutout_schema_to_mapping(schema: Dict) -> Dict:
|
|||
elif property["type"] == "array" and property["items"]["type"] == "string":
|
||||
mapping[field] = (List[str], ...)
|
||||
elif property["type"] == "array" and property["items"]["type"] == "array":
|
||||
# here only consider the `Tuple[str, str]` situation
|
||||
mapping[field] = (List[Tuple[str, str]], ...)
|
||||
# here only consider the `List[List[str]]` situation
|
||||
mapping[field] = (List[List[str]], ...)
|
||||
return mapping
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue