chore: add examples for ask_code and aask_code.

This commit is contained in:
刘棒棒 2023-11-18 18:33:00 +08:00
parent 218eeef4b8
commit 62254a184e

View file

@ -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!')"}
"""