shukdevdatta123 commited on
Commit
a577779
Β·
verified Β·
1 Parent(s): 9be1d2a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -12
app.py CHANGED
@@ -1,5 +1,5 @@
1
  import gradio as gr
2
- from openai import OpenAI
3
  import json
4
  import os
5
  import time
@@ -22,13 +22,11 @@ class ChatbotManager:
22
  return "❌ Please enter a valid API key"
23
 
24
  self.current_api_key = api_key.strip()
25
-
26
- # Create OpenAI client with the new syntax
27
- self.client = openai.OpenAI(api_key=self.current_api_key)
28
 
29
  # Test the API key
30
  try:
31
- self.client.models.list()
32
  return "βœ… API key validated successfully!"
33
  except Exception as e:
34
  return f"❌ Invalid API key: {str(e)}"
@@ -71,8 +69,8 @@ class ChatbotManager:
71
  # Add current user input
72
  messages.append({"role": "user", "content": user_input})
73
 
74
- # Generate response using new OpenAI client syntax
75
- response = self.client.chat.completions.create(
76
  model=self.current_model,
77
  messages=messages,
78
  max_tokens=self.max_tokens,
@@ -123,15 +121,14 @@ class ChatbotManager:
123
  # Initialize chatbot manager
124
  chatbot = ChatbotManager()
125
 
126
- # Define available models
127
  AVAILABLE_MODELS = [
128
  "gpt-3.5-turbo",
129
  "gpt-3.5-turbo-16k",
130
  "gpt-4",
131
  "gpt-4-32k",
132
- "gpt-4-turbo-preview",
133
- "gpt-4o",
134
- "gpt-4o-mini"
135
  ]
136
 
137
  def create_interface():
@@ -299,6 +296,15 @@ def create_interface():
299
  - **Model Errors**: Some models may not be available in your region
300
  - **Long Response Times**: Reduce max tokens or switch to faster models
301
  - **Context Limits**: Clear chat history if responses become inconsistent
 
 
 
 
 
 
 
 
 
302
  """)
303
 
304
  # Event handlers
@@ -447,7 +453,9 @@ def print_setup_instructions():
447
  =====================================
448
 
449
  πŸ“¦ Required Dependencies:
450
- pip install gradio openai requests
 
 
451
 
452
  πŸ”‘ API Key Setup:
453
  1. Visit https://platform.openai.com/
 
1
  import gradio as gr
2
+ import openai
3
  import json
4
  import os
5
  import time
 
22
  return "❌ Please enter a valid API key"
23
 
24
  self.current_api_key = api_key.strip()
25
+ openai.api_key = self.current_api_key
 
 
26
 
27
  # Test the API key
28
  try:
29
+ openai.Model.list()
30
  return "βœ… API key validated successfully!"
31
  except Exception as e:
32
  return f"❌ Invalid API key: {str(e)}"
 
69
  # Add current user input
70
  messages.append({"role": "user", "content": user_input})
71
 
72
+ # Generate response using OpenAI 0.28 syntax
73
+ response = openai.ChatCompletion.create(
74
  model=self.current_model,
75
  messages=messages,
76
  max_tokens=self.max_tokens,
 
121
  # Initialize chatbot manager
122
  chatbot = ChatbotManager()
123
 
124
+ # Define available models for OpenAI 0.28
125
  AVAILABLE_MODELS = [
126
  "gpt-3.5-turbo",
127
  "gpt-3.5-turbo-16k",
128
  "gpt-4",
129
  "gpt-4-32k",
130
+ "gpt-4-0613",
131
+ "gpt-4-32k-0613"
 
132
  ]
133
 
134
  def create_interface():
 
296
  - **Model Errors**: Some models may not be available in your region
297
  - **Long Response Times**: Reduce max tokens or switch to faster models
298
  - **Context Limits**: Clear chat history if responses become inconsistent
299
+
300
+ ## πŸ“¦ Installation Requirements
301
+
302
+ This version is compatible with OpenAI 0.28.0. Install dependencies:
303
+ ```bash
304
+ pip install openai==0.28.0
305
+ pip install gradio
306
+ pip install requests
307
+ ```
308
  """)
309
 
310
  # Event handlers
 
453
  =====================================
454
 
455
  πŸ“¦ Required Dependencies:
456
+ pip install openai==0.28.0
457
+ pip install gradio
458
+ pip install requests
459
 
460
  πŸ”‘ API Key Setup:
461
  1. Visit https://platform.openai.com/