API Key checking
This commit is contained in:
Binary file not shown.
Binary file not shown.
@@ -6,4 +6,8 @@ Nutze nur dann Beispiele, wenn du gefragt wirst. Wenn möglich, antworte in etwa
|
|||||||
[assistant]
|
[assistant]
|
||||||
Verstanden.
|
Verstanden.
|
||||||
|
|
||||||
|
[user]
|
||||||
|
Kleiner Test, funktionierst du?
|
||||||
|
|
||||||
|
[assistant]
|
||||||
|
Offensichtlich.
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ Die Datei ist die einzige Quelle der Wahrheit. Dieses Modul stellt die
|
|||||||
Bausteine bereit, die auch das TUel (tui.py) verwendet.
|
Bausteine bereit, die auch das TUel (tui.py) verwendet.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
import os
|
||||||
import re
|
import re
|
||||||
import sys
|
import sys
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
@@ -24,9 +25,10 @@ from typing import Iterator
|
|||||||
|
|
||||||
from openai import OpenAI
|
from openai import OpenAI
|
||||||
|
|
||||||
BASE_URL = "http://127.0.0.1:8000/v1"
|
BASE_URL = "http://192.168.161.4:9161/v1"
|
||||||
MODEL = "glm-5.2-colibri"
|
MODEL = "glm-5.2-colibri"
|
||||||
MAX_TOKENS = 1024
|
MAX_TOKENS = 1024
|
||||||
|
API_KEY = os.environ.get("COLIBRI_API_KEY", "not-needed")
|
||||||
|
|
||||||
HEADER_RE = re.compile(r"^\[(system|assistant|user)\]\s*$", re.IGNORECASE)
|
HEADER_RE = re.compile(r"^\[(system|assistant|user)\]\s*$", re.IGNORECASE)
|
||||||
TRAILING_EMPTY_RE = re.compile(r"\n*\[(?:system|assistant|user)\][ \t]*\s*$", re.IGNORECASE)
|
TRAILING_EMPTY_RE = re.compile(r"\n*\[(?:system|assistant|user)\][ \t]*\s*$", re.IGNORECASE)
|
||||||
@@ -35,10 +37,11 @@ _client: OpenAI | None = None
|
|||||||
|
|
||||||
|
|
||||||
def client() -> OpenAI:
|
def client() -> OpenAI:
|
||||||
"""Lazy angelegter OpenAI-Client (lokaler Endpunkt, API-Key beliebig)."""
|
"""Lazy angelegter OpenAI-Client. Key aus COLIBRI_API_KEY, sonst Dummy
|
||||||
|
(der lokale Endpunkt braucht keinen)."""
|
||||||
global _client
|
global _client
|
||||||
if _client is None:
|
if _client is None:
|
||||||
_client = OpenAI(base_url=BASE_URL, api_key="not-needed")
|
_client = OpenAI(base_url=BASE_URL, api_key=API_KEY)
|
||||||
return _client
|
return _client
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user