@@ -34,6 +34,10 @@ utils = { index = "gitea" }
|
|||||||
[tool.black]
|
[tool.black]
|
||||||
target-version = [ "py314" ]
|
target-version = [ "py314" ]
|
||||||
|
|
||||||
|
[[tool.mypy.overrides]]
|
||||||
|
module = ["exiftool", "exiftool.*", "utils", "utils.*"]
|
||||||
|
ignore_missing_imports = true
|
||||||
|
|
||||||
[[tool.uv.index]]
|
[[tool.uv.index]]
|
||||||
name = "gitea"
|
name = "gitea"
|
||||||
url = "https://gitea.schneiderserver.site/api/packages/mathias2784/pypi/simple"
|
url = "https://gitea.schneiderserver.site/api/packages/mathias2784/pypi/simple"
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import re
|
|||||||
|
|
||||||
import openai
|
import openai
|
||||||
from openai import OpenAI
|
from openai import OpenAI
|
||||||
from pydantic import ValidationError
|
from pydantic import BaseModel, ValidationError
|
||||||
|
|
||||||
from photools3.models import (
|
from photools3.models import (
|
||||||
LlmMessageContent,
|
LlmMessageContent,
|
||||||
@@ -25,7 +25,8 @@ logger = logging.getLogger(__name__)
|
|||||||
class LlmSession:
|
class LlmSession:
|
||||||
base_url: str = str(settings.llm_api_base_url)
|
base_url: str = str(settings.llm_api_base_url)
|
||||||
api_key: str = settings.llm_api_key
|
api_key: str = settings.llm_api_key
|
||||||
response_model = LlmResponseGeneral
|
response_model: type[BaseModel] = LlmResponseGeneral
|
||||||
|
prompt: str = ""
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self, system_prompt: str, temperature: float = settings.llm_default_temperature
|
self, system_prompt: str, temperature: float = settings.llm_default_temperature
|
||||||
@@ -59,15 +60,15 @@ class LlmSession:
|
|||||||
|
|
||||||
def call(
|
def call(
|
||||||
self,
|
self,
|
||||||
prompt: str,
|
|
||||||
photos: list[Photo],
|
photos: list[Photo],
|
||||||
model_id=None,
|
model_id=None,
|
||||||
max_retries: int = 2,
|
max_retries: int = 2,
|
||||||
|
prompt: str | None = None,
|
||||||
):
|
):
|
||||||
if not model_id:
|
if not model_id:
|
||||||
model_id = self.models[0].id
|
model_id = self.models[0].id
|
||||||
|
|
||||||
request = self._build_request(prompt, photos, model_id)
|
request = self._build_request(prompt or self.prompt, photos, model_id)
|
||||||
|
|
||||||
last_error = None
|
last_error = None
|
||||||
for attempt in range(max_retries + 1):
|
for attempt in range(max_retries + 1):
|
||||||
@@ -147,6 +148,7 @@ class LlmSession:
|
|||||||
|
|
||||||
class LlmSessionCaptionsAndKeywords(LlmSession):
|
class LlmSessionCaptionsAndKeywords(LlmSession):
|
||||||
response_model = LlmResponseCaptionsAndKeywords
|
response_model = LlmResponseCaptionsAndKeywords
|
||||||
|
prompt = "Give me a caption and keyword for the following photo(s)"
|
||||||
|
|
||||||
def __init__(self, temperature: float = settings.llm_default_temperature):
|
def __init__(self, temperature: float = settings.llm_default_temperature):
|
||||||
super().__init__(
|
super().__init__(
|
||||||
@@ -159,16 +161,10 @@ class LlmSessionCaptionsAndKeywords(LlmSession):
|
|||||||
temperature=temperature,
|
temperature=temperature,
|
||||||
)
|
)
|
||||||
|
|
||||||
def call(self, photos: list[Photo], model_id=None):
|
|
||||||
return super().call(
|
|
||||||
prompt="Give me a caption and keyword for the following photo(s)",
|
|
||||||
photos=photos,
|
|
||||||
model_id=model_id,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class LlmSessionQuality(LlmSession):
|
class LlmSessionQuality(LlmSession):
|
||||||
response_model = LlmResponseQuality
|
response_model = LlmResponseQuality
|
||||||
|
prompt = "Assess the quality of the following photos to help me decide which ones to sort out"
|
||||||
|
|
||||||
def __init__(self, temperature: float = settings.llm_default_temperature):
|
def __init__(self, temperature: float = settings.llm_default_temperature):
|
||||||
super().__init__(
|
super().__init__(
|
||||||
@@ -180,10 +176,3 @@ class LlmSessionQuality(LlmSession):
|
|||||||
),
|
),
|
||||||
temperature=temperature,
|
temperature=temperature,
|
||||||
)
|
)
|
||||||
|
|
||||||
def call(self, photos: list[Photo], model_id=None):
|
|
||||||
return super().call(
|
|
||||||
prompt="Assess the quality of the following photos to help me decide which ones to sort out",
|
|
||||||
photos=photos,
|
|
||||||
model_id=model_id,
|
|
||||||
)
|
|
||||||
|
|||||||
@@ -22,4 +22,4 @@ class Settings(BaseSettings):
|
|||||||
metadata_prefix: str
|
metadata_prefix: str
|
||||||
|
|
||||||
|
|
||||||
settings = Settings() # type: ignore[reportCallIssue]
|
settings = Settings() # type: ignore[call-arg]
|
||||||
|
|||||||
Reference in New Issue
Block a user