Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -200,10 +200,10 @@ def create_audio_recorder():
|
|
| 200 |
|
| 201 |
class AdvancedRAG:
|
| 202 |
def __init__(self):
|
| 203 |
-
self.vector_store_id: Optional[str] = None
|
| 204 |
-
self.file_ids: List[str] = []
|
| 205 |
self.thread_id: Optional[str] = None
|
| 206 |
self.assistant_id: Optional[str] = os.getenv("ASSISTANT_ID")
|
|
|
|
|
|
|
| 207 |
|
| 208 |
def create_thread(self) -> str:
|
| 209 |
thread = openai.beta.threads.create()
|
|
@@ -221,11 +221,10 @@ class AdvancedRAG:
|
|
| 221 |
file=file_obj,
|
| 222 |
purpose="assistants"
|
| 223 |
)
|
| 224 |
-
self.file_ids.append(file_obj.id)
|
| 225 |
|
| 226 |
-
# Create a new thread
|
| 227 |
-
|
| 228 |
-
|
| 229 |
|
| 230 |
# Add the file to the thread
|
| 231 |
openai.beta.threads.messages.create(
|
|
@@ -241,6 +240,9 @@ class AdvancedRAG:
|
|
| 241 |
|
| 242 |
def ask_question(self, question: str) -> str:
|
| 243 |
try:
|
|
|
|
|
|
|
|
|
|
| 244 |
# Add the question to the thread
|
| 245 |
openai.beta.threads.messages.create(
|
| 246 |
thread_id=self.thread_id,
|
|
|
|
| 200 |
|
| 201 |
class AdvancedRAG:
|
| 202 |
def __init__(self):
|
|
|
|
|
|
|
| 203 |
self.thread_id: Optional[str] = None
|
| 204 |
self.assistant_id: Optional[str] = os.getenv("ASSISTANT_ID")
|
| 205 |
+
if not self.assistant_id:
|
| 206 |
+
raise ValueError("ASSISTANT_ID environment variable is not set")
|
| 207 |
|
| 208 |
def create_thread(self) -> str:
|
| 209 |
thread = openai.beta.threads.create()
|
|
|
|
| 221 |
file=file_obj,
|
| 222 |
purpose="assistants"
|
| 223 |
)
|
|
|
|
| 224 |
|
| 225 |
+
# Create a new thread if one doesn't exist
|
| 226 |
+
if not self.thread_id:
|
| 227 |
+
self.create_thread()
|
| 228 |
|
| 229 |
# Add the file to the thread
|
| 230 |
openai.beta.threads.messages.create(
|
|
|
|
| 240 |
|
| 241 |
def ask_question(self, question: str) -> str:
|
| 242 |
try:
|
| 243 |
+
if not self.thread_id:
|
| 244 |
+
self.create_thread()
|
| 245 |
+
|
| 246 |
# Add the question to the thread
|
| 247 |
openai.beta.threads.messages.create(
|
| 248 |
thread_id=self.thread_id,
|