Commit aab2c5f0 authored by Kantz's avatar Kantz
Browse files

temperaturen hinzugefügt

parent da60296c
......@@ -4,11 +4,13 @@ MATHPIX_APP_KEY=""
OPENAI_BASE_URL=""
OPENAI_API_KEY=""
OPENAI_CHAT_MODEL=""
OPENAI_CHAT_TEMPERATURE=""
OPENAI_EMBED_MODEL=""
POSTGRES_URL=""
OLLAMA_URL=""
OLLAMA_MODEL= ""
OLLAMA_TEMPERATURE=""
FRONTEND_URL=""
\ No newline at end of file
......@@ -12,6 +12,7 @@ class OllamaSettings:
model: str
timeout: float | None
keepalive: str | None
temperature: float | None
@dataclass(frozen=True)
......@@ -27,6 +28,7 @@ class OpenAIChatSettings:
api_key: str
model: str
timeout: float | None
temperature: float | None
@dataclass(frozen=True)
class MathpixSettings:
......@@ -60,6 +62,7 @@ def get_ollama_settings() -> OllamaSettings:
model=os.getenv("OLLAMA_MODEL", "qwen3"),
timeout=_read_float(os.getenv("OLLAMA_TIMEOUT")),
keepalive=os.getenv("OLLAMA_KEEPALIVE"),
temperature=_read_float(os.getenv("OLLAMA_TEMPERATURE")),
)
......@@ -89,6 +92,7 @@ def get_openai_chat_settings() -> OpenAIChatSettings | None:
api_key=api_key,
model=model,
timeout=_read_float(os.getenv("OPENAI_CHAT_TIMEOUT")),
temperature=_read_float(os.getenv("OPENAI_CHAT_TEMPERATURE")),
)
......
......@@ -21,10 +21,10 @@ def _chat_openai(messages: list[dict]) -> dict:
timeout = settings.timeout or 60.0
client = OpenAI(api_key=settings.api_key, base_url=settings.base_url, timeout=timeout)
response = client.chat.completions.create(
messages=messages,
model=settings.model,
)
kwargs = {"messages": messages, "model": settings.model}
if settings.temperature is not None:
kwargs["temperature"] = settings.temperature
response = client.chat.completions.create(**kwargs)
message = response.choices[0].message if response.choices else {}
return {"raw": response, "message": message}
......@@ -47,6 +47,8 @@ def chat(
kwargs["tools"] = tools
if settings.keepalive:
kwargs["keep_alive"] = settings.keepalive
if settings.temperature is not None:
kwargs["options"] = {"temperature": settings.temperature}
response = client.chat(**_filter_kwargs(client.chat, kwargs))
return {"raw": response, "message": _extract_message(response)}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment