Spaces:
Runtime error
Runtime error
Commit
·
9531d87
1
Parent(s):
80f3e35
chore: explain the hooks
Browse files- wanderlust.py +6 -3
wanderlust.py
CHANGED
|
@@ -186,6 +186,7 @@ def ChatInterface():
|
|
| 186 |
prompt = solara.use_reactive("")
|
| 187 |
run_id: solara.Reactive[str] = solara.use_reactive(None)
|
| 188 |
|
|
|
|
| 189 |
thread: Thread = solara.use_memo(openai.beta.threads.create, dependencies=[])
|
| 190 |
|
| 191 |
def add_message(value: str):
|
|
@@ -196,6 +197,9 @@ def ChatInterface():
|
|
| 196 |
thread_id=thread.id, content=value, role="user"
|
| 197 |
)
|
| 198 |
messages.set([*messages.value, new_message])
|
|
|
|
|
|
|
|
|
|
| 199 |
run_id.value = openai.beta.threads.runs.create(
|
| 200 |
thread_id=thread.id,
|
| 201 |
assistant_id="asst_RqVKAzaybZ8un7chIwPCIQdH",
|
|
@@ -236,12 +240,11 @@ def ChatInterface():
|
|
| 236 |
completed = True
|
| 237 |
time.sleep(0.1)
|
| 238 |
|
|
|
|
| 239 |
result = solara.use_thread(poll, dependencies=[run_id.value])
|
| 240 |
|
| 241 |
# Create DOM for chat interface
|
| 242 |
-
with solara.Column(
|
| 243 |
-
classes=["chat-interface"],
|
| 244 |
-
):
|
| 245 |
if len(messages.value) > 0:
|
| 246 |
with ChatBox():
|
| 247 |
for message in messages.value:
|
|
|
|
| 186 |
prompt = solara.use_reactive("")
|
| 187 |
run_id: solara.Reactive[str] = solara.use_reactive(None)
|
| 188 |
|
| 189 |
+
# Create a thread to hold the conversation only once when this component is created
|
| 190 |
thread: Thread = solara.use_memo(openai.beta.threads.create, dependencies=[])
|
| 191 |
|
| 192 |
def add_message(value: str):
|
|
|
|
| 197 |
thread_id=thread.id, content=value, role="user"
|
| 198 |
)
|
| 199 |
messages.set([*messages.value, new_message])
|
| 200 |
+
# this creates a new run for the thread
|
| 201 |
+
# also also triggers a rerender (since run_id.value changes)
|
| 202 |
+
# which will trigger the poll function blow to start in a thread
|
| 203 |
run_id.value = openai.beta.threads.runs.create(
|
| 204 |
thread_id=thread.id,
|
| 205 |
assistant_id="asst_RqVKAzaybZ8un7chIwPCIQdH",
|
|
|
|
| 240 |
completed = True
|
| 241 |
time.sleep(0.1)
|
| 242 |
|
| 243 |
+
# run/restart a thread any time the run_id changes
|
| 244 |
result = solara.use_thread(poll, dependencies=[run_id.value])
|
| 245 |
|
| 246 |
# Create DOM for chat interface
|
| 247 |
+
with solara.Column(classes=["chat-interface"]):
|
|
|
|
|
|
|
| 248 |
if len(messages.value) > 0:
|
| 249 |
with ChatBox():
|
| 250 |
for message in messages.value:
|