mirror of
https://github.com/Zippland/Snap-Solver.git
synced 2026-01-19 17:51:12 +08:00
51 lines
1.6 KiB
Python
51 lines
1.6 KiB
Python
from abc import ABC, abstractmethod
|
|
from typing import Generator, Any
|
|
|
|
class BaseModel(ABC):
|
|
def __init__(self, api_key: str, temperature: float = 0.7, system_prompt: str = None):
|
|
self.api_key = api_key
|
|
self.temperature = temperature
|
|
self.system_prompt = system_prompt or self.get_default_system_prompt()
|
|
|
|
@abstractmethod
|
|
def analyze_image(self, image_data: str, proxies: dict = None) -> Generator[dict, None, None]:
|
|
"""
|
|
Analyze the given image and yield response chunks.
|
|
|
|
Args:
|
|
image_data: Base64 encoded image data
|
|
proxies: Optional proxy configuration
|
|
|
|
Yields:
|
|
dict: Response chunks with status and content
|
|
"""
|
|
pass
|
|
|
|
@abstractmethod
|
|
def analyze_text(self, text: str, proxies: dict = None) -> Generator[dict, None, None]:
|
|
"""
|
|
Analyze the given text and yield response chunks.
|
|
|
|
Args:
|
|
text: Text to analyze
|
|
proxies: Optional proxy configuration
|
|
|
|
Yields:
|
|
dict: Response chunks with status and content
|
|
"""
|
|
pass
|
|
|
|
@abstractmethod
|
|
def get_default_system_prompt(self) -> str:
|
|
"""Return the default system prompt for this model"""
|
|
pass
|
|
|
|
@abstractmethod
|
|
def get_model_identifier(self) -> str:
|
|
"""Return the model identifier used in API calls"""
|
|
pass
|
|
|
|
def validate_api_key(self) -> bool:
|
|
"""Validate if the API key is in the correct format"""
|
|
return bool(self.api_key and self.api_key.strip())
|