-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from ijwfly/feature/dalle-3
Dall-E 3 support with API usage calculation Function calling refactoring Readme update for easier installation settings.py comments clarification (thanks @yaroslavyaroslav for idea and contribution)
- Loading branch information
Showing
18 changed files
with
406 additions
and
146 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
from typing import Optional | ||
|
||
import pydantic | ||
from aiogram.types import Message | ||
from abc import ABC, abstractmethod | ||
|
||
|
||
class OpenAIFunctionParams(pydantic.BaseModel): | ||
pass | ||
|
||
|
||
class OpenAIFunction(ABC): | ||
PARAMS_SCHEMA = OpenAIFunctionParams | ||
|
||
def __init__(self, user, db, context_manager, message: Message): | ||
self.user = user | ||
self.db = db | ||
self.context_manager = context_manager | ||
self.message = message | ||
|
||
@abstractmethod | ||
async def run(self, params: OpenAIFunctionParams) -> Optional[str]: | ||
pass | ||
|
||
async def run_dict_args(self, params: dict): | ||
try: | ||
params = self.PARAMS_SCHEMA(**params) | ||
except Exception as e: | ||
return f"Parsing error: {e}" | ||
return await self.run(params) | ||
|
||
async def run_str_args(self, params: str): | ||
try: | ||
params = self.PARAMS_SCHEMA.parse_raw(params) | ||
except Exception as e: | ||
return f"Parsing error: {e}" | ||
return await self.run(params) | ||
|
||
@classmethod | ||
@abstractmethod | ||
def get_description(cls) -> str: | ||
pass | ||
|
||
@classmethod | ||
def get_name(cls) -> str: | ||
return cls.__name__ | ||
|
||
@classmethod | ||
def get_params_schema(cls) -> dict: | ||
params_schema = cls.PARAMS_SCHEMA.schema() | ||
return params_schema | ||
|
||
@classmethod | ||
def get_system_prompt_addition(cls) -> Optional[str]: | ||
""" | ||
Returns text to add to system prompt when this function is added to context. You can use this to add | ||
additional instructions about how to use this function. | ||
""" | ||
return None |
Oops, something went wrong.