Spaces:
Runtime error
Runtime error
Update ai_generate.py
Browse files- ai_generate.py +4 -4
ai_generate.py
CHANGED
@@ -33,7 +33,7 @@ def generate_groq(text, model):
|
|
33 |
response += chunk.choices[0].delta.content or ""
|
34 |
return response
|
35 |
|
36 |
-
def generate_openai(text, model):
|
37 |
message=[{"role": "user", "content": text}]
|
38 |
response = openai_client.chat.completions.create(
|
39 |
model=model,
|
@@ -56,18 +56,18 @@ def generate(text, model, api):
|
|
56 |
elif model == "OpenAI GPT 3.5":
|
57 |
try:
|
58 |
openai_client = OpenAI(api_key=api)
|
59 |
-
return generate_openai(text, "gpt-3.5-turbo")
|
60 |
except:
|
61 |
return "Please add a valid API key"
|
62 |
elif model == "OpenAI GPT 4":
|
63 |
try:
|
64 |
openai_client = OpenAI(api_key=api)
|
65 |
-
return generate_openai(text, "gpt-4-turbo")
|
66 |
except:
|
67 |
return "Please add a valid API key"
|
68 |
elif model == "OpenAI GPT 4o":
|
69 |
try:
|
70 |
openai_client = OpenAI(api_key=api)
|
71 |
-
return generate_openai(text, "gpt-4o")
|
72 |
except:
|
73 |
return "Please add a valid API key"
|
|
|
33 |
response += chunk.choices[0].delta.content or ""
|
34 |
return response
|
35 |
|
36 |
+
def generate_openai(text, model, openai_client):
|
37 |
message=[{"role": "user", "content": text}]
|
38 |
response = openai_client.chat.completions.create(
|
39 |
model=model,
|
|
|
56 |
elif model == "OpenAI GPT 3.5":
|
57 |
try:
|
58 |
openai_client = OpenAI(api_key=api)
|
59 |
+
return generate_openai(text, "gpt-3.5-turbo", openai_client)
|
60 |
except:
|
61 |
return "Please add a valid API key"
|
62 |
elif model == "OpenAI GPT 4":
|
63 |
try:
|
64 |
openai_client = OpenAI(api_key=api)
|
65 |
+
return generate_openai(text, "gpt-4-turbo", openai_client)
|
66 |
except:
|
67 |
return "Please add a valid API key"
|
68 |
elif model == "OpenAI GPT 4o":
|
69 |
try:
|
70 |
openai_client = OpenAI(api_key=api)
|
71 |
+
return generate_openai(text, "gpt-4o", openai_client)
|
72 |
except:
|
73 |
return "Please add a valid API key"
|