minko186 commited on
Commit
7b33051
·
verified ·
1 Parent(s): c80b6f5

Update ai_generate.py

Browse files
Files changed (1) hide show
  1. 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
- openai_client = OpenAI(api_key=api)
58
- return generate_openai(text, "gpt-3.5-turbo", openai_client)
 
 
 
59
  elif model == "OpenAI GPT 4":
60
- openai_client = OpenAI(api_key=api)
61
- return generate_openai(text, "gpt-4-turbo", openai_client)
 
 
 
62
  elif model == "OpenAI GPT 4o":
63
- openai_client = OpenAI(api_key=api)
64
- return generate_openai(text, "gpt-4o", openai_client)
 
 
 
 
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"