2024-04-07 22:27:00 -06:00
|
|
|
from typing import Union
|
|
|
|
|
2024-04-09 19:26:44 -06:00
|
|
|
from nio import RoomMessageImage
|
|
|
|
|
|
|
|
from matrix_gpt import MatrixClientHelper
|
2024-04-07 22:27:00 -06:00
|
|
|
from matrix_gpt.generate_clients.command_info import CommandInfo
|
|
|
|
|
|
|
|
|
|
|
|
class ApiClient:
|
|
|
|
_HUMAN_NAME = 'user'
|
|
|
|
_BOT_NAME = 'assistant'
|
|
|
|
|
2024-04-09 19:26:44 -06:00
|
|
|
def __init__(self, api_key: str, client_helper: MatrixClientHelper):
|
2024-04-10 16:42:52 -06:00
|
|
|
self._api_key = api_key
|
|
|
|
self._client_helper = client_helper
|
2024-04-07 22:27:00 -06:00
|
|
|
self._context = []
|
|
|
|
|
|
|
|
def _create_client(self, base_url: str = None):
|
|
|
|
raise NotImplementedError
|
|
|
|
|
2024-04-10 16:42:52 -06:00
|
|
|
def check_ignore_request(self):
|
|
|
|
return False
|
|
|
|
|
2024-04-07 22:27:00 -06:00
|
|
|
def assemble_context(self, messages: Union[str, list], system_prompt: str = None, injected_system_prompt: str = None):
|
|
|
|
raise NotImplementedError
|
|
|
|
|
2024-04-09 19:26:44 -06:00
|
|
|
def generate_text_msg(self, content: str, role: str):
|
|
|
|
raise NotImplementedError
|
|
|
|
|
2024-04-07 22:27:00 -06:00
|
|
|
def append_msg(self, content: str, role: str):
|
|
|
|
raise NotImplementedError
|
|
|
|
|
2024-04-09 19:26:44 -06:00
|
|
|
async def append_img(self, img_event: RoomMessageImage, role: str):
|
|
|
|
raise NotImplementedError
|
|
|
|
|
2024-04-07 22:27:00 -06:00
|
|
|
async def generate(self, command_info: CommandInfo):
|
|
|
|
raise NotImplementedError
|
|
|
|
|
|
|
|
@property
|
|
|
|
def context(self):
|
|
|
|
return self._context
|
|
|
|
|
|
|
|
@property
|
|
|
|
def HUMAN_NAME(self):
|
|
|
|
return self._HUMAN_NAME
|
|
|
|
|
|
|
|
@property
|
|
|
|
def BOT_NAME(self):
|
|
|
|
return self._BOT_NAME
|