update simple_scorer

This commit is contained in:
seehi 2024-07-08 20:55:32 +08:00
parent f61506bd32
commit 1ead3e4d80
6 changed files with 71 additions and 75 deletions

View file

@ -1,20 +1,27 @@
import asyncio
from metagpt.exp_pool.scorers import SimpleScorer
from metagpt.logs import logger
REQ = "Write a program to implement quicksort in python."
def echo(req: str):
"""Echo from req."""
RESP1 = """
def quicksort(arr):
return quicksort([x for x in arr[1:] if x <= arr[0]]) + [arr[0]] + quicksort([x for x in arr[1:] if x > arr[0]])
"""
return req
RESP2 = """
def quicksort(arr):
if len(arr) <= 1:
return arr
return quicksort([x for x in arr[1:] if x <= arr[0]]) + [arr[0]] + quicksort([x for x in arr[1:] if x > arr[0]])
"""
async def simple():
scorer = SimpleScorer()
score = await scorer.evaluate(echo, "data", ("data",))
logger.info(f"The score is: {score}")
await scorer.evaluate(req=REQ, resp=RESP1)
await scorer.evaluate(req=REQ, resp=RESP2)
async def main():