Files
data-processing/openAI_validate_data/2025-07_gpt03_web-search-preview/request.py
2025-07-21 13:21:43 +02:00

102 lines
3.0 KiB
Python

import os
import sys
from typing import Optional
from pydantic import BaseModel
from openai import OpenAI
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..', '_data')))
from api_keys import OPENAI_API_KEY
client = OpenAI(api_key=OPENAI_API_KEY)
preliminary_angebot_schema = {
"name": "create_preliminary_angebot",
"description": "Erstellt ein strukturiertes PreliminaryAngebot",
"parameters": {
"type": "object",
"properties": {
"name": {"type": "string"},
"beschreibung": {"type": "string"},
"strasse": {"type": "string"},
"hausNr": {"type": "string"},
"plz": {"type": "string"},
"ort": {"type": "string"},
"adresseZusatz": {"type": "string"},
"web": {"type": "string"},
"mail": {"type": "string"},
"telefon": {"type": "string"},
"fax": {"type": "string"},
"kategorie": {"type": "string"},
"unterkategorie": {"type": "string"},
"themen": {"type": "string"},
"traeger": {"type": "string"},
"zielgruppe": {"type": "string"},
"angebote": {"type": "string"},
"oeffnungsZeiten": {"type": "string"},
"kostenuebernahme": {"type": "string"},
"sprache": {"type": "string"},
"barrierefreiheit": {"type": "string"},
"konstellation": {"type": "string"},
"restInput": {"type": "string"},
"completeInput": {"type": "string"},
},
"required": ["name", "beschreibung", "plz", "ort", "adresseZusatz", "web", "restInput", "completeInput"]
}
}
class PreliminaryAngebot(BaseModel):
name: str = ""
beschreibung: str = ""
strasse: Optional[str] = ""
hausNr: Optional[str] = ""
plz: str = ""
ort: str = ""
adresseZusatz: str = ""
web: str = ""
mail: Optional[str] = ""
telefon: Optional[str] = ""
fax: Optional[str] = ""
kategorie: Optional[str] = ""
unterkategorie: Optional[str] = ""
themen: Optional[str] = ""
traeger: Optional[str] = ""
zielgruppe: Optional[str] = ""
angebote: Optional[str] = ""
oeffnungsZeiten: Optional[str] = ""
kostenuebernahme: Optional[str] = ""
sprache: Optional[str] = ""
barrierefreiheit: Optional[str] = ""
konstellation: Optional[str] = ""
restInput: str = ""
completeInput: str = ""
inputText = '''
Hier sind Daten einer psychologischen Anlaufstation.
Kannst du fehlende Daten ergänzen und fehlerhafte ggf. ersetzen? Wichtig wäre die Angabe der korrekten Webseite.
Kinder- u. Jugendlichenpsychotherapeutin Stephanie Eckmann, Lünen
Birkenweg 9
44532 Lünen
'''
response = client.responses.parse(
model="gpt-4o-mini",
tools=[{"type": "web_search_preview"}],
input=inputText,
text_format=PreliminaryAngebot,
)
print('### Input ###\n', inputText.replace('\r', '').replace('\n', ' '))
print('\n\n### Response ###\n', response.output_text)
print("\n\nOk ciao")