quivr/backend/modules/brain/qa_interface.py
Stan Girard cd927ebdcf
feat: Add support for gpt-4o model (#2589)
This pull request adds support for the gpt-4o model to the existing
codebase. It includes changes to the BrainConfig, openAiFreeModels,
defineMaxTokens, model_compatible_with_function_calling, create_graph,
main, and process_assistant functions.
2024-05-13 14:07:41 -07:00

60 lines
1.5 KiB
Python

from abc import ABC, abstractmethod
from uuid import UUID
from modules.chat.dto.chats import ChatQuestion
class QAInterface(ABC):
"""
Abstract class for all QA interfaces.
This can be used to implement custom answer generation logic.
"""
@abstractmethod
def calculate_pricing(self):
raise NotImplementedError(
"calculate_pricing is an abstract method and must be implemented"
)
@abstractmethod
def generate_answer(
self,
chat_id: UUID,
question: ChatQuestion,
save_answer: bool,
*custom_params: tuple
):
raise NotImplementedError(
"generate_answer is an abstract method and must be implemented"
)
@abstractmethod
def generate_stream(
self,
chat_id: UUID,
question: ChatQuestion,
save_answer: bool,
*custom_params: tuple
):
raise NotImplementedError(
"generate_stream is an abstract method and must be implemented"
)
def model_compatible_with_function_calling(self, model: str):
if model in [
"gpt-4o",
"gpt-4-turbo",
"gpt-4-turbo-2024-04-09",
"gpt-4-turbo-preview",
"gpt-4-0125-preview",
"gpt-4-1106-preview",
"gpt-4",
"gpt-4-0613",
"gpt-3.5-turbo",
"gpt-3.5-turbo-0125",
"gpt-3.5-turbo-1106",
"gpt-3.5-turbo-0613",
]:
return True
return False