Spaces:
Runtime error
Runtime error
Update ai_generate.py
Browse files- ai_generate.py +15 -6
ai_generate.py
CHANGED
@@ -54,11 +54,20 @@ def generate(text, model, api):
|
|
54 |
elif model == "Gemma":
|
55 |
return generate_groq(text, "gemma2-9b-it")
|
56 |
elif model == "OpenAI GPT 3.5":
|
57 |
-
|
58 |
-
|
|
|
|
|
|
|
59 |
elif model == "OpenAI GPT 4":
|
60 |
-
|
61 |
-
|
|
|
|
|
|
|
62 |
elif model == "OpenAI GPT 4o":
|
63 |
-
|
64 |
-
|
|
|
|
|
|
|
|
54 |
elif model == "Gemma":
|
55 |
return generate_groq(text, "gemma2-9b-it")
|
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"
|