endert1099 commited on
Commit
9c14c56
ยท
1 Parent(s): 8242563

Upload blubeAPI.py

Browse files
Files changed (1) hide show
  1. blubeAPI.py +10 -8
blubeAPI.py CHANGED
@@ -10,20 +10,26 @@ import openai
10
  from openai import OpenAI
11
  import os
12
  import time
 
 
13
 
14
- client = OpenAI(
15
- api_key=os.environ["OPEN_API_KEY"]
16
- )
17
 
18
  def findOccurrences(s, ch):
19
  return [i for i, letter in enumerate(s) if letter == ch]
20
  def format(data: str):
 
21
  data = data.replace("['", "")
22
  data = data.replace("']", "")
23
  data = data.replace("[\"", "")
24
  data = data.replace("\"]", "")
25
  data = data.replace("\\\'", "\'")
26
  data = data.replace("\\n", "")
 
 
 
27
 
28
  sourceErrorInstances = findOccurrences(data, "ใ€")
29
  lSourceErrorInstances = findOccurrences(data, "ใ€‘")
@@ -73,7 +79,7 @@ def runbot():
73
  thread = client.beta.threads.create()
74
  print("(3/3) Finished creating thread, launching interface...\n")
75
 
76
- iface.launch(share=False)
77
  def getAssistant():
78
  return my_assistant
79
  def getPersona():
@@ -115,7 +121,6 @@ def chatbot(input_text):
115
  tt = 0
116
  errorCode = 0
117
  while run.status != "completed":
118
- ttime = time.time() - stime
119
  run = client.beta.threads.runs.retrieve(
120
  thread_id=thread.id, run_id=run.id
121
  )
@@ -136,9 +141,6 @@ def chatbot(input_text):
136
  if t > 15:
137
  print(f"Time taken is over 15 ticks, average time is 11, check issues.\n\nINFO: Status is {s} and the total ticks is {tt}")
138
  t = 0
139
- if ttime > 20:
140
- print("\n\n\nTAKEN OVER 20 SECONDS, RESTARTING PROCESS\n\n\n")
141
- chatbot(input_text)
142
  if errorCode == 1:
143
  raise RuntimeError("\n\nThe process finished with an error: Process failed unexpectedly. Check the command prompt for more details. This error is most likely a overuse error, so the program will sleep for 20 seconds to avoid more errors\n\n")
144
  time.sleep(20)
 
10
  from openai import OpenAI
11
  import os
12
  import time
13
+ import random
14
+ import math
15
 
16
+ os.environ["OPENAI_API_KEY"] = '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'
17
+
18
+ client = OpenAI()
19
 
20
  def findOccurrences(s, ch):
21
  return [i for i, letter in enumerate(s) if letter == ch]
22
  def format(data: str):
23
+
24
  data = data.replace("['", "")
25
  data = data.replace("']", "")
26
  data = data.replace("[\"", "")
27
  data = data.replace("\"]", "")
28
  data = data.replace("\\\'", "\'")
29
  data = data.replace("\\n", "")
30
+ data = data.replace("**", "")
31
+ data = data.replace(".", ". ")
32
+ data = data.replace(" ", " ")
33
 
34
  sourceErrorInstances = findOccurrences(data, "ใ€")
35
  lSourceErrorInstances = findOccurrences(data, "ใ€‘")
 
79
  thread = client.beta.threads.create()
80
  print("(3/3) Finished creating thread, launching interface...\n")
81
 
82
+ iface.launch(share=True)
83
  def getAssistant():
84
  return my_assistant
85
  def getPersona():
 
121
  tt = 0
122
  errorCode = 0
123
  while run.status != "completed":
 
124
  run = client.beta.threads.runs.retrieve(
125
  thread_id=thread.id, run_id=run.id
126
  )
 
141
  if t > 15:
142
  print(f"Time taken is over 15 ticks, average time is 11, check issues.\n\nINFO: Status is {s} and the total ticks is {tt}")
143
  t = 0
 
 
 
144
  if errorCode == 1:
145
  raise RuntimeError("\n\nThe process finished with an error: Process failed unexpectedly. Check the command prompt for more details. This error is most likely a overuse error, so the program will sleep for 20 seconds to avoid more errors\n\n")
146
  time.sleep(20)