VanteroVantero API
App

Tutorials

Praktische Beispiele und Anleitungen für fortgeschrittene Features.

Streaming-Antworten
Einsteiger
5 Min.

Erhalten Sie Antworten in Echtzeit mit Server-Sent Events.

streaming.pypython
1from openai import OpenAI
2
3client = OpenAI(
4 api_key="sk_vantero_...",
5 base_url="https://api.vantero.chat/v1"
6)
7
8# Streaming aktivieren
9stream = client.chat.completions.create(
10 model="mistral-small",
11 messages=[{"role": "user", "content": "Erkläre mir KI"}],
12 stream=True # Wichtig!
13)
14
15for chunk in stream:
16 if chunk.choices[0].delta.content:
17 print(chunk.choices[0].delta.content, end="")
18
19# SSE Format Beispiel:
20# data: {"id":"chatcmpl-abc123","choices":[{"delta":{"content":"KI"},...}]}
21# data: {"id":"chatcmpl-abc123","choices":[{"delta":{"content":" steht"},...}]}
22# data: [DONE]
Function Calling (Tools)
Fortgeschritten
10 Min.

Ermöglichen Sie dem Modell, externe Funktionen aufzurufen.

tools.pypython
1from openai import OpenAI
2
3client = OpenAI(
4 api_key="sk_vantero_...",
5 base_url="https://api.vantero.chat/v1"
6)
7
8# Tool/Function definieren
9tools = [
10 {
11 "type": "function",
12 "function": {
13 "name": "get_weather",
14 "description": "Aktuelle Wetterdaten für einen Ort abrufen",
15 "parameters": {
16 "type": "object",
17 "properties": {
18 "location": {
19 "type": "string",
20 "description": "Stadt, z.B. 'Berlin'"
21 },
22 "unit": {
23 "type": "string",
24 "enum": ["celsius", "fahrenheit"],
25 "description": "Temperatureinheit"
26 }
27 },
28 "required": ["location"]
29 }
30 }
31 }
32]
33
34response = client.chat.completions.create(
35 model="mistral-small",
36 messages=[{"role": "user", "content": "Wie ist das Wetter in Berlin?"}],
37 tools=tools,
38 tool_choice="auto" # oder "required" oder "none"
39)
40
41# Prüfen ob Tool aufgerufen wurde
42if response.choices[0].finish_reason == "tool_calls":
43 tool_call = response.choices[0].message.tool_calls[0]
44 print(f"Tool: {tool_call.function.name}")
45 print(f"Arguments: {tool_call.function.arguments}")
46
47# Tool-Call Response Beispiel:
48# {
49# "id": "chatcmpl-abc123",
50# "choices": [{
51# "message": {
52# "role": "assistant",
53# "tool_calls": [{
54# "id": "call_xyz789",
55# "type": "function",
56# "function": {
57# "name": "get_weather",
58# "arguments": "{\"location\": \"Berlin\", \"unit\": \"celsius\"}"
59# }
60# }]
61# },
62# "finish_reason": "tool_calls"
63# }]
64# }
Bildanalyse (Vision)
Einsteiger
5 Min.

Analysieren Sie Bilder mit multimodalen Modellen.

vision.pypython
1from openai import OpenAI
2
3client = OpenAI(
4 api_key="sk_vantero_...",
5 base_url="https://api.vantero.chat/v1"
6)
7
8# Bild-Analyse mit URL
9response = client.chat.completions.create(
10 model="mistral-small", # Muss Bild-Feature unterstützen
11 messages=[
12 {
13 "role": "user",
14 "content": [
15 {"type": "text", "text": "Was siehst du auf diesem Bild?"},
16 {"type": "image_url", "image_url": {"url": "https://example.com/image.jpg"}}
17 ]
18 }
19 ]
20)
21print(response.choices[0].message.content)
22
23# Oder mit Base64
24import base64
25with open("bild.jpg", "rb") as f:
26 image_data = base64.b64encode(f.read()).decode()
27
28response = client.chat.completions.create(
29 model="mistral-small",
30 messages=[
31 {
32 "role": "user",
33 "content": [
34 {"type": "text", "text": "Beschreibe dieses Bild"},
35 {"type": "image_url", "image_url": {"url": f"data:image/jpeg;base64,{image_data}"}}
36 ]
37 }
38 ]
39)
Strukturierte JSON-Ausgabe
Einsteiger
5 Min.

Erzwingen Sie JSON-Ausgaben für einfache Weiterverarbeitung.

json.pypython
1from openai import OpenAI
2
3client = OpenAI(
4 api_key="sk_vantero_...",
5 base_url="https://api.vantero.chat/v1"
6)
7
8# JSON Mode aktivieren
9response = client.chat.completions.create(
10 model="mistral-small",
11 messages=[
12 {
13 "role": "user",
14 "content": "Liste 3 deutsche Städte mit Einwohnerzahl als JSON"
15 }
16 ],
17 response_format={"type": "json_object"} # Erzwingt JSON-Ausgabe
18)
19
20# Antwort ist garantiert valides JSON
21import json
22data = json.loads(response.choices[0].message.content)
23print(data)
24
25# Beispiel-Ausgabe:
26# {"cities": [
27# {"name": "Berlin", "population": 3645000},
28# {"name": "Hamburg", "population": 1841000},
29# {"name": "München", "population": 1472000}
30# ]}