kavansaun commited on
Commit
e2e6179
·
verified ·
1 Parent(s): 7a34524

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -9
app.py CHANGED
@@ -8,7 +8,7 @@ from github import Github
8
  import uuid
9
  import time
10
 
11
- # Clients
12
  openai_key = os.getenv("OPENAI_KEY")
13
  if not openai_key:
14
  raise ValueError("OPENAI_KEY not set")
@@ -20,8 +20,8 @@ if not github_key:
20
  client = OpenAI(api_key=openai_key)
21
  g = Github(github_key)
22
 
23
- # Global repo name, repo name must be under quotations
24
- REPO_NAME = ""
25
 
26
  # Session data for each user
27
  user_dictionary = {}
@@ -80,7 +80,7 @@ with gr.Blocks(theme=gr.themes.Monochrome(), css="""footer {display:none !import
80
  "content": user_input
81
  })
82
 
83
- # Format chat
84
  formatted_chat = [
85
  msg for msg in user_dictionary[user_id]
86
  if msg["role"] != "system"
@@ -88,15 +88,15 @@ with gr.Blocks(theme=gr.themes.Monochrome(), css="""footer {display:none !import
88
 
89
  return formatted_chat, ""
90
 
91
- # Generate Chat Bots response
92
  def predict_prompt(user_id):
93
  if not user_id or user_id not in user_dictionary:
94
  return []
95
 
96
- # Optional delay for a human realistic response time
97
  time.sleep(1)
98
 
99
- # Try tp get the response from OpenAI
100
  try:
101
  response = client.chat.completions.create(
102
  model="gpt-4o-mini", # Model Type
@@ -106,13 +106,13 @@ with gr.Blocks(theme=gr.themes.Monochrome(), css="""footer {display:none !import
106
  except Exception as e:
107
  reply = f"Error: {str(e)}"
108
 
109
- # Add assistant reply
110
  user_dictionary[user_id].append({
111
  "role": "assistant",
112
  "content": reply
113
  })
114
 
115
- # Format chat
116
  formatted_chat = [
117
  msg for msg in user_dictionary[user_id]
118
  if msg["role"] != "system"
 
8
  import uuid
9
  import time
10
 
11
+ # Environment variables
12
  openai_key = os.getenv("OPENAI_KEY")
13
  if not openai_key:
14
  raise ValueError("OPENAI_KEY not set")
 
20
  client = OpenAI(api_key=openai_key)
21
  g = Github(github_key)
22
 
23
+ # Repo name, name must be under quotations
24
+ REPO_NAME = "NAME"
25
 
26
  # Session data for each user
27
  user_dictionary = {}
 
80
  "content": user_input
81
  })
82
 
83
+ # Format conversation
84
  formatted_chat = [
85
  msg for msg in user_dictionary[user_id]
86
  if msg["role"] != "system"
 
88
 
89
  return formatted_chat, ""
90
 
91
+ # Generate Chat Bot response
92
  def predict_prompt(user_id):
93
  if not user_id or user_id not in user_dictionary:
94
  return []
95
 
96
+ # Optional delay for a realistic human response time
97
  time.sleep(1)
98
 
99
+ # Try to get the response from OpenAI
100
  try:
101
  response = client.chat.completions.create(
102
  model="gpt-4o-mini", # Model Type
 
106
  except Exception as e:
107
  reply = f"Error: {str(e)}"
108
 
109
+ # Add chatbot reply to session data
110
  user_dictionary[user_id].append({
111
  "role": "assistant",
112
  "content": reply
113
  })
114
 
115
+ # Format conversation
116
  formatted_chat = [
117
  msg for msg in user_dictionary[user_id]
118
  if msg["role"] != "system"