AI implementation for openai and claude.
This commit is contained in:
27
backend/app/services/provider_base.py
Normal file
27
backend/app/services/provider_base.py
Normal file
@@ -0,0 +1,27 @@
|
||||
from abc import ABC, abstractmethod
|
||||
from typing import AsyncGenerator
|
||||
|
||||
|
||||
class AIProvider(ABC):
|
||||
"""Abstract base class for AI providers"""
|
||||
|
||||
def __init__(self, api_key: str, model: str):
|
||||
self.api_key = api_key
|
||||
self.model = model
|
||||
|
||||
@abstractmethod
|
||||
async def chat(self, message: str, system_prompt: str = None) -> str:
|
||||
"""Non-streaming chat"""
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
async def chat_stream(
|
||||
self, message: str, system_prompt: str = None
|
||||
) -> AsyncGenerator[str, None]:
|
||||
"""Streaming chat - yields chunks of text"""
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_provider_name(self) -> str:
|
||||
"""Return provider identifier"""
|
||||
pass
|
||||
Reference in New Issue
Block a user