Anustup commited on
Commit
9683b3a
·
verified ·
1 Parent(s): 12a0383

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -6
app.py CHANGED
@@ -9,14 +9,14 @@ client = OpenAI(api_key=OPENAI_API_KEY)
9
  OPEN_AI_MODEL = "gpt-4-1106-preview"
10
 
11
  # thread = gr.State(client.beta.threads.create())
 
12
 
13
  def initialize_thread():
14
- session = gr.interface.get_session()
15
- if "thread_id" not in session:
16
  thread = client.beta.threads.create()
17
- session["thread_id"] = thread.id
18
- session["thread"] = thread
19
- return session["thread_id"], session["thread"]
20
 
21
  def wait_on_run(run, thread):
22
  while run.status == "queued" or run.status == "in_progress":
@@ -110,8 +110,8 @@ def response_evaluation_for_case_tx(thread_id, query, question_text, input, outp
110
  def run_chat_in_all_cases(message, history, question_text,input, output, examples, code_written):
111
  # thread = client.beta.threads.create()
112
  # thread_id = thread.id
 
113
  thread_id = initialize_thread()
114
- session = gr.interface.get_session()
115
  print(thread_id)
116
  if not message and not code_written:
117
  ai_message = opening_statement(thread_id[0], question_text, input, output, examples, thread_id[1])
 
9
  OPEN_AI_MODEL = "gpt-4-1106-preview"
10
 
11
  # thread = gr.State(client.beta.threads.create())
12
+ thread_id = None
13
 
14
  def initialize_thread():
15
+ global thread_id
16
+ if thread_id is None:
17
  thread = client.beta.threads.create()
18
+ thread_id = thread.id
19
+ return thread_id, thread
 
20
 
21
  def wait_on_run(run, thread):
22
  while run.status == "queued" or run.status == "in_progress":
 
110
  def run_chat_in_all_cases(message, history, question_text,input, output, examples, code_written):
111
  # thread = client.beta.threads.create()
112
  # thread_id = thread.id
113
+ global thread_id
114
  thread_id = initialize_thread()
 
115
  print(thread_id)
116
  if not message and not code_written:
117
  ai_message = opening_statement(thread_id[0], question_text, input, output, examples, thread_id[1])