From 62254a184e485ab5bb5219b84c40660b56b216a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E6=A3=92=E6=A3=92?= Date: Sat, 18 Nov 2023 18:33:00 +0800 Subject: [PATCH] chore: add examples for ask_code and aask_code. --- metagpt/provider/openai_api.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/metagpt/provider/openai_api.py b/metagpt/provider/openai_api.py index 287668c83..8f8d45d73 100644 --- a/metagpt/provider/openai_api.py +++ b/metagpt/provider/openai_api.py @@ -284,6 +284,8 @@ class OpenAIGPTAPI(BaseGPTAPI, RateLimiter): Examples: >>> llm = OpenAIGPTAPI() + >>> llm.ask_code("Write a python hello world code.") + {'language': 'python', 'code': "print('Hello, World!')"} >>> msg = [{'role': 'user', 'content': "Write a python hello world code."}] >>> llm.ask_code(msg) {'language': 'python', 'code': "print('Hello, World!')"} @@ -292,13 +294,16 @@ class OpenAIGPTAPI(BaseGPTAPI, RateLimiter): rsp = self._chat_completion_function(messages, **kwargs) return self.get_choice_function_arguments(rsp) - async def aask_code(self, messages: list[dict], **kwargs) -> dict: + async def aask_code(self, messages: Union[str, Message, list[dict]], **kwargs) -> dict: """Use function of tools to ask a code. https://platform.openai.com/docs/api-reference/chat/create#chat-create-tools Examples: >>> llm = OpenAIGPTAPI() + >>> rsp = await llm.ask_code("Write a python hello world code.") + >>> rsp + {'language': 'python', 'code': "print('Hello, World!')"} >>> msg = [{'role': 'user', 'content': "Write a python hello world code."}] >>> rsp = await llm.aask_code(msg) # -> {'language': 'python', 'code': "print('Hello, World!')"} """