🌟 The Multi-Agent Framework: First AI Software Company, Towards Natural Language Programming
rename example file and add more logs. add ping.py
geekancc0412b70da0
diff --git a/examples/llm_hello_world.py b/examples/hello_world.pysimilarity index 57%rename from examples/llm_hello_world.pyrename to examples/hello_world.pyindex 62fc2ed68..d28541522 100644--- a/examples/llm_hello_world.py+++ b/examples/hello_world.py@@ -3,7 +3,7 @@"""@Time : 2023/5/6 14:13@Author : alexanderwu-@File : llm_hello_world.py+@File : hello_world.py"""import asyncio@@ -11,20 +11,16 @@ from metagpt.llm import LLMfrom metagpt.logs import logger-async def main():- llm = LLM()- # llm type check- question = "what's your name"- logger.info(f"{question}: ")- logger.info(await llm.aask(question))- logger.info("\n\n")-- logger.info(- await llm.aask(- "who are you", system_msgs=["act as a robot, just answer 'I'am robot' if the question is 'who are you'"]- )- )+async def ask_and_print(question: str, llm: LLM, system_prompt) -> str:+ logger.info(f"Q: {question}")+ rsp = await llm.aask(question, system_msgs=[system_prompt])+ logger.info(f"A: {rsp}")+ logger.info("\n")+ return rsp++async def lowlevel_api_example(llm: LLM):+ logger.info("low level api example")logger.info(await llm.aask_batch(["hi", "write python hello world."]))hello_msg = [{"role": "user", "content": "count from 1 to 10. split by newline."}]@@ -39,5 +35,12 @@ async def main():logger.info(llm.completion(hello_msg))+async def main():+ llm = LLM()+ await ask_and_print("what's your name?", llm, "I'm a helpful AI assistant.")+ await ask_and_print("who are you?", llm, "just answer 'I'am robot' if the question is 'who are you'")+ await lowlevel_api_example(llm)++if __name__ == "__main__":asyncio.run(main())diff --git a/examples/ping.py b/examples/ping.pynew file mode 100644index 000000000..20eab5cb0--- /dev/null+++ b/examples/ping.py@@ -0,0 +1,29 @@+#!/usr/bin/env python+# -*- coding: utf-8 -*-+"""+@Time : 2024/4/22 14:28+@Author : alexanderwu+@File : ping.py+"""++import asyncio++from metagpt.llm import LLM+from metagpt.logs import logger+++async def ask_and_print(question: str, llm: LLM, system_prompt) -> str:+ logger.info(f"Q: {question}")+ rsp = await llm.aask(question, system_msgs=[system_prompt])+ logger.info(f"A: {rsp}")+ logger.info("\n")+ return rsp+++async def main():+ llm = LLM()+ await ask_and_print("ping?", llm, "Just answer pong when ping.")+++if __name__ == "__main__":+ asyncio.run(main())