How can I make OpenAI address me informally?

Hello,

How can I use this code to make OpenAI address me informally and not formally when answering all questions?

 import pyttsx3 import re import pyjokes import speech_recognition as sr import geocoder import datetime import pytz from geopy.geocoders import Nominatim from timezonefinder import TimezoneFinder import openai openai.api_key = 'sk-...' model_id = "gpt-4" engine = pyttsx3.init() def recognize_speech(recognizer, source): print("Sage etwas...") audio = recognizer.listen(source, timeout=10) try: text = recognizer.recognize_google(audio, language="de-DE") print("Text: " + text) return text except sr.UnknownValueError: return "not_understood" except sr.RequestError as e: print(f"Fehler bei der Anfrage an die Google Web Speech API: {e}") return "" def openai_request(prompt): response = openai.ChatCompletion.create( model=model_id, messages=[{"role": "user", "content": prompt}], max_tokens=150 ) api_usage = response['usage'] print('Total Token consumed: {0}'.format(api_usage['total_tokens'])) response_text = response.choices[0].message['content'] prompt += response_text return prompt def speak(text=None): if text: engine.say(text) engine.runAndWait() def hey_luna_in_q(q): return "luna" in q.lower() def wait_for_wake_word(recognizer, source): while True: print("Warte auf Wake-Word...") audio = recognizer.listen(source) try: text = recognizer.recognize_google(audio, language="de-DE") if hey_luna_in_q(text): print("Wake-Word erkannt!") return except sr.UnknownValueError: pass except sr.RequestError as e: print(f"Fehler bei der Anfrage an die Google Web Speech API: {e}") def get_local_time(location_name): try: if location_name.lower() == "current location": current_location = geocoder.ip('me') latitude, longitude = current_location.latlng else: geolocator = Nominatim(user_agent="voiceAssistant") location = geolocator.geocode(location_name) if not location: return "Ort nicht gefunden" latitude = location.latitude longitude = location.longitude tf = TimezoneFinder() timezone = tf.timezone_at(lng=longitude, lat=latitude) if timezone: local_time = datetime.datetime.now(pytz.timezone(timezone)) return local_time.strftime("%H:%M") else: return "Unbekannte Zeitzone" except Exception as e: print("Fehler beim Abrufen der lokalen Zeit:", e) return "Fehler" def execute(): recognizer = sr.Recognizer() witz_erzählt = False # Variable, um den Zustand des Witzes zu verfolgen with sr.Microphone() as source: while True: wait_for_wake_word(recognizer, source) print("Warte auf Wake-Word...") q = recognize_speech(recognizer, source) print("Erkannter Text:", q) if q == "not_understood": speak("Entschuldigung! Das habe ich nicht verstanden.") continue if "hallo" in q.lower(): speak("Hallo! Womit kann ich dir behilflich sein?") continue if "wie geht es dir" in q.lower(): speak("Mir geht es gut, danke! Wie geht es dir?") continue if "spät ist es in" in q.lower() or "wieviel uhr ist es in" in q.lower() or "wieviel uhr in" in q.lower() or "zeit in" in q.lower() or "uhrzeit in" in q.lower(): location_name = q.split("in")[-1].strip() print("Extrahierter Ortname:", location_name) local_time = get_local_time(location_name) print("Lokale Zeit für", location_name, ":", local_time) if local_time: speak(f"In {location_name} ist es {local_time}.") else: speak(f"Entschuldigung, ich konnte die Zeit für {location_name} nicht finden.") continue if "spät ist es" in q.lower() or "wieviel uhr" in q.lower() or "zeit in" in q.lower() or "uhrzeit in" in q.lower(): current_location = geocoder.ip('me') latitude, longitude = current_location.latlng local_time = get_local_time("current location") speak(f"Es ist {local_time}.") continue if "erzähle mir einen witz" in q.lower() or "erzähl mir einen witz" in q.lower() or "ich möchte einen witz hören" in q.lower(): joke = pyjokes.get_joke(language='de') speak(joke) witz_erzählt = True continue if "ich bin traurig" in q.lower() or "mir geht es nicht gut" in q.lower() or "es geht mir nicht gut" in q.lower() or "mir geht es schlecht" in q.lower(): if not witz_erzählt: speak("Das tut mir leid zu hören. Ich bin hier für dich, wenn du reden möchtest oder jemanden zum Zuhören brauchst. Soll ich dir zum Aufmuntern einen Witz erzählen?") response = recognize_speech(recognizer, source) if "ja" in response.lower(): joke = pyjokes.get_joke(language='de') speak(joke) continue elif "nein" in response.lower(): speak("Ok, womit kann ich dir sonst behilflich sein?") continue else: speak("Entschuldigung. Ich habe dich nicht verstanden.") continue prompt = q response = openai_request(prompt) if response.lower().startswith(q.lower()): response = response[len(q):].strip() speak(response) if __name__ == '__main__': execute()

Kind regards

(1 votes)
Loading...

Similar Posts

Subscribe
Notify of
4 Answers
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
SolusBellator
1 year ago

Maybe counts almost as a life hack, but…

English.

There is always the address “You”, then you can choose how to interpret it… 😅

TUrabbIT
1 year ago

You can install and always send the instruction before the prompt