Hallo,
ich programmiere gerade einen Sprachassistenten und wollte ihn nun mit GPT-4 verbinden, ich habe auf Shop - ChatGPT 50000 Tokens gekauft, doch wenn ich das Programm starte, steht, dass ich trotzdem keinen Zugriff auf GPT-4 habe. Muss ich die Tokens irgendwo anders kaufen?
Mein Code:
import openai
import pyttsx3
import re
import pyjokes
import speech_recognition as sr
from pyowm import OWM
import spotipy
from spotipy.oauth2 import SpotifyOAuth
import time
import random
import datetime
import pytz
from geopy.geocoders import Nominatim
from timezonefinder import TimezoneFinder
openai.api_key = 'sk-...'
model_id = "gpt-4"
engine = pyttsx3.init()
def recognize_speech():
recognizer = sr.Recognizer()
while True:
with sr.Microphone() as source:
print("Sage etwas...")
audio = recognizer.listen(source, timeout=15)
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=prompt
)
api_usage = response['usage']
print('Total Token consumed: {0}'.format(api_usage['total_tokens']))
prompt.append({'role': response.choices[0].message.role, 'content': response.choices[0].message.content})
return prompt
def speak(text):
engine.say(text)
engine.runAndWait()
def ausführen():
while True:
q = recognize_speech()
print("Erkannter Text:", q)
if q == "not_understood":
speak("Entschuldigung! Das habe ich nicht verstanden.")
break
elif not q:
break
elif "hallo" in q:
speak('Hallo! Womit kann ich dir behilflich sein?')
break
else:
prompt = [{'role': 'user', 'content': q}]
prompt = openai_request(prompt)
response = prompt[-1]['content']
speak(response)
if __name__ == '__main__':
ausführen()
Fehlercode:
C:\Users\User\PycharmProjects\voiceAssistant\venv\interpreter\Scripts\python.exe C:\Users\User\PycharmProjects\voiceAssistant\main.py
Sage etwas...
Text: wann war der erste Weltkrieg
Erkannter Text: wann war der erste Weltkrieg
Traceback (most recent call last):
File "C:\Users\User\PycharmProjects\voiceAssistant\main.py", line 83, in <module>
ausführen()
File "C:\Users\User\PycharmProjects\voiceAssistant\main.py", line 77, in ausführen
prompt = openai_request(prompt)
^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\User\PycharmProjects\voiceAssistant\main.py", line 43, in openai_request
response = openai.ChatCompletion.create(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\User\PycharmProjects\voiceAssistant\venv\interpreter\Lib\site-packages\openai\api_resources\chat_completion.py", line 25, in create
return super().create(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\User\PycharmProjects\voiceAssistant\venv\interpreter\Lib\site-packages\openai\api_resources\abstract\engine_api_resource.py", line 153, in create
response, _, api_key = requestor.request(
^^^^^^^^^^^^^^^^^^
File "C:\Users\User\PycharmProjects\voiceAssistant\venv\interpreter\Lib\site-packages\openai\api_requestor.py", line 298, in request
resp, got_stream = self._interpret_response(result, stream)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\User\PycharmProjects\voiceAssistant\venv\interpreter\Lib\site-packages\openai\api_requestor.py", line 700, in _interpret_response
self._interpret_response_line(
File "C:\Users\User\PycharmProjects\voiceAssistant\venv\interpreter\Lib\site-packages\openai\api_requestor.py", line 765, in _interpret_response_line
raise self.handle_error_response(
openai.error.InvalidRequestError: The model `gpt-4` does not exist or you do not have access to it. Learn more: https://help.openai.com/en/articles/7102672-how-can-i-access-gpt-4.
Process finished with exit code 1
Freundliche Grüsse
Okay ich werde es versuchen, vielen Dank!