Hier werden die Unterschiede zwischen zwei Versionen angezeigt.
Beide Seiten der vorigen Revision Vorhergehende Überarbeitung Nächste Überarbeitung | Vorhergehende Überarbeitung | ||
openai [2025/07/21 14:17] jango [Chat Completion mit Verlauf] |
openai [2025/08/02 19:49] (aktuell) jango |
||
---|---|---|---|
Zeile 2: | Zeile 2: | ||
[[https:// | [[https:// | ||
+ | |||
+ | ====Local==== | ||
+ | <code python> | ||
+ | import requests | ||
+ | import json | ||
+ | import pyttsx3 | ||
+ | |||
+ | # gemma-3-1b-it, | ||
+ | MODEL_NAME = " | ||
+ | API_URL = " | ||
+ | |||
+ | def frage_gpt(prompt_text): | ||
+ | try: | ||
+ | response = requests.post( | ||
+ | API_URL + "/ | ||
+ | headers={" | ||
+ | data=json.dumps({ | ||
+ | " | ||
+ | " | ||
+ | {" | ||
+ | {" | ||
+ | ], | ||
+ | " | ||
+ | }) | ||
+ | ) | ||
+ | if response.status_code == 200: | ||
+ | return response.json() # response.text | ||
+ | else: | ||
+ | return f" | ||
+ | except Exception as e: | ||
+ | return f" | ||
+ | | ||
+ | def frage_gpt_stream(prompt_text): | ||
+ | try: | ||
+ | response = requests.post( | ||
+ | API_URL + "/ | ||
+ | headers={" | ||
+ | data=json.dumps({ | ||
+ | " | ||
+ | " | ||
+ | {" | ||
+ | {" | ||
+ | ], | ||
+ | " | ||
+ | }), | ||
+ | stream=True | ||
+ | ) | ||
+ | |||
+ | if response.status_code != 200: | ||
+ | print(f" | ||
+ | return | ||
+ | | ||
+ | # Antwort-Stream verarbeiten | ||
+ | for line in response.iter_lines(): | ||
+ | if line: | ||
+ | decoded_line = line.decode(" | ||
+ | if decoded_line.startswith(" | ||
+ | payload = json.loads(decoded_line[6: | ||
+ | delta = payload.get(" | ||
+ | if delta: | ||
+ | print(delta, | ||
+ | |||
+ | except Exception as e: | ||
+ | print("" | ||
+ | |||
+ | |||
+ | engine = pyttsx3.init() | ||
+ | engine.setProperty(" | ||
+ | engine.setProperty(" | ||
+ | voices = engine.getProperty(" | ||
+ | for voice in voices: | ||
+ | if " | ||
+ | engine.setProperty(" | ||
+ | break | ||
+ | |||
+ | |||
+ | while True: | ||
+ | frage = input(" | ||
+ | frage_gpt_stream(frage) | ||
+ | # | ||
+ | # | ||
+ | # | ||
+ | </ | ||
====Chat Completion==== | ====Chat Completion==== |