2023-09-10 12:01:45 -07:00
|
|
|
from abc import ABC, abstractmethod
|
|
|
|
|
from typing import Dict
|
|
|
|
|
|
2023-08-23 11:19:16 -07:00
|
|
|
class AIFunction:
|
2023-08-22 17:11:20 -07:00
|
|
|
def __init__(self) -> None:
|
|
|
|
|
self.intro : str = None
|
|
|
|
|
|
2023-09-10 12:01:45 -07:00
|
|
|
@abstractmethod
|
|
|
|
|
def get_name(self) -> str:
|
|
|
|
|
"""
|
|
|
|
|
return the name of the function (should be snake case)
|
|
|
|
|
"""
|
2023-08-22 17:11:20 -07:00
|
|
|
pass
|
|
|
|
|
|
2023-09-10 12:01:45 -07:00
|
|
|
@abstractmethod
|
|
|
|
|
def get_description(self) -> str:
|
|
|
|
|
"""
|
|
|
|
|
return a detailed description of what the function does
|
|
|
|
|
"""
|
2023-08-22 17:11:20 -07:00
|
|
|
pass
|
|
|
|
|
|
2023-09-10 12:01:45 -07:00
|
|
|
@abstractmethod
|
|
|
|
|
def get_parameters(self) -> Dict:
|
|
|
|
|
"""
|
|
|
|
|
Return the list of parameters to execute this function in the form of
|
|
|
|
|
JSON schema as specified in the OpenAI documentation:
|
|
|
|
|
https://platform.openai.com/docs/api-reference/chat/create#chat/create-parameters
|
|
|
|
|
"""
|
2023-08-22 17:11:20 -07:00
|
|
|
pass
|
|
|
|
|
|
2023-09-10 12:01:45 -07:00
|
|
|
@abstractmethod
|
|
|
|
|
def execute(self, **kwargs) -> Dict:
|
|
|
|
|
"""
|
|
|
|
|
Execute the function and return a JSON serializable dict.
|
|
|
|
|
The parameters are passed in the form of kwargs
|
|
|
|
|
"""
|
2023-08-22 17:11:20 -07:00
|
|
|
pass
|
|
|
|
|
|
2023-09-10 12:01:45 -07:00
|
|
|
@abstractmethod
|
|
|
|
|
def is_local(self) -> bool:
|
|
|
|
|
"""
|
|
|
|
|
is this function call need network?
|
|
|
|
|
"""
|
2023-08-22 17:11:20 -07:00
|
|
|
pass
|
|
|
|
|
|
2023-09-10 12:01:45 -07:00
|
|
|
@abstractmethod
|
|
|
|
|
def is_in_zone(self) -> bool:
|
|
|
|
|
"""
|
|
|
|
|
is this function call in Lan?
|
|
|
|
|
"""
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
@abstractmethod
|
|
|
|
|
def is_ready_only(self) -> bool:
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
#def load_from_config(self,config:dict) -> bool:
|
|
|
|
|
# pass
|
|
|
|
|
|
2023-08-22 17:11:20 -07:00
|
|
|
# call chain is a combination of ai_function,group of ai_function.
|
2023-08-23 11:19:16 -07:00
|
|
|
class CallChain:
|
2023-08-22 17:11:20 -07:00
|
|
|
def __init__(self) -> None:
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
def load_from_config(self,config:dict) -> bool:
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
async def execute(self):
|
|
|
|
|
pass
|