18 lines
1.6 KiB
Python
18 lines
1.6 KiB
Python
#!/usr/bin/env python3
|
|
"""Nachprüfung zu Block A (#1263): Embeddings mit dem SDK-Standard, Feld `model`, ungültige Anfragen. Tunnel wie bei block_ab.py."""
|
|
import subprocess, sys, openai
|
|
KEY = subprocess.run(["ssh", "-o", "BatchMode=yes", "srv04", "cat /tmp/nexus-kern/key"], capture_output=True, text=True).stdout.strip()
|
|
c = openai.OpenAI(base_url="http://127.0.0.1:18100/v1", api_key=KEY, max_retries=0, timeout=600)
|
|
print("openai-SDK", openai.__version__)
|
|
def t(name, fn):
|
|
try: print(name, "->", fn())
|
|
except openai.APIStatusError as e: print(name, "-> Status", e.status_code, str(e.body)[:220])
|
|
except Exception as e: print(name, "->", type(e).__name__, str(e)[:220])
|
|
t("embeddings SDK-Standard", lambda: len(c.embeddings.create(model="bge-m3", input="Hallo").data[0].embedding))
|
|
t("embeddings float", lambda: len(c.embeddings.create(model="bge-m3", input="Hallo", encoding_format="float").data[0].embedding))
|
|
for m in (sys.argv[1:] or ["ollama-llama3.2-3b", "strata-qwen36-ud-q4_k_xl"]):
|
|
t(m + " model ohne Stream", lambda: c.chat.completions.create(model=m, messages=[{"role": "user", "content": "Hi"}], max_tokens=5).model)
|
|
t(m + " model im Stream", lambda: sorted({p.model for p in c.chat.completions.create(model=m, messages=[{"role": "user", "content": "Hi"}], max_tokens=5, stream=True)}))
|
|
t(m + " max_tokens als Text", lambda: c.chat.completions.create(model=m, messages=[{"role": "user", "content": "Hi"}], extra_body={"max_tokens": "viele"}).choices[0].finish_reason)
|
|
t(m + " ohne messages", lambda: c.post("/chat/completions", body={"model": m}, cast_to=object))
|