NaderAfshar commited on
Commit ·
fd58b95
1
Parent(s): f5f5f81
Committing new and updated files
Browse files- app.py +49 -66
- app2.py +228 -0
- requirements.txt +5 -8
- step3.py +166 -0
- steps.py +141 -0
- storage/default__vector_store.json +1 -0
- storage/docstore.json +1 -0
- storage/graph_store.json +1 -0
- storage/image__vector_store.json +1 -0
- storage/index_store.json +1 -0
- workflows/RAG-EventDriven.html +2 -2
app.py
CHANGED
|
@@ -14,13 +14,10 @@
|
|
| 14 |
|
| 15 |
# Warning control
|
| 16 |
import warnings
|
| 17 |
-
warnings.filterwarnings('ignore')
|
| 18 |
-
|
| 19 |
-
|
| 20 |
import os, json
|
| 21 |
-
from
|
| 22 |
-
from llama_index.llms.
|
| 23 |
-
from llama_index.embeddings.
|
| 24 |
from llama_index.core import (
|
| 25 |
VectorStoreIndex,
|
| 26 |
StorageContext,
|
|
@@ -37,17 +34,26 @@ from llama_index.core.workflow import (
|
|
| 37 |
HumanResponseEvent
|
| 38 |
)
|
| 39 |
from llama_index.utils.workflow import draw_all_possible_flows
|
| 40 |
-
import whisper
|
|
|
|
| 41 |
import gradio as gr
|
| 42 |
import asyncio
|
|
|
|
| 43 |
from queue import Queue
|
| 44 |
from dotenv import load_dotenv
|
| 45 |
|
| 46 |
# Load environment variables
|
| 47 |
load_dotenv()
|
| 48 |
-
|
| 49 |
llama_cloud_api_key = os.getenv("LLAMA_CLOUD_API_KEY")
|
| 50 |
LLAMA_CLOUD_BASE_URL = os.getenv("LLAMA_CLOUD_BASE_URL")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
|
| 52 |
|
| 53 |
class ParseFormEvent(Event):
|
|
@@ -67,7 +73,7 @@ class GenerateQuestionsEvent(Event):
|
|
| 67 |
|
| 68 |
class RAGWorkflow(Workflow):
|
| 69 |
storage_dir = "./storage"
|
| 70 |
-
llm:
|
| 71 |
query_engine: VectorStoreIndex
|
| 72 |
|
| 73 |
@step
|
|
@@ -80,7 +86,7 @@ class RAGWorkflow(Workflow):
|
|
| 80 |
raise ValueError("No application form provided")
|
| 81 |
|
| 82 |
# give ourselves an LLM to work with
|
| 83 |
-
self.llm =
|
| 84 |
|
| 85 |
# ingest our data and set up the query engine
|
| 86 |
if os.path.exists(self.storage_dir):
|
|
@@ -98,7 +104,7 @@ class RAGWorkflow(Workflow):
|
|
| 98 |
# embed and index the documents
|
| 99 |
index = VectorStoreIndex.from_documents(
|
| 100 |
documents,
|
| 101 |
-
embed_model=
|
| 102 |
)
|
| 103 |
index.storage_context.persist(persist_dir=self.storage_dir)
|
| 104 |
|
|
@@ -221,16 +227,11 @@ class RAGWorkflow(Workflow):
|
|
| 221 |
return FeedbackEvent(feedback=ev.response)
|
| 222 |
|
| 223 |
|
| 224 |
-
# In[4]:
|
| 225 |
-
|
| 226 |
|
| 227 |
WORKFLOW_FILE = "workflows/RAG-EventDriven.html"
|
| 228 |
draw_all_possible_flows(RAGWorkflow, filename=WORKFLOW_FILE)
|
| 229 |
|
| 230 |
|
| 231 |
-
# In[5]:
|
| 232 |
-
|
| 233 |
-
|
| 234 |
from IPython.display import display, HTML, DisplayHandle
|
| 235 |
from helper import extract_html_content
|
| 236 |
|
|
@@ -240,15 +241,6 @@ display(HTML(html_content), metadata=dict(isolated=True))
|
|
| 240 |
|
| 241 |
# Cool! You can see the path all the way to the end and the feedback loop is clear.
|
| 242 |
|
| 243 |
-
# <div style="background-color:#fff6ff; padding:13px; border-width:3px; border-color:#efe6ef; border-style:solid; border-radius:6px">
|
| 244 |
-
# <p> 💻 <b>To access <code>fake_application_form.pdf</code>, <code>fake_resume.pdf</code>, <code>requirements.txt</code> and <code>helper.py</code> files:</b> 1) click on the <em>"File"</em> option on the top menu of the notebook and then 2) click on <em>"Open"</em>. The form and resume are inside the data folder.
|
| 245 |
-
#
|
| 246 |
-
# <p> ⬇ <b>Download Notebooks:</b> 1) click on the <em>"File"</em> option on the top menu of the notebook and then 2) click on <em>"Download as"</em> and select <em>"Notebook (.ipynb)"</em>.</p>
|
| 247 |
-
#
|
| 248 |
-
# <p> 📒 For more help, please see the <em>"Appendix – Tips and Help"</em> Lesson.</p>
|
| 249 |
-
#
|
| 250 |
-
# </div>
|
| 251 |
-
|
| 252 |
# <p style="background-color:#f7fff8; padding:15px; border-width:3px; border-color:#e0f0e0; border-style:solid; border-radius:6px"> 🚨
|
| 253 |
# <b>Different Run Results:</b> The output generated by AI chat models can vary with each execution due to their dynamic, probabilistic nature. Don't be surprised if your results differ from those shown in the video.</p>
|
| 254 |
|
|
@@ -258,26 +250,23 @@ display(HTML(html_content), metadata=dict(isolated=True))
|
|
| 258 |
#
|
| 259 |
# Here's a function that takes a file and uses Whisper to return just the text:
|
| 260 |
|
| 261 |
-
# In[6]:
|
| 262 |
-
|
| 263 |
|
| 264 |
def transcribe_speech(filepath):
|
| 265 |
if filepath is None:
|
| 266 |
gr.Warning("No audio found, please retry.")
|
| 267 |
-
|
| 268 |
-
|
| 269 |
-
|
| 270 |
-
|
| 271 |
-
|
| 272 |
-
|
|
|
|
| 273 |
|
| 274 |
|
| 275 |
# But before we can use it, you need to capture some audio from your microphone. That involves some extra steps!
|
| 276 |
#
|
| 277 |
# First, create a callback function that saves data to a global variable.
|
| 278 |
|
| 279 |
-
# In[15]:
|
| 280 |
-
|
| 281 |
|
| 282 |
def store_transcription(output):
|
| 283 |
global transcription_value
|
|
@@ -312,7 +301,8 @@ with test_interface:
|
|
| 312 |
)
|
| 313 |
|
| 314 |
test_interface.launch(
|
| 315 |
-
share=
|
|
|
|
| 316 |
server_port=8000,
|
| 317 |
prevent_thread_lock=True
|
| 318 |
)
|
|
@@ -320,8 +310,6 @@ test_interface.launch(
|
|
| 320 |
|
| 321 |
# You can now print out the transcription, which is stored in that global variable you created earlier:
|
| 322 |
|
| 323 |
-
# In[ ]:
|
| 324 |
-
|
| 325 |
|
| 326 |
print(transcription_value)
|
| 327 |
|
|
@@ -333,7 +321,7 @@ print(transcription_value)
|
|
| 333 |
test_interface.close()
|
| 334 |
|
| 335 |
|
| 336 |
-
#
|
| 337 |
|
| 338 |
# Now create an entirely new class, a Transcription Handler.
|
| 339 |
class TranscriptionHandler:
|
|
@@ -369,8 +357,8 @@ class TranscriptionHandler:
|
|
| 369 |
self.interface = self.create_interface()
|
| 370 |
self.interface.launch(
|
| 371 |
share=False,
|
| 372 |
-
server_port=8000,
|
| 373 |
-
|
| 374 |
)
|
| 375 |
|
| 376 |
# we poll every 1.5 seconds waiting for something to end up in the queue
|
|
@@ -387,30 +375,25 @@ class TranscriptionHandler:
|
|
| 387 |
|
| 388 |
|
| 389 |
|
| 390 |
-
|
| 391 |
-
w = RAGWorkflow(timeout=600, verbose=False)
|
| 392 |
|
| 393 |
-
|
| 394 |
-
|
| 395 |
-
|
| 396 |
-
|
| 397 |
-
|
| 398 |
-
async for event in handler.stream_events():
|
| 399 |
-
if isinstance(event, InputRequiredEvent):
|
| 400 |
-
# Get transcription
|
| 401 |
-
transcription_handler = TranscriptionHandler()
|
| 402 |
-
response = await transcription_handler.get_transcription()
|
| 403 |
-
|
| 404 |
-
handler.ctx.send_event(
|
| 405 |
-
HumanResponseEvent(
|
| 406 |
-
response=response
|
| 407 |
-
)
|
| 408 |
-
)
|
| 409 |
-
|
| 410 |
-
response = await handler
|
| 411 |
-
print("Agent complete! Here's your final result:")
|
| 412 |
-
print(str(response))
|
| 413 |
-
|
| 414 |
-
if __name__ == "__main__":
|
| 415 |
-
asyncio.run(main())
|
| 416 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
# Warning control
|
| 16 |
import warnings
|
|
|
|
|
|
|
|
|
|
| 17 |
import os, json
|
| 18 |
+
from llama_cloud_services import LlamaParse
|
| 19 |
+
from llama_index.llms.cohere import Cohere
|
| 20 |
+
from llama_index.embeddings.huggingface import HuggingFaceEmbedding
|
| 21 |
from llama_index.core import (
|
| 22 |
VectorStoreIndex,
|
| 23 |
StorageContext,
|
|
|
|
| 34 |
HumanResponseEvent
|
| 35 |
)
|
| 36 |
from llama_index.utils.workflow import draw_all_possible_flows
|
| 37 |
+
#import whisper
|
| 38 |
+
from llama_index.readers.whisper import WhisperReader
|
| 39 |
import gradio as gr
|
| 40 |
import asyncio
|
| 41 |
+
import nest_asyncio
|
| 42 |
from queue import Queue
|
| 43 |
from dotenv import load_dotenv
|
| 44 |
|
| 45 |
# Load environment variables
|
| 46 |
load_dotenv()
|
| 47 |
+
CO_API_KEY = os.getenv("COHERE_API_KEY")
|
| 48 |
llama_cloud_api_key = os.getenv("LLAMA_CLOUD_API_KEY")
|
| 49 |
LLAMA_CLOUD_BASE_URL = os.getenv("LLAMA_CLOUD_BASE_URL")
|
| 50 |
+
OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
|
| 51 |
+
|
| 52 |
+
warnings.filterwarnings('ignore')
|
| 53 |
+
|
| 54 |
+
nest_asyncio.apply() # Accommodate nested events.
|
| 55 |
+
|
| 56 |
+
transcription_value = None
|
| 57 |
|
| 58 |
|
| 59 |
class ParseFormEvent(Event):
|
|
|
|
| 73 |
|
| 74 |
class RAGWorkflow(Workflow):
|
| 75 |
storage_dir = "./storage"
|
| 76 |
+
llm: Cohere
|
| 77 |
query_engine: VectorStoreIndex
|
| 78 |
|
| 79 |
@step
|
|
|
|
| 86 |
raise ValueError("No application form provided")
|
| 87 |
|
| 88 |
# give ourselves an LLM to work with
|
| 89 |
+
self.llm = Cohere(api_key=CO_API_KEY, model="command-r-plus")
|
| 90 |
|
| 91 |
# ingest our data and set up the query engine
|
| 92 |
if os.path.exists(self.storage_dir):
|
|
|
|
| 104 |
# embed and index the documents
|
| 105 |
index = VectorStoreIndex.from_documents(
|
| 106 |
documents,
|
| 107 |
+
embed_model=HuggingFaceEmbedding(model_name="BAAI/bge-small-en-v1.5")
|
| 108 |
)
|
| 109 |
index.storage_context.persist(persist_dir=self.storage_dir)
|
| 110 |
|
|
|
|
| 227 |
return FeedbackEvent(feedback=ev.response)
|
| 228 |
|
| 229 |
|
|
|
|
|
|
|
| 230 |
|
| 231 |
WORKFLOW_FILE = "workflows/RAG-EventDriven.html"
|
| 232 |
draw_all_possible_flows(RAGWorkflow, filename=WORKFLOW_FILE)
|
| 233 |
|
| 234 |
|
|
|
|
|
|
|
|
|
|
| 235 |
from IPython.display import display, HTML, DisplayHandle
|
| 236 |
from helper import extract_html_content
|
| 237 |
|
|
|
|
| 241 |
|
| 242 |
# Cool! You can see the path all the way to the end and the feedback loop is clear.
|
| 243 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 244 |
# <p style="background-color:#f7fff8; padding:15px; border-width:3px; border-color:#e0f0e0; border-style:solid; border-radius:6px"> 🚨
|
| 245 |
# <b>Different Run Results:</b> The output generated by AI chat models can vary with each execution due to their dynamic, probabilistic nature. Don't be surprised if your results differ from those shown in the video.</p>
|
| 246 |
|
|
|
|
| 250 |
#
|
| 251 |
# Here's a function that takes a file and uses Whisper to return just the text:
|
| 252 |
|
|
|
|
|
|
|
| 253 |
|
| 254 |
def transcribe_speech(filepath):
|
| 255 |
if filepath is None:
|
| 256 |
gr.Warning("No audio found, please retry.")
|
| 257 |
+
audio_file= open(filepath, "rb")
|
| 258 |
+
reader = WhisperReader(
|
| 259 |
+
model="whisper-1",
|
| 260 |
+
api_key=OPENAI_API_KEY,
|
| 261 |
+
)
|
| 262 |
+
documents = reader.load_data(filepath)
|
| 263 |
+
return documents[0].text
|
| 264 |
|
| 265 |
|
| 266 |
# But before we can use it, you need to capture some audio from your microphone. That involves some extra steps!
|
| 267 |
#
|
| 268 |
# First, create a callback function that saves data to a global variable.
|
| 269 |
|
|
|
|
|
|
|
| 270 |
|
| 271 |
def store_transcription(output):
|
| 272 |
global transcription_value
|
|
|
|
| 301 |
)
|
| 302 |
|
| 303 |
test_interface.launch(
|
| 304 |
+
share=True,
|
| 305 |
+
show_error=True,
|
| 306 |
server_port=8000,
|
| 307 |
prevent_thread_lock=True
|
| 308 |
)
|
|
|
|
| 310 |
|
| 311 |
# You can now print out the transcription, which is stored in that global variable you created earlier:
|
| 312 |
|
|
|
|
|
|
|
| 313 |
|
| 314 |
print(transcription_value)
|
| 315 |
|
|
|
|
| 321 |
test_interface.close()
|
| 322 |
|
| 323 |
|
| 324 |
+
# Make sure to run the previous cell to close the Gradio interface before running the next cell
|
| 325 |
|
| 326 |
# Now create an entirely new class, a Transcription Handler.
|
| 327 |
class TranscriptionHandler:
|
|
|
|
| 357 |
self.interface = self.create_interface()
|
| 358 |
self.interface.launch(
|
| 359 |
share=False,
|
| 360 |
+
server_port=8000,
|
| 361 |
+
inbrowser=True # open in a browser
|
| 362 |
)
|
| 363 |
|
| 364 |
# we poll every 1.5 seconds waiting for something to end up in the queue
|
|
|
|
| 375 |
|
| 376 |
|
| 377 |
|
| 378 |
+
w = RAGWorkflow(timeout=600, verbose=False)
|
|
|
|
| 379 |
|
| 380 |
+
handler = w.run(
|
| 381 |
+
resume_file="./data/fake_resume.pdf",
|
| 382 |
+
application_form="./data/fake_application_form.pdf"
|
| 383 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 384 |
|
| 385 |
+
async for event in handler.stream_events():
|
| 386 |
+
if isinstance(event, InputRequiredEvent):
|
| 387 |
+
# Get transcription
|
| 388 |
+
transcription_handler = TranscriptionHandler()
|
| 389 |
+
response = await transcription_handler.get_transcription()
|
| 390 |
+
|
| 391 |
+
handler.ctx.send_event(
|
| 392 |
+
HumanResponseEvent(
|
| 393 |
+
response=response
|
| 394 |
+
)
|
| 395 |
+
)
|
| 396 |
+
|
| 397 |
+
response = await handler
|
| 398 |
+
print("Agent complete! Here's your final result:")
|
| 399 |
+
print(str(response))
|
app2.py
ADDED
|
@@ -0,0 +1,228 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python
|
| 2 |
+
# coding: utf-8
|
| 3 |
+
|
| 4 |
+
import warnings
|
| 5 |
+
import os
|
| 6 |
+
import json
|
| 7 |
+
import asyncio
|
| 8 |
+
from queue import Queue
|
| 9 |
+
from dotenv import load_dotenv
|
| 10 |
+
import gradio as gr
|
| 11 |
+
from llama_cloud_services import LlamaParse
|
| 12 |
+
from llama_index.llms.cohere import Cohere
|
| 13 |
+
from llama_index.embeddings.huggingface import HuggingFaceEmbedding
|
| 14 |
+
from llama_index.core import (
|
| 15 |
+
VectorStoreIndex,
|
| 16 |
+
StorageContext,
|
| 17 |
+
load_index_from_storage
|
| 18 |
+
)
|
| 19 |
+
from llama_index.core.workflow import (
|
| 20 |
+
StartEvent,
|
| 21 |
+
StopEvent,
|
| 22 |
+
Workflow,
|
| 23 |
+
step,
|
| 24 |
+
Event,
|
| 25 |
+
Context,
|
| 26 |
+
InputRequiredEvent,
|
| 27 |
+
HumanResponseEvent
|
| 28 |
+
)
|
| 29 |
+
from llama_index.readers.whisper import WhisperReader
|
| 30 |
+
import nest_asyncio
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
# Load environment variables
|
| 34 |
+
load_dotenv()
|
| 35 |
+
CO_API_KEY = os.getenv("COHERE_API_KEY")
|
| 36 |
+
llama_cloud_api_key = os.getenv("LLAMA_CLOUD_API_KEY")
|
| 37 |
+
LLAMA_CLOUD_BASE_URL = os.getenv("LLAMA_CLOUD_BASE_URL")
|
| 38 |
+
OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
|
| 39 |
+
|
| 40 |
+
warnings.filterwarnings('ignore')
|
| 41 |
+
|
| 42 |
+
nest_asyncio.apply()
|
| 43 |
+
|
| 44 |
+
# Define Event Classes
|
| 45 |
+
class ParseFormEvent(Event):
|
| 46 |
+
application_form: str
|
| 47 |
+
|
| 48 |
+
class QueryEvent(Event):
|
| 49 |
+
query: str
|
| 50 |
+
|
| 51 |
+
class ResponseEvent(Event):
|
| 52 |
+
response: str
|
| 53 |
+
|
| 54 |
+
class FeedbackEvent(Event):
|
| 55 |
+
feedback: str
|
| 56 |
+
|
| 57 |
+
class GenerateQuestionsEvent(Event):
|
| 58 |
+
pass
|
| 59 |
+
|
| 60 |
+
# Define Workflow
|
| 61 |
+
class RAGWorkflow(Workflow):
|
| 62 |
+
storage_dir = "./storage"
|
| 63 |
+
llm: Cohere
|
| 64 |
+
query_engine: VectorStoreIndex
|
| 65 |
+
|
| 66 |
+
@step
|
| 67 |
+
async def set_up(self, ctx: Context, ev: StartEvent) -> ParseFormEvent:
|
| 68 |
+
if not ev.resume_file:
|
| 69 |
+
raise ValueError("No resume file provided")
|
| 70 |
+
if not ev.application_form:
|
| 71 |
+
raise ValueError("No application form provided")
|
| 72 |
+
|
| 73 |
+
self.llm = Cohere(api_key=CO_API_KEY, model="command-r-plus")
|
| 74 |
+
|
| 75 |
+
if os.path.exists(self.storage_dir):
|
| 76 |
+
storage_context = StorageContext.from_defaults(persist_dir=self.storage_dir)
|
| 77 |
+
index = load_index_from_storage(storage_context)
|
| 78 |
+
else:
|
| 79 |
+
documents = LlamaParse(
|
| 80 |
+
api_key=llama_cloud_api_key,
|
| 81 |
+
base_url=LLAMA_CLOUD_BASE_URL,
|
| 82 |
+
result_type="markdown",
|
| 83 |
+
content_guideline_instruction="This is a resume, gather related facts together and format it as bullet points with headers"
|
| 84 |
+
).load_data(ev.resume_file)
|
| 85 |
+
|
| 86 |
+
index = VectorStoreIndex.from_documents(
|
| 87 |
+
documents,
|
| 88 |
+
embed_model=HuggingFaceEmbedding(model_name="BAAI/bge-small-en-v1.5")
|
| 89 |
+
)
|
| 90 |
+
index.storage_context.persist(persist_dir=self.storage_dir)
|
| 91 |
+
|
| 92 |
+
self.query_engine = index.as_query_engine(llm=self.llm, similarity_top_k=5)
|
| 93 |
+
return ParseFormEvent(application_form=ev.application_form)
|
| 94 |
+
|
| 95 |
+
@step
|
| 96 |
+
async def parse_form(self, ctx: Context, ev: ParseFormEvent) -> GenerateQuestionsEvent:
|
| 97 |
+
parser = LlamaParse(
|
| 98 |
+
api_key=llama_cloud_api_key,
|
| 99 |
+
base_url=LLAMA_CLOUD_BASE_URL,
|
| 100 |
+
result_type="markdown",
|
| 101 |
+
content_guideline_instruction="This is a job application form. Create a list of all the fields that need to be filled in.",
|
| 102 |
+
formatting_instruction="Return a bulleted list of the fields ONLY."
|
| 103 |
+
)
|
| 104 |
+
|
| 105 |
+
result = parser.load_data(ev.application_form)[0]
|
| 106 |
+
raw_json = self.llm.complete(
|
| 107 |
+
f"This is a parsed form. Convert it into a JSON object containing only the list of fields to be filled in, in the form {{ fields: [...] }}. <form>{result.text}</form>. Return JSON ONLY, no markdown."
|
| 108 |
+
)
|
| 109 |
+
fields = json.loads(raw_json.text)["fields"]
|
| 110 |
+
|
| 111 |
+
await ctx.set("fields_to_fill", fields)
|
| 112 |
+
return GenerateQuestionsEvent()
|
| 113 |
+
|
| 114 |
+
@step
|
| 115 |
+
async def generate_questions(self, ctx: Context, ev: GenerateQuestionsEvent | FeedbackEvent) -> QueryEvent:
|
| 116 |
+
fields = await ctx.get("fields_to_fill")
|
| 117 |
+
|
| 118 |
+
for field in fields:
|
| 119 |
+
question = f"How would you answer this question about the candidate? <field>{field}</field>"
|
| 120 |
+
|
| 121 |
+
if hasattr(ev, "feedback"):
|
| 122 |
+
question += f"\nPrevious feedback: <feedback>{ev.feedback}</feedback>"
|
| 123 |
+
|
| 124 |
+
ctx.send_event(QueryEvent(field=field, query=question))
|
| 125 |
+
|
| 126 |
+
await ctx.set("total_fields", len(fields))
|
| 127 |
+
return
|
| 128 |
+
|
| 129 |
+
@step
|
| 130 |
+
async def ask_question(self, ctx: Context, ev: QueryEvent) -> ResponseEvent:
|
| 131 |
+
response = self.query_engine.query(
|
| 132 |
+
f"This is a question about the specific resume we have in our database: {ev.query}"
|
| 133 |
+
)
|
| 134 |
+
return ResponseEvent(field=ev.field, response=response.response)
|
| 135 |
+
|
| 136 |
+
@step
|
| 137 |
+
async def fill_in_application(self, ctx: Context, ev: ResponseEvent) -> InputRequiredEvent:
|
| 138 |
+
total_fields = await ctx.get("total_fields")
|
| 139 |
+
responses = ctx.collect_events(ev, [ResponseEvent] * total_fields)
|
| 140 |
+
|
| 141 |
+
if responses is None:
|
| 142 |
+
return None
|
| 143 |
+
|
| 144 |
+
responseList = "\n".join(f"Field: {r.field}\nResponse: {r.response}" for r in responses)
|
| 145 |
+
result = self.llm.complete(
|
| 146 |
+
f"You are given a list of fields in an application form and responses to questions about those fields from a resume. Combine the two into a list of fields and succinct, factual answers.\n<responses>{responseList}</responses>"
|
| 147 |
+
)
|
| 148 |
+
|
| 149 |
+
await ctx.set("filled_form", str(result))
|
| 150 |
+
|
| 151 |
+
return InputRequiredEvent(
|
| 152 |
+
prefix="How does this look? Provide feedback.",
|
| 153 |
+
result=result
|
| 154 |
+
)
|
| 155 |
+
|
| 156 |
+
@step
|
| 157 |
+
async def get_feedback(self, ctx: Context, ev: HumanResponseEvent) -> FeedbackEvent | StopEvent:
|
| 158 |
+
result = self.llm.complete(
|
| 159 |
+
f"You have received feedback on the form-filling task.\n<feedback>{ev.response}</feedback>\nIf everything is fine, respond with 'OKAY'. Otherwise, respond with 'FEEDBACK'."
|
| 160 |
+
)
|
| 161 |
+
|
| 162 |
+
verdict = result.text.strip()
|
| 163 |
+
return StopEvent(result=await ctx.get("filled_form")) if verdict == "OKAY" else FeedbackEvent(feedback=ev.response)
|
| 164 |
+
|
| 165 |
+
|
| 166 |
+
# Transcription Handler
|
| 167 |
+
class TranscriptionHandler:
|
| 168 |
+
def __init__(self):
|
| 169 |
+
self.transcription_queue = Queue()
|
| 170 |
+
self.interface = None
|
| 171 |
+
|
| 172 |
+
def store_transcription(self, output):
|
| 173 |
+
self.transcription_queue.put(output)
|
| 174 |
+
return output
|
| 175 |
+
|
| 176 |
+
def create_interface(self):
|
| 177 |
+
mic_transcribe = gr.Interface(
|
| 178 |
+
fn=lambda x: self.store_transcription(transcribe_speech(x)),
|
| 179 |
+
inputs=gr.Audio(sources=["microphone"], type="filepath"),
|
| 180 |
+
outputs=gr.Textbox(label="Transcription")
|
| 181 |
+
)
|
| 182 |
+
self.interface = gr.Blocks()
|
| 183 |
+
with self.interface:
|
| 184 |
+
gr.TabbedInterface([mic_transcribe], ["Transcribe Microphone"])
|
| 185 |
+
return self.interface
|
| 186 |
+
|
| 187 |
+
async def get_transcription(self):
|
| 188 |
+
self.interface = self.create_interface()
|
| 189 |
+
self.interface.launch(share=False, server_port=8000, inbrowser=True)
|
| 190 |
+
|
| 191 |
+
while True:
|
| 192 |
+
if not self.transcription_queue.empty():
|
| 193 |
+
result = self.transcription_queue.get()
|
| 194 |
+
self.interface.close()
|
| 195 |
+
return result
|
| 196 |
+
await asyncio.sleep(1.5)
|
| 197 |
+
|
| 198 |
+
|
| 199 |
+
# Transcription function
|
| 200 |
+
def transcribe_speech(filepath):
|
| 201 |
+
if not filepath:
|
| 202 |
+
gr.Warning("No audio found, please retry.")
|
| 203 |
+
reader = WhisperReader(model="whisper-1", api_key=OPENAI_API_KEY)
|
| 204 |
+
documents = reader.load_data(filepath)
|
| 205 |
+
return documents[0].text
|
| 206 |
+
|
| 207 |
+
|
| 208 |
+
# Async Wrapper
|
| 209 |
+
async def main():
|
| 210 |
+
w = RAGWorkflow(timeout=600, verbose=False)
|
| 211 |
+
|
| 212 |
+
handler = w.run(
|
| 213 |
+
resume_file="./data/fake_resume.pdf",
|
| 214 |
+
application_form="./data/fake_application_form.pdf"
|
| 215 |
+
)
|
| 216 |
+
|
| 217 |
+
async for event in handler.stream_events():
|
| 218 |
+
if isinstance(event, InputRequiredEvent):
|
| 219 |
+
transcription_handler = TranscriptionHandler()
|
| 220 |
+
response = await transcription_handler.get_transcription()
|
| 221 |
+
handler.ctx.send_event(HumanResponseEvent(response=response))
|
| 222 |
+
|
| 223 |
+
response = await handler
|
| 224 |
+
print("Agent complete! Here's your final result:")
|
| 225 |
+
print(str(response))
|
| 226 |
+
|
| 227 |
+
if __name__ == "__main__":
|
| 228 |
+
asyncio.run(main())
|
requirements.txt
CHANGED
|
@@ -1,23 +1,20 @@
|
|
| 1 |
pytorch
|
| 2 |
gradio ==5.20.1
|
| 3 |
gradio_client ==1.7.2
|
| 4 |
-
llama-
|
| 5 |
llama-index ==0.12.23
|
| 6 |
-
llama-index-agent-openai ==0.4.6
|
| 7 |
llama-index-cli ==0.4.1
|
| 8 |
llama-index-core ==0.12.23.post2
|
| 9 |
llama-index-embeddings-huggingface ==0.5.2
|
| 10 |
-
llama-index-embeddings-openai ==0.3.1
|
| 11 |
llama-index-indices-managed-llama-cloud ==0.6.8
|
| 12 |
llama-index-llms-cohere ==0.4.0
|
| 13 |
-
llama-index-llms-openai
|
| 14 |
-
llama-index-
|
| 15 |
-
llama-index-program-openai ==0.3.1
|
| 16 |
-
llama-index-question-gen-openai ==0.3.0
|
| 17 |
llama-index-readers-file ==0.4.6
|
| 18 |
llama-index-readers-llama-parse ==0.4.0
|
| 19 |
llama-index-utils-workflow ==0.3.0
|
| 20 |
-
openai-whisper ==20240930
|
|
|
|
| 21 |
pydantic ==2.10.6
|
| 22 |
pydantic_core ==2.27.2
|
| 23 |
dotenv
|
|
|
|
| 1 |
pytorch
|
| 2 |
gradio ==5.20.1
|
| 3 |
gradio_client ==1.7.2
|
| 4 |
+
llama-parse
|
| 5 |
llama-index ==0.12.23
|
|
|
|
| 6 |
llama-index-cli ==0.4.1
|
| 7 |
llama-index-core ==0.12.23.post2
|
| 8 |
llama-index-embeddings-huggingface ==0.5.2
|
|
|
|
| 9 |
llama-index-indices-managed-llama-cloud ==0.6.8
|
| 10 |
llama-index-llms-cohere ==0.4.0
|
| 11 |
+
llama-index-llms-openai
|
| 12 |
+
llama-index-llms-groq
|
|
|
|
|
|
|
| 13 |
llama-index-readers-file ==0.4.6
|
| 14 |
llama-index-readers-llama-parse ==0.4.0
|
| 15 |
llama-index-utils-workflow ==0.3.0
|
| 16 |
+
#openai-whisper ==20240930
|
| 17 |
+
llama-index-readers-whisper
|
| 18 |
pydantic ==2.10.6
|
| 19 |
pydantic_core ==2.27.2
|
| 20 |
dotenv
|
step3.py
ADDED
|
@@ -0,0 +1,166 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from helper import get_llama_cloud_api_key
|
| 2 |
+
from helper import extract_html_content
|
| 3 |
+
from IPython.display import display, HTML
|
| 4 |
+
from llama_index.utils.workflow import draw_all_possible_flows
|
| 5 |
+
from llama_index.core.tools import FunctionTool
|
| 6 |
+
from llama_index.core.agent import FunctionCallingAgent
|
| 7 |
+
from llama_index.core import Settings
|
| 8 |
+
from llama_parse import LlamaParse
|
| 9 |
+
from llama_index.llms.groq import Groq
|
| 10 |
+
from llama_index.embeddings.huggingface import HuggingFaceEmbedding
|
| 11 |
+
from llama_index.core import (
|
| 12 |
+
VectorStoreIndex,
|
| 13 |
+
StorageContext,
|
| 14 |
+
load_index_from_storage
|
| 15 |
+
)
|
| 16 |
+
import nest_asyncio
|
| 17 |
+
from llama_index.core.workflow import (
|
| 18 |
+
StartEvent,
|
| 19 |
+
StopEvent,
|
| 20 |
+
Workflow,
|
| 21 |
+
step,
|
| 22 |
+
Event,
|
| 23 |
+
Context
|
| 24 |
+
)
|
| 25 |
+
from pathlib import Path
|
| 26 |
+
from dotenv import load_dotenv
|
| 27 |
+
import os
|
| 28 |
+
import asyncio
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
storage_dir = "./storage"
|
| 32 |
+
nest_asyncio.apply()
|
| 33 |
+
|
| 34 |
+
load_dotenv()
|
| 35 |
+
llama_cloud_api_key = os.getenv("LLAMA_CLOUD_API_KEY")
|
| 36 |
+
GROQ_API_KEY = os.getenv("GROQ_API_KEY")
|
| 37 |
+
LLAMA_CLOUD_BASE_URL = os.getenv("LLAMA_CLOUD_BASE_URL")
|
| 38 |
+
|
| 39 |
+
global_llm = Groq(api_key=GROQ_API_KEY, model="llama3-70b-8192")
|
| 40 |
+
global_embed_model = HuggingFaceEmbedding(model_name="BAAI/bge-small-en-v1.5")
|
| 41 |
+
Settings.embed_model = global_embed_model
|
| 42 |
+
|
| 43 |
+
documents = LlamaParse(
|
| 44 |
+
api_key=llama_cloud_api_key,
|
| 45 |
+
result_type="markdown",
|
| 46 |
+
content_guideline_instruction="This is a resume, gather related facts together and format it as "
|
| 47 |
+
"bullet points with headers"
|
| 48 |
+
).load_data("data/fake_resume.pdf")
|
| 49 |
+
|
| 50 |
+
print(documents[0].text)
|
| 51 |
+
|
| 52 |
+
index = VectorStoreIndex.from_documents(
|
| 53 |
+
documents,
|
| 54 |
+
embed_model=global_embed_model
|
| 55 |
+
)
|
| 56 |
+
|
| 57 |
+
query_engine = index.as_query_engine(llm=global_llm, similarity_top_k=5)
|
| 58 |
+
response = query_engine.query("What is this person's name and what was their most recent job?")
|
| 59 |
+
print(response)
|
| 60 |
+
|
| 61 |
+
index.storage_context.persist(persist_dir=storage_dir)
|
| 62 |
+
|
| 63 |
+
restored_index = None
|
| 64 |
+
# Check if the index is stored on disk
|
| 65 |
+
if os.path.exists(storage_dir):
|
| 66 |
+
# Load the index from disk
|
| 67 |
+
storage_context = StorageContext.from_defaults(persist_dir=storage_dir)
|
| 68 |
+
restored_index = load_index_from_storage(storage_context)
|
| 69 |
+
else:
|
| 70 |
+
print("Index not found on disk.")
|
| 71 |
+
|
| 72 |
+
|
| 73 |
+
print("\n\n Reading back the index \n")
|
| 74 |
+
response = restored_index.as_query_engine(llm=global_llm, similarity_top_k=5)\
|
| 75 |
+
.query("What is this person's name and what was their most recent job?")
|
| 76 |
+
print(response)
|
| 77 |
+
|
| 78 |
+
print("\n\n" + "="*50, "\n\n")
|
| 79 |
+
|
| 80 |
+
|
| 81 |
+
def query_resume(q: str) -> str:
|
| 82 |
+
"""Answers questions about a specific resume."""
|
| 83 |
+
# we're using the query engine we already created above
|
| 84 |
+
response = query_engine.query(f"This is a question about the specific resume we have in our database: {q}")
|
| 85 |
+
return response.response
|
| 86 |
+
|
| 87 |
+
|
| 88 |
+
resume_tool = FunctionTool.from_defaults(fn=query_resume)
|
| 89 |
+
|
| 90 |
+
agent = FunctionCallingAgent.from_tools(
|
| 91 |
+
tools=[resume_tool],
|
| 92 |
+
llm=global_llm,
|
| 93 |
+
verbose=True
|
| 94 |
+
)
|
| 95 |
+
|
| 96 |
+
response = agent.chat("How many years of experience does the applicant have?")
|
| 97 |
+
print(response)
|
| 98 |
+
|
| 99 |
+
|
| 100 |
+
class QueryEvent(Event):
|
| 101 |
+
query: str
|
| 102 |
+
|
| 103 |
+
|
| 104 |
+
class RAGWorkflow(Workflow):
|
| 105 |
+
storage_dir = "./storage"
|
| 106 |
+
llm: Groq
|
| 107 |
+
query_engine: VectorStoreIndex
|
| 108 |
+
|
| 109 |
+
# the first step will be setup
|
| 110 |
+
@step
|
| 111 |
+
async def set_up(self, ctx: Context, ev: StartEvent) -> QueryEvent:
|
| 112 |
+
|
| 113 |
+
if not ev.resume_file:
|
| 114 |
+
raise ValueError("No resume file provided")
|
| 115 |
+
|
| 116 |
+
# define an LLM to work with
|
| 117 |
+
self.llm = global_llm
|
| 118 |
+
|
| 119 |
+
# ingest the data and set up the query engine
|
| 120 |
+
if os.path.exists(self.storage_dir):
|
| 121 |
+
# you've already ingested your documents
|
| 122 |
+
storage_context = StorageContext.from_defaults(persist_dir=self.storage_dir)
|
| 123 |
+
index = load_index_from_storage(storage_context)
|
| 124 |
+
else:
|
| 125 |
+
# parse and load your documents
|
| 126 |
+
documents = LlamaParse(
|
| 127 |
+
result_type="markdown",
|
| 128 |
+
content_guideline_instruction="This is a resume, gather related facts together and format it as bullet points with headers"
|
| 129 |
+
).load_data(ev.resume_file)
|
| 130 |
+
# embed and index the documents
|
| 131 |
+
index = VectorStoreIndex.from_documents(
|
| 132 |
+
documents,
|
| 133 |
+
embed_model=global_embed_model
|
| 134 |
+
)
|
| 135 |
+
index.storage_context.persist(persist_dir=self.storage_dir)
|
| 136 |
+
|
| 137 |
+
# either way, create a query engine
|
| 138 |
+
self.query_engine = index.as_query_engine(llm=self.llm, similarity_top_k=5)
|
| 139 |
+
|
| 140 |
+
# now fire off a query event to trigger the next step
|
| 141 |
+
return QueryEvent(query=ev.query)
|
| 142 |
+
|
| 143 |
+
# the second step will be to ask a question and return a result immediately
|
| 144 |
+
@step
|
| 145 |
+
async def ask_question(self, ctx: Context, ev: QueryEvent) -> StopEvent:
|
| 146 |
+
response = self.query_engine.query(f"This is a question about the specific resume we have in our database: {ev.query}")
|
| 147 |
+
return StopEvent(result=response.response)
|
| 148 |
+
|
| 149 |
+
|
| 150 |
+
async def main():
|
| 151 |
+
w = RAGWorkflow(timeout=120, verbose=False)
|
| 152 |
+
result = await w.run(
|
| 153 |
+
resume_file="./data/fake_resume.pdf",
|
| 154 |
+
query="Where is the first place the applicant worked?"
|
| 155 |
+
)
|
| 156 |
+
print(result)
|
| 157 |
+
|
| 158 |
+
# Display of the workflow
|
| 159 |
+
workflow_file = Path(__file__).parent / "workflows" / "rag_workflow.html"
|
| 160 |
+
draw_all_possible_flows(w, filename=str(workflow_file))
|
| 161 |
+
html_content = extract_html_content(str(workflow_file))
|
| 162 |
+
display(HTML(html_content), metadata=dict(isolated=True))
|
| 163 |
+
|
| 164 |
+
|
| 165 |
+
if __name__ == "__main__":
|
| 166 |
+
asyncio.run(main())
|
steps.py
ADDED
|
@@ -0,0 +1,141 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import warnings
|
| 2 |
+
import os
|
| 3 |
+
import json
|
| 4 |
+
import random
|
| 5 |
+
import asyncio
|
| 6 |
+
from queue import Queue
|
| 7 |
+
from dotenv import load_dotenv
|
| 8 |
+
import gradio as gr
|
| 9 |
+
from llama_cloud_services import LlamaParse
|
| 10 |
+
from llama_index.utils.workflow import draw_all_possible_flows
|
| 11 |
+
from llama_index.llms.cohere import Cohere
|
| 12 |
+
from llama_index.llms.openai import OpenAI
|
| 13 |
+
from llama_index.llms.groq import Groq
|
| 14 |
+
from llama_index.embeddings.huggingface import HuggingFaceEmbedding
|
| 15 |
+
from llama_index.core import (
|
| 16 |
+
VectorStoreIndex,
|
| 17 |
+
StorageContext,
|
| 18 |
+
load_index_from_storage
|
| 19 |
+
)
|
| 20 |
+
from llama_index.core.workflow import (
|
| 21 |
+
StartEvent,
|
| 22 |
+
StopEvent,
|
| 23 |
+
Workflow,
|
| 24 |
+
step,
|
| 25 |
+
Event,
|
| 26 |
+
Context,
|
| 27 |
+
InputRequiredEvent,
|
| 28 |
+
HumanResponseEvent
|
| 29 |
+
)
|
| 30 |
+
from llama_index.readers.whisper import WhisperReader
|
| 31 |
+
import nest_asyncio
|
| 32 |
+
|
| 33 |
+
from IPython.display import display, HTML, DisplayHandle
|
| 34 |
+
from helper import extract_html_content
|
| 35 |
+
from pathlib import Path
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
# Load environment variables
|
| 39 |
+
load_dotenv()
|
| 40 |
+
CO_API_KEY = os.getenv("COHERE_API_KEY")
|
| 41 |
+
llama_cloud_api_key = os.getenv("LLAMA_CLOUD_API_KEY")
|
| 42 |
+
LLAMA_CLOUD_BASE_URL = os.getenv("LLAMA_CLOUD_BASE_URL")
|
| 43 |
+
OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
|
| 44 |
+
GROQ_API_KEY = os.getenv("GROQ_API_KEY")
|
| 45 |
+
|
| 46 |
+
warnings.filterwarnings('ignore')
|
| 47 |
+
#llm = Cohere(api_key=CO_API_KEY, model="command-r")
|
| 48 |
+
#llm = OpenAI(api_key=OPENAI_API_KEY, model="gpt-4o-mini")
|
| 49 |
+
llm = Groq(api_key=GROQ_API_KEY, model="llama3-70b-8192")
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
class FirstEvent(Event):
|
| 53 |
+
first_output: str
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
class SecondEvent(Event):
|
| 57 |
+
second_output: str
|
| 58 |
+
response: str
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
class TextEvent(Event):
|
| 62 |
+
delta: str
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
class ProgressEvent(Event):
|
| 66 |
+
msg: str
|
| 67 |
+
|
| 68 |
+
|
| 69 |
+
class MyWorkflow(Workflow):
|
| 70 |
+
@step
|
| 71 |
+
async def step_one(self, ctx: Context, ev: StartEvent) -> FirstEvent:
|
| 72 |
+
ctx.write_event_to_stream(ProgressEvent(msg="Step one is happening"))
|
| 73 |
+
return FirstEvent(first_output="First step complete.")
|
| 74 |
+
|
| 75 |
+
@step
|
| 76 |
+
async def step_two(self, ctx: Context, ev: FirstEvent) -> SecondEvent:
|
| 77 |
+
# Pay attention to this API: ;;m.astream.complete(). Here "a" is for async.
|
| 78 |
+
generator = await llm.astream_complete(
|
| 79 |
+
"Please give me the first 50 words of Moby Dick, a book in the public domain."
|
| 80 |
+
)
|
| 81 |
+
|
| 82 |
+
async for response in generator:
|
| 83 |
+
# Allow the workflow to stream this piece of response
|
| 84 |
+
ctx.write_event_to_stream(TextEvent(delta=response.delta))
|
| 85 |
+
|
| 86 |
+
return SecondEvent(
|
| 87 |
+
second_output="Second step complete, full response attached",
|
| 88 |
+
response=str(response),
|
| 89 |
+
)
|
| 90 |
+
|
| 91 |
+
@step
|
| 92 |
+
async def step_three(self, ctx: Context, ev: SecondEvent) -> StopEvent:
|
| 93 |
+
ctx.write_event_to_stream(ProgressEvent(msg="\nStep three is happening"))
|
| 94 |
+
return StopEvent(result="Workflow complete.")
|
| 95 |
+
|
| 96 |
+
|
| 97 |
+
async def main():
|
| 98 |
+
workflow = MyWorkflow(timeout=30, verbose=False)
|
| 99 |
+
handler = workflow.run(first_input="Start the workflow.")
|
| 100 |
+
|
| 101 |
+
async for ev in handler.stream_events():
|
| 102 |
+
if isinstance(ev, ProgressEvent):
|
| 103 |
+
print(ev.msg)
|
| 104 |
+
if isinstance(ev, TextEvent):
|
| 105 |
+
print(ev.delta, end="")
|
| 106 |
+
|
| 107 |
+
final_result = await handler
|
| 108 |
+
print("Final result = ", final_result)
|
| 109 |
+
|
| 110 |
+
# Display of the workflow
|
| 111 |
+
workflow_file = Path(__file__).parent / "workflows" / "RAG-EventDriven.html"
|
| 112 |
+
draw_all_possible_flows(workflow, filename=str(workflow_file))
|
| 113 |
+
|
| 114 |
+
html_content = extract_html_content(workflow_file)
|
| 115 |
+
display(HTML(html_content), metadata=dict(isolated=True))
|
| 116 |
+
|
| 117 |
+
|
| 118 |
+
if __name__ == "__main__":
|
| 119 |
+
asyncio.run(main())
|
| 120 |
+
|
| 121 |
+
|
| 122 |
+
|
| 123 |
+
'''
|
| 124 |
+
# instantiate the workflow
|
| 125 |
+
async def main():
|
| 126 |
+
from pathlib import Path
|
| 127 |
+
workflow = MyWorkflow(timeout=10, verbose=False)
|
| 128 |
+
result = await workflow.run(first_input="Start the workflow.")
|
| 129 |
+
print(result)
|
| 130 |
+
|
| 131 |
+
# Test the display of the workflow
|
| 132 |
+
WORKFLOW_FILE = Path(__file__).parent / "workflows" / "RAG-EventDriven.html"
|
| 133 |
+
draw_all_possible_flows(workflow, filename=str(WORKFLOW_FILE))
|
| 134 |
+
|
| 135 |
+
html_content = extract_html_content(WORKFLOW_FILE)
|
| 136 |
+
display(HTML(html_content), metadata=dict(isolated=True))
|
| 137 |
+
print(result)
|
| 138 |
+
|
| 139 |
+
if __name__ == "__main__":
|
| 140 |
+
asyncio.run(main())
|
| 141 |
+
'''
|
storage/default__vector_store.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"embedding_dict": {"949fb843-d2e1-4df7-858d-6ea740348615": [-0.020423749461770058, 0.00410477863624692, -0.03959893807768822, -0.027569523081183434, -0.02744361013174057, -0.041709963232278824, -0.020953059196472168, 0.0424102321267128, 0.0070471628569066525, 0.03129240870475769, 0.009148924611508846, -0.06779246777296066, 0.01039735134691, -0.029072396457195282, 0.02673731930553913, 0.04951454699039459, -0.010763268917798996, -0.0113962572067976, -0.010601821355521679, 0.021657392382621765, 0.009539928287267685, -0.03809518367052078, -0.012542372569441795, -0.013446645811200142, 0.019652241840958595, 0.008892602287232876, -0.03134826198220253, -0.031112223863601685, 0.01763404719531536, -0.1772795468568802, -0.036278728395700455, 0.01820453628897667, 0.054610904306173325, -0.021267928183078766, 0.05088735371828079, -0.037977807223796844, 0.034602317959070206, -0.010789809748530388, -0.050366051495075226, -0.011662923730909824, -0.03032693825662136, -0.002638117643073201, 0.003832531627267599, 0.02067975327372551, -0.00795040000230074, -0.035482652485370636, -0.001285213278606534, -0.004110515583306551, -0.06809874624013901, -0.004148754756897688, -0.041867952793836594, -0.06540362536907196, -0.037066325545310974, 0.03563074395060539, 0.01872185803949833, 0.015004496090114117, 0.026009101420640945, 0.012490692548453808, -0.02907627820968628, 0.05924493446946144, 0.030421875417232513, -0.01509262528270483, -0.11066746711730957, 0.05097777396440506, 0.062401339411735535, 0.09266693145036697, -0.01502771582454443, -0.06289611011743546, -0.015988726168870926, 0.03495841845870018, 0.002465705620124936, 0.012939674779772758, -0.02670181728899479, 0.042300429195165634, 0.03615913540124893, 0.016131117939949036, 0.0963212326169014, 0.015922971069812775, 0.01197795756161213, 0.0269565898925066, -0.005713308695703745, -0.08395648002624512, -0.00907319039106369, 0.032065410166978836, 0.01700935885310173, 0.008160727098584175, -0.027379468083381653, 0.029870634898543358, 0.03720197081565857, 0.04909859225153923, 0.02195289544761181, 0.018105708062648773, 0.03980959206819534, -0.019042866304516792, -0.03645585849881172, -0.002377524506300688, 0.022363385185599327, 0.04551755636930466, 0.0015804496360942721, 0.4498453140258789, -0.04338901489973068, -0.020658569410443306, -0.0295588206499815, -0.03287849575281143, 0.027398400008678436, 0.008231702260673046, 0.03658454120159149, -0.000939337769523263, 0.026301635429263115, 0.008547990582883358, -0.03691079467535019, -0.031019559130072594, 0.061091769486665726, -0.028558984398841858, 0.013133954256772995, -0.005849332083016634, -0.0030317725613713264, 0.03242901340126991, 0.009456201456487179, -0.005154249724000692, 0.04757615551352501, 0.06765532493591309, 0.042317166924476624, -0.05858435109257698, -0.004576721228659153, 0.049311697483062744, 0.0011206739582121372, 0.0597059540450573, -0.005417617503553629, 0.12684544920921326, 0.024989938363432884, 0.04078371450304985, 0.017335200682282448, -0.00644930312409997, -0.004308067727833986, -0.016597235575318336, -0.07727187871932983, -0.06686728447675705, -0.028145743533968925, 0.08646252751350403, -0.055703241378068924, 0.02281826362013817, -0.02410641312599182, -0.023507876321673393, -0.023843377828598022, 0.041310034692287445, 0.0317242294549942, 0.012662828899919987, 0.02080390602350235, 0.00846031028777361, 0.014472910203039646, 0.04123539477586746, -0.006300431210547686, -0.04311465099453926, -0.0026084440760314465, 0.02936951071023941, 0.00952248927205801, -0.004472213797271252, -0.07129170745611191, 0.01823875866830349, -0.01865188218653202, -0.012867280282080173, 0.026158545166254044, 0.01858024299144745, 0.008625590242445469, -0.14799438416957855, 0.020847884938120842, 0.030502693727612495, 0.03386717289686203, -0.06337320059537888, -0.02237853594124317, -0.015859905630350113, -0.06203273683786392, -0.06025172024965286, 0.04790010303258896, -0.02977094240486622, -0.02982066012918949, -0.003482510568574071, 0.007860020734369755, 0.003976714797317982, -0.006124473642557859, 0.03245169296860695, 0.0009277199278585613, 0.04408995434641838, -0.02023613452911377, -0.06041561812162399, 0.02159396931529045, 0.012034798040986061, -0.015649905428290367, -0.020107805728912354, -0.06760213524103165, 0.03311021625995636, -0.035620469599962234, 0.02295125275850296, 0.048563580960035324, -0.006613114848732948, 0.0816645547747612, -0.06650641560554504, 0.01067241933196783, -0.011992820538580418, 0.10618086159229279, 0.06758811324834824, -0.022925280034542084, 0.016161292791366577, -0.032337650656700134, -0.011678492650389671, 0.026034345850348473, 0.0465838797390461, 0.061940938234329224, 0.022977396845817566, -0.01563957706093788, -0.0013291555223986506, 0.02159111388027668, 0.0344565324485302, 0.03567863628268242, -0.06408921629190445, 0.006175400223582983, 0.024620013311505318, 0.007413909770548344, 0.023988472297787666, 0.017263639718294144, 0.009375846944749355, -0.07514318078756332, -0.2994374930858612, 0.0032298481091856956, -0.01882956735789776, -0.0008250133832916617, -0.0563361756503582, -0.012800078839063644, 0.03152719512581825, -0.000800585316028446, -0.003814669558778405, 0.049737926572561264, 0.08072611689567566, 0.0490516796708107, 0.053099676966667175, -0.066283218562603, 0.013114342465996742, -0.028616374358534813, 0.059143729507923126, -0.037646785378456116, -0.013914422132074833, -0.030098872259259224, 0.03961369767785072, -0.02091013267636299, 0.00776439905166626, -0.1295919120311737, 0.04042470455169678, -0.01813306286931038, 0.09676332026720047, 0.06959429383277893, -0.04589959233999252, -0.09575694799423218, -0.005863768048584461, -0.045767247676849365, 0.03254956752061844, -0.13041146099567413, 0.059330739080905914, 0.0025037892628461123, 0.032470811158418655, -0.02961512841284275, 0.009274769574403763, 0.041754961013793945, -0.015049168840050697, 0.010986804030835629, -0.03859458863735199, -0.053780682384967804, -0.0014185786712914705, -0.047871772199869156, -0.03475818410515785, -0.08581393957138062, -0.023583093658089638, 0.01952718012034893, -0.017033753916621208, -0.0050774309784173965, 0.012300482951104641, 0.017442423850297928, -0.04722842201590538, -0.006174788344651461, 0.00458670174703002, 0.021127276122570038, -0.011262929998338223, -0.010686388239264488, -0.03178451955318451, -0.03218111768364906, -0.018160656094551086, 0.001149826915934682, -0.01978180930018425, -0.0007407140219584107, 0.02340368926525116, -0.045553985983133316, 0.008827767334878445, -0.07911369204521179, -0.041971202939748764, 0.059493839740753174, -0.008084083907306194, -0.004048218484967947, 0.04016747325658798, 0.0026171167846769094, 0.018847033381462097, 0.0007799767190590501, 0.009726558811962605, 0.03453671559691429, 0.005263587459921837, -0.03991551324725151, 0.06573418527841568, 0.05593233183026314, 0.03172401338815689, 0.03821314498782158, 0.06725562363862991, -0.0034097798634320498, -0.031564537435770035, 0.03133765980601311, -0.01812797784805298, 0.016283512115478516, -0.061753325164318085, -0.059131212532520294, 0.0010721199214458466, 0.0024194156285375357, -0.2349187582731247, 0.019512834027409554, 0.014799099415540695, -0.04524233564734459, 0.00370545475743711, 0.007880056276917458, 0.041399016976356506, -0.015890346840023994, -0.020128628239035606, -0.0014705038629472256, -0.0039368886500597, 0.03356924653053284, 0.08662919700145721, 0.0029673136305063963, 0.05075853317975998, 0.04066026583313942, 0.04435833543539047, 0.03100826032459736, 0.029977036640048027, 0.009859045036137104, 0.04252171888947487, 0.018138939514756203, 0.1668182611465454, -0.021056486293673515, 0.025080040097236633, 0.02269195206463337, -0.00422894861549139, 0.0056631481274962425, 0.05249670520424843, 0.007824722677469254, -0.021112345159053802, -0.053076546639204025, 0.010038626380264759, 0.007573668844997883, -0.06068864464759827, -0.01129821315407753, -0.0040957750752568245, -0.031704410910606384, -0.024347610771656036, 0.025526169687509537, 0.09941771626472473, -0.010778024792671204, 0.03743874281644821, -0.007443481124937534, 0.07126263529062271, -0.04638288915157318, -0.07363323122262955, -0.07404593378305435, -0.004670256748795509, -0.029621200636029243, -0.05455372482538223, -0.04815134406089783, 0.004863479640334845, -0.013309670612215996, -0.023167084902524948, 0.05597292259335518, 0.0035438265185803175, -0.034332871437072754, -0.10126355290412903, -0.029351120814681053, -0.0036261137574911118, -0.01363946683704853, 0.020965101197361946, 0.0508677177131176, 0.026757536455988884], "eda5445f-43af-4348-a05b-a7c16f03cc4c": [-0.069781593978405, -0.013873922638595104, -0.006308151874691248, -0.06538788974285126, 0.023965971544384956, -0.003410632722079754, -0.04852736368775368, 0.0469718798995018, 0.006770620588213205, 0.018033456057310104, 0.0016102808294817805, -0.06243492662906647, -0.0007300369325093925, -0.010014286264777184, 0.06133260950446129, 0.05953250452876091, -0.025107717141509056, -0.033459488302469254, -0.004971526097506285, 0.002171438420191407, -0.0393802672624588, 0.0007621749537065625, 0.008513989858329296, -0.06879079341888428, 0.026111818850040436, 0.012525085359811783, 0.004889010451734066, -0.08196038007736206, -0.0077954428270459175, -0.1416730135679245, 0.017641248181462288, 0.029656557366251945, 0.029647106304764748, -0.01787773333489895, 0.029504533857107162, 0.03369882330298424, 6.177310569910333e-05, -0.00930225383490324, -0.001604773453436792, -0.024071821942925453, -0.015807567164301872, 0.013942889869213104, -0.012890560552477837, 0.043240923434495926, 0.011878915131092072, -0.06749359518289566, -0.016515662893652916, -0.021756354719400406, -0.08532699942588806, 0.000986779574304819, 0.009436802007257938, -0.06583008915185928, -0.047803282737731934, 0.015868881717324257, 0.03818907216191292, 0.008253577165305614, 0.031918928027153015, 0.02518889494240284, 0.01517234742641449, 0.04970960691571236, 0.05620546638965607, -0.05201468616724014, -0.18630501627922058, 0.07128170877695084, 0.04442593455314636, 0.04756423085927963, -0.012913192622363567, -0.09521473199129105, 0.015558892861008644, -0.006049163639545441, 0.0317641906440258, -0.01583714224398136, 0.03159784898161888, 0.06532072275876999, 0.043180983513593674, 0.02602476440370083, 0.023268334567546844, 0.04657715931534767, 0.03648393601179123, -0.03993532061576843, 0.010314417071640491, -0.04638480395078659, 0.008401170372962952, 0.017940092831850052, -0.016378171741962433, -0.00954380352050066, -0.014447706751525402, 0.0029935480561107397, -0.0010364240733906627, 0.03985007852315903, -0.02712932974100113, 0.008105253800749779, 0.02456553466618061, -0.030565867200493813, -0.03654484823346138, 0.019585879519581795, -0.0015403900761157274, 0.005927133373916149, -0.05007694661617279, 0.42199617624282837, -0.02770966850221157, -0.012174634262919426, -0.01653645932674408, -0.0002654017589520663, 0.05297181010246277, -0.0003831910144072026, 0.060913730412721634, -0.012132181786000729, 0.005837585311383009, 0.02714100107550621, -0.021498193964362144, 0.002188536338508129, 0.09152457118034363, -0.058788564056158066, -0.008630559779703617, 0.003191881813108921, 0.02527552656829357, 0.017854558303952217, 0.021934861317276955, 0.006601930595934391, 0.0406033881008625, 0.046544209122657776, 0.03250766918063164, -0.02818894572556019, -0.012139401398599148, 0.05342886596918106, -0.014505136758089066, 0.06295791268348694, -0.00690750777721405, 0.059016212821006775, 0.01977587677538395, 0.10214836895465851, -0.011413550935685635, 0.0014139721170067787, -0.000973717775195837, -0.015514547005295753, -0.07561034709215164, -0.037787824869155884, -0.026380861178040504, 0.05931389704346657, -0.015194352716207504, 0.04945690184831619, 0.04560018703341484, -0.07369445264339447, 0.00021131077664904296, 0.059015292674303055, 0.025138171389698982, 0.01251013670116663, 0.022634319961071014, -0.013581326231360435, 0.017987264320254326, 0.07463161647319794, -0.015886882320046425, -0.03973817080259323, -0.03572045639157295, -0.01144353672862053, -0.009288672357797623, 0.035734519362449646, -0.050477027893066406, -0.020965494215488434, -0.05377501621842384, 0.0014880480011925101, -0.01061150524765253, 0.056961048394441605, 0.025627126917243004, -0.15735861659049988, 0.03734267130494118, 0.0923972949385643, 0.026839032769203186, -0.010501649230718613, -0.013094400987029076, 0.018079319968819618, -0.01788272336125374, -0.04915109649300575, 0.0325072705745697, -0.053460508584976196, -0.014429098926484585, 0.039371270686388016, 0.02216084860265255, 0.01753970980644226, 0.03901059925556183, 0.00533848674967885, -0.03359692171216011, 0.05370952934026718, -0.04163926839828491, -0.0470522977411747, 0.0188149381428957, -0.022638214752078056, -0.018590522930026054, 0.013807384297251701, 0.0011207663919776678, 0.03707128390669823, -0.11434775590896606, 0.03692750632762909, 0.05570210516452789, 0.01429258193820715, 0.028005268424749374, -0.05581441894173622, 0.06873339414596558, -0.01708086207509041, 0.05033847317099571, 0.045997679233551025, -0.009064671583473682, 0.02831646241247654, -0.0754011794924736, -0.03974785655736923, 0.025340601801872253, -0.001423622015863657, 0.03690798208117485, 0.014626666903495789, -0.012419534847140312, -0.019043851643800735, 0.030288804322481155, 0.01834404282271862, 0.02311239019036293, -0.034652117639780045, 0.0024197574239224195, 0.059800077229738235, 0.00045599188888445497, 0.06548478454351425, -0.018267180770635605, 0.04086969047784805, -0.04895542934536934, -0.3304947316646576, 0.006728538312017918, -0.0110640162602067, -0.028767479583621025, -0.03638773784041405, -0.02484002336859703, 0.013707608915865421, -0.03481480851769447, 0.07064148783683777, 0.010682215914130211, 0.0435052253305912, 0.0679481104016304, 0.018660778179764748, -0.04766044393181801, 0.027642928063869476, -0.021628480404615402, 0.04845377802848816, -0.001046566292643547, -0.014025558717548847, -0.03000771440565586, -0.01778610609471798, 0.018259579315781593, -0.03508725389838219, -0.08634727448225021, 0.04815733805298805, 0.037510912865400314, 0.06400343775749207, 0.04065418243408203, -0.022263506427407265, -0.06055065616965294, 0.02975490875542164, 0.01066263485699892, 0.04090745374560356, -0.11955887824296951, 0.01516890712082386, 0.02922329492866993, 0.046443454921245575, -0.0265754796564579, 0.008239023387432098, 0.03066891059279442, 0.00396446418017149, 0.019331766292452812, -0.0006657814956270158, -0.11225384473800659, -0.04750657454133034, -0.057980332523584366, -0.019024742767214775, -0.08096952736377716, -0.019371341913938522, -0.021077856421470642, 0.005962889175862074, -0.0014223080361261964, 0.03592289611697197, 0.007230712100863457, 0.00795462541282177, -0.0156745333224535, -0.0181796383112669, 0.007638469338417053, 0.01944405399262905, 0.03691546991467476, -0.00218405039049685, -0.038922328501939774, -0.027342677116394043, 0.03261926770210266, -0.011212572455406189, 0.019509432837367058, 0.020507430657744408, 0.003626967314630747, -0.006671955808997154, -0.14708828926086426, -0.03585341200232506, 0.044034700840711594, 0.0030476560350507498, 0.009676276706159115, -0.02058241330087185, -0.08300846070051193, -0.001045658951625228, -0.03056381829082966, 0.03300406038761139, -0.0062597026117146015, -0.056589893996715546, -0.056873124092817307, 0.026140592992305756, 0.032783474773168564, -0.01670157164335251, 0.023767543956637383, 0.05354703217744827, 0.0445016548037529, -0.00317833642475307, 0.03951619192957878, -0.034108348190784454, -0.005770612508058548, -0.04309752210974693, -0.022010816261172295, 0.039306964725255966, 0.006940542254596949, -0.22832641005516052, -0.04170854762196541, -0.0013016152661293745, -0.054145995527505875, 0.0006083007901906967, -0.013134476728737354, 0.06646665930747986, -0.06619256734848022, 0.000748049933463335, 0.012043740600347519, 0.0030860689003020525, -0.008868318051099777, 0.059267956763505936, -0.02881576307117939, 0.060163263231515884, 0.06984936445951462, 0.031175877898931503, -0.0017375423340126872, 0.0425826795399189, -0.04868241026997566, 0.0017051775939762592, 0.023723656311631203, 0.15045872330665588, -0.0354410745203495, 0.015894988551735878, 0.04738953337073326, -0.054146040230989456, -0.021877730265259743, 0.01790519803762436, 0.0025913133285939693, -0.04666030779480934, 0.005668713711202145, 0.054717421531677246, 0.007728177588433027, -0.011131559498608112, 0.015936074778437614, -0.03576522320508957, 0.00427484093233943, 0.0051941112615168095, -0.004913663957268, 0.03052656166255474, 0.014054232276976109, 0.0164832454174757, 0.03368829935789108, 0.0455629825592041, -0.0427006259560585, 0.0014872908359393477, -0.0628671869635582, -0.0053012678399682045, 0.007279928773641586, -0.009662953205406666, -0.055379752069711685, 0.03392284736037254, -0.0525670200586319, 0.052112970501184464, 0.03971678018569946, -0.008077407255768776, -0.067570261657238, -0.05841720849275589, -0.030914416536688805, 0.04750857502222061, 0.03468552604317665, 0.016000673174858093, 0.0720420852303505, 0.03261450678110123], "3e40b9dc-8ae7-4942-8453-e13255a37580": [-0.02459508180618286, -0.0027271637227386236, -0.04204753786325455, -0.053665753453969955, 0.039147987961769104, -0.04690176621079445, -3.186641333741136e-05, -0.00432047713547945, -0.04345689341425896, -0.0003290200256742537, 0.0015637135365977883, -0.08338262140750885, 0.01198857557028532, 0.006539987865835428, 0.045869678258895874, 0.03440142795443535, 0.008074712939560413, -0.010711110197007656, 0.023898787796497345, 0.018149657174944878, 0.04099419340491295, 0.003940315451472998, -0.016150139272212982, -0.06055734306573868, -0.02779461443424225, 0.05771622806787491, -0.0037091269623488188, -0.05479688197374344, -0.028767501935362816, -0.11372333019971848, -0.024679793044924736, -0.01852261833846569, 0.05908171460032463, 0.005948175676167011, 0.0264264103025198, 0.02789524383842945, 0.042078133672475815, -0.0034731081686913967, -0.06094304099678993, 0.026185810565948486, -0.014838348142802715, 0.0056037441827356815, -0.003912467509508133, 0.006370039191097021, 0.0698765367269516, -0.041123829782009125, -0.014210651628673077, -0.011969460174441338, -0.11081996560096741, -0.01138040516525507, -0.020149879157543182, -0.01371605135500431, -0.0418267697095871, 0.031664203852415085, 0.03840912878513336, 0.05192067474126816, 0.026579713448882103, 0.016409436240792274, 0.019786007702350616, -0.014399510808289051, 0.06136137992143631, 0.0016969419084489346, -0.11764462292194366, 0.05913344770669937, 0.04890760779380798, 0.07447952032089233, -0.07592634111642838, -0.05833319202065468, 0.049036841839551926, 0.019429294392466545, 0.026029523462057114, -0.02315087616443634, 0.027199124917387962, 0.04254736751317978, 0.03591358661651611, 0.047862689942121506, 0.017961900681257248, 0.011579212732613087, -0.024480240419507027, -0.05744631215929985, 0.004154340364038944, -0.007435423322021961, -0.040457624942064285, 0.040373802185058594, 0.010533218272030354, 0.009646782651543617, 0.03825629502534866, 0.05747321620583534, -0.044859569519758224, 0.06938368827104568, -0.0022208343725651503, -0.0013996110064908862, 0.10379375517368317, -0.011933967471122742, -0.011584428139030933, -0.0075948843732476234, 0.06313180178403854, 0.03327736258506775, -0.04979622736573219, 0.4250638782978058, -0.05872898921370506, 0.030495446175336838, 0.012491602450609207, -0.02030928246676922, 0.009320336394011974, -0.008324481546878815, 0.024629442021250725, -0.020826727151870728, 0.02610703371465206, -0.02824055403470993, -0.00332009163685143, 0.0038981821853667498, 0.0744379535317421, -0.0020669500809162855, 0.03194597736001015, 0.023657619953155518, -0.023850560188293457, 0.055471520870923996, -0.0004585599235724658, 0.04806596040725708, -0.0021918027196079493, 0.060781512409448624, 0.06818933039903641, -0.017204653471708298, 0.00235997186973691, 0.04493964836001396, 0.039912234991788864, 0.03846575319766998, 0.02341482602059841, 0.08625780045986176, 0.03491724282503128, 0.08091996610164642, -0.0298148225992918, 0.031154660508036613, -0.0017435571644455194, -0.008719682693481445, -0.0656084269285202, -0.016170674934983253, -0.014106372371315956, 0.11972766369581223, -0.018198035657405853, 0.06003521755337715, 0.03017125278711319, -0.10440700501203537, -0.043821658939123154, 0.011050579138100147, 0.029309341683983803, 0.012506580911576748, -0.02963162027299404, -0.012882002629339695, 0.005431013181805611, 0.07571049779653549, 0.02122918702661991, 0.0012680541258305311, -0.00017842717352323234, 0.0002888212911784649, 0.017351096495985985, -0.03245280683040619, -0.03522598370909691, -0.01391208078712225, -0.05275356024503708, 0.012058385647833347, 0.010508378967642784, 0.017179198563098907, 0.03057328797876835, -0.1985536515712738, 0.04106253758072853, -0.000972098030615598, 0.0056717065162956715, -0.04114006459712982, 0.029997363686561584, 0.030518123880028725, 0.0005079794791527092, -0.0867132619023323, 0.04323359206318855, -0.03810490667819977, -0.0252385176718235, -0.0034444970078766346, -0.002399241318926215, 0.0047459849156439304, 0.023413123562932014, 0.0008658455917611718, -0.0399860218167305, 0.004127450753003359, -0.0202129315584898, -0.037093423306941986, 0.0011048302985727787, -0.03366786614060402, 0.00410414207726717, 0.025079363957047462, -0.04955916479229927, -0.026674939319491386, -0.029941432178020477, 0.06196104362607002, -0.005754987709224224, -0.012442627921700478, 0.013490809127688408, -0.04324805364012718, 0.02122465707361698, -0.02913554385304451, 0.0578642338514328, 0.02215348742902279, -0.046844132244586945, -0.015238521620631218, -0.027660105377435684, -0.02473144605755806, -0.02573077194392681, -0.0061148726381361485, 0.047629933804273605, 0.013132111169397831, -0.009437594562768936, 0.03131081536412239, 0.025251945480704308, 0.0317230150103569, 0.0170176699757576, -0.04408138245344162, 0.026051511988043785, 0.020520225167274475, 0.036606527864933014, 0.05687052756547928, -0.04089706018567085, -0.018189534544944763, -0.0878048986196518, -0.29751816391944885, -0.03861520439386368, -0.01820439100265503, 0.04300788789987564, 0.01375926285982132, -0.013858392834663391, 0.018955878913402557, -0.025520499795675278, 0.05331750959157944, 0.06319965422153473, 0.10073326528072357, 0.03834696486592293, 0.032453298568725586, -0.03296496346592903, 0.007014884613454342, -0.01360876765102148, 0.001275549060665071, -0.040692560374736786, -0.01632518880069256, -0.03879856318235397, 0.021801317110657692, -0.02920234203338623, -0.002969310386106372, -0.1257217526435852, 0.005705258343368769, -0.011251880787312984, 0.09643805027008057, 0.04309836030006409, -0.018812768161296844, -0.054408181458711624, 0.005043653305619955, -0.006006771698594093, 0.01926831714808941, -0.12018879503011703, 0.0037672552280128, 0.02703336998820305, 0.06019825115799904, -0.015903225168585777, -0.04023586958646774, -0.0037090592086315155, -0.011600201018154621, -0.001960140187293291, -0.0029030637815594673, -0.08703784644603729, -0.029246823862195015, -0.005426168441772461, -0.044694725424051285, -0.06501496583223343, -0.020539648830890656, 0.02592363953590393, -0.007091593462973833, 0.05573863163590431, 0.027399791404604912, -0.013007656671106815, 0.009862367063760757, 0.013002891093492508, -0.02986104227602482, 0.01377869863063097, -0.04916178435087204, -0.003029577899724245, -0.025868628174066544, -0.04981478303670883, -0.02481328509747982, 0.04732359200716019, 0.005551372189074755, 0.01232007797807455, 0.011473712511360645, 0.03364542871713638, 0.018442075699567795, -0.05699446424841881, -0.0009020004654303193, 0.0944700837135315, -0.007151632569730282, 0.019515590742230415, 0.025953250005841255, -0.029873374849557877, -0.047453250735998154, -0.0036718021146953106, 0.016906974837183952, -0.002247367985546589, 0.0017183572053909302, -0.020516689866781235, 0.025646092370152473, 0.010244986042380333, -0.01492489967495203, 0.025775479152798653, 0.0616762600839138, -0.07383105903863907, 0.022650593891739845, 0.03990279138088226, 0.020007116720080376, -0.027538005262613297, -0.060655854642391205, -0.11146628111600876, 0.07253413647413254, -0.0018238578923046589, -0.24216897785663605, -0.05725044757127762, -0.004207031335681677, -0.024379421025514603, 0.0256356168538332, -0.014387154951691628, 0.06063530594110489, -0.028575662523508072, -0.002056764205917716, 0.004386635962873697, -0.04553389921784401, 0.04502780735492706, -0.004284072667360306, 0.01893712393939495, 0.05554435774683952, 0.017061656340956688, 0.011686012148857117, -0.006190766114741564, -0.0022329913917928934, 0.006693477276712656, 0.0653030127286911, -0.006394729018211365, 0.14944416284561157, -0.027011176571249962, 0.001682215603068471, 0.07649211585521698, -0.04392145201563835, 0.004398396238684654, 0.09030815213918686, -0.00901324674487114, -0.058990515768527985, -0.0027327467687427998, 0.053825657814741135, -0.024018101394176483, -0.006373172625899315, 0.02008768916130066, 0.040439702570438385, -0.007336467504501343, 0.009194009937345982, -0.07564068585634232, -0.0051545933820307255, -0.007716304622590542, 0.05438129976391792, 0.03217923268675804, 0.04263686016201973, -0.06775613874197006, -0.03516388684511185, -0.0970081090927124, -0.042143240571022034, 0.019693683832883835, -0.030054179951548576, -0.0488622710108757, -0.006975266616791487, -0.015622304752469063, -0.0048998454585671425, 0.06864845752716064, 0.018434006720781326, -0.03368890658020973, -0.050863299518823624, -0.0890837088227272, -0.010642820037901402, 0.006492000538855791, -0.005771419499069452, 0.006113579962402582, 0.03179433196783066]}, "text_id_to_ref_doc_id": {"949fb843-d2e1-4df7-858d-6ea740348615": "23e28b4b-62c3-4e17-b3a0-f830f4f1dca6", "eda5445f-43af-4348-a05b-a7c16f03cc4c": "915e49b4-52d4-4b83-8234-6eb520aa40b7", "3e40b9dc-8ae7-4942-8453-e13255a37580": "786dc0d9-dd19-4be2-8027-005b54d09842"}, "metadata_dict": {"949fb843-d2e1-4df7-858d-6ea740348615": {"_node_type": "TextNode", "document_id": "23e28b4b-62c3-4e17-b3a0-f830f4f1dca6", "doc_id": "23e28b4b-62c3-4e17-b3a0-f830f4f1dca6", "ref_doc_id": "23e28b4b-62c3-4e17-b3a0-f830f4f1dca6"}, "eda5445f-43af-4348-a05b-a7c16f03cc4c": {"_node_type": "TextNode", "document_id": "915e49b4-52d4-4b83-8234-6eb520aa40b7", "doc_id": "915e49b4-52d4-4b83-8234-6eb520aa40b7", "ref_doc_id": "915e49b4-52d4-4b83-8234-6eb520aa40b7"}, "3e40b9dc-8ae7-4942-8453-e13255a37580": {"_node_type": "TextNode", "document_id": "786dc0d9-dd19-4be2-8027-005b54d09842", "doc_id": "786dc0d9-dd19-4be2-8027-005b54d09842", "ref_doc_id": "786dc0d9-dd19-4be2-8027-005b54d09842"}}}
|
storage/docstore.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"docstore/metadata": {"23e28b4b-62c3-4e17-b3a0-f830f4f1dca6": {"doc_hash": "ec7cb315d1b308d0ae022c78acc2f9bc5a2e011b6b9216e06e304394efcda964"}, "915e49b4-52d4-4b83-8234-6eb520aa40b7": {"doc_hash": "462ec5c5c45da617a23c1ba05c2ea8fdfb12232e5b2277ad17b2aa54393e610a"}, "786dc0d9-dd19-4be2-8027-005b54d09842": {"doc_hash": "ed022f5a93cadb684fc4406cd0f8c89e891cd27ab480fe74ddc16de7b928c698"}, "949fb843-d2e1-4df7-858d-6ea740348615": {"doc_hash": "49d6eef6279612434cc13da66dd423d713b7a940effd8c8f8a04540c92301988", "ref_doc_id": "23e28b4b-62c3-4e17-b3a0-f830f4f1dca6"}, "eda5445f-43af-4348-a05b-a7c16f03cc4c": {"doc_hash": "a33cba242c9cfef420917121ecfbd3cebcdac0922422f6231f1d12d125e0429b", "ref_doc_id": "915e49b4-52d4-4b83-8234-6eb520aa40b7"}, "3e40b9dc-8ae7-4942-8453-e13255a37580": {"doc_hash": "3ccf436e9b52028f19deac56f16026e88aaac1182998185346b04b2e4354cd83", "ref_doc_id": "786dc0d9-dd19-4be2-8027-005b54d09842"}}, "docstore/data": {"949fb843-d2e1-4df7-858d-6ea740348615": {"__data__": {"id_": "949fb843-d2e1-4df7-858d-6ea740348615", "embedding": null, "metadata": {}, "excluded_embed_metadata_keys": [], "excluded_llm_metadata_keys": [], "relationships": {"1": {"node_id": "23e28b4b-62c3-4e17-b3a0-f830f4f1dca6", "node_type": "4", "metadata": {}, "hash": "ec7cb315d1b308d0ae022c78acc2f9bc5a2e011b6b9216e06e304394efcda964", "class_name": "RelatedNodeInfo"}}, "metadata_template": "{key}: {value}", "metadata_separator": "\n", "text": "# Sarah Chen\n\nEmail: sarah.chen@email.com\n\nLinkedIn: linkedin.com/in/sarahchen\n\nGitHub: github.com/sarahcodes\n\nPortfolio: sarahchen.dev\n\nLocation: San Francisco, CA\n\n# Professional Summary\n\nInnovative Full Stack Web Developer with 6+ years of experience crafting scalable web applications and microservices. Specialized in React, Node.js, and cloud architecture. Proven track record of leading technical teams and implementing CI/CD pipelines that reduced deployment time by 40%. Passionate about clean code, accessibility, and mentoring junior developers.\n\n# Professional Experience\n\n# Senior Full Stack Developer\n\nTechFlow Solutions | San Francisco, CA January 2022 - Present\n\n- Architected and implemented a microservices-based e-commerce platform serving 100K+ daily users\n- Led a team of 5 developers in rebuilding the company's flagship product using React and Node.js\n- Implemented GraphQL API gateway that reduced API response times by 60%\n- Established coding standards and review processes that improved code quality by 45%\n\n# Technical Skills\n\n# Frontend:\n\n- React.js, Redux, Next.js, TypeScript\n- Vue.js, Nuxt.js\n- HTML5, CSS3, SASS/SCSS\n- Jest, React Testing Library\n- WebPack, Babel\n\n# Backend:\n\n- Node.js, Express.js\n- Python, Django\n- GraphQL, REST APIs\n- PostgreSQL, MongoDB", "mimetype": "text/plain", "start_char_idx": 0, "end_char_idx": 1291, "metadata_seperator": "\n", "text_template": "{metadata_str}\n\n{content}", "class_name": "TextNode"}, "__type__": "1"}, "eda5445f-43af-4348-a05b-a7c16f03cc4c": {"__data__": {"id_": "eda5445f-43af-4348-a05b-a7c16f03cc4c", "embedding": null, "metadata": {}, "excluded_embed_metadata_keys": [], "excluded_llm_metadata_keys": [], "relationships": {"1": {"node_id": "915e49b4-52d4-4b83-8234-6eb520aa40b7", "node_type": "4", "metadata": {}, "hash": "462ec5c5c45da617a23c1ba05c2ea8fdfb12232e5b2277ad17b2aa54393e610a", "class_name": "RelatedNodeInfo"}}, "metadata_template": "{key}: {value}", "metadata_separator": "\n", "text": "# Full Stack Developer\n\nInnovateSoft | Oakland, CA March 2019 - December 2021\n\n- Mentored 3 junior developers who were promoted to mid-level positions\n- Developed and maintained 10+ customer-facing applications using Vue.js and Django\n- Implemented automated testing suite that increased code coverage from 65% to 95%\n- Optimized database queries resulting in 30% faster page load times\n- Collaborated with UX team to implement accessibility features (WCAG 2.1 compliance)\n- Created documentation that reduced onboarding time for new developers by 50%\n\n# Tools & Others:\n\n- Docker, Kubernetes\n- AWS (EC2, S3, Lambda)\n- Git, GitHub Actions\n- Jenkins, CircleCI\n- Agile/Scrum methodology\n- Performance optimization\n\n# Junior Web Developer\n\nStartupHub | San Jose, CA June 2017 - February 2019\n\n- Built responsive web applications using React.js and Express.js\n- Implemented user authentication system using JWT and OAuth2.0\n- Contributed to migration of legacy PHP applications to modern JavaScript stack\n- Developed RESTful APIs consumed by mobile and web applications\n\n# Education\n\nBachelor of Science in Computer Science\n\nUniversity of California, Berkeley 2013 - 2017\n\n- GPA: 3.8/4.0\n- Minor in User Experience Design\n- President of Women in Tech Society", "mimetype": "text/plain", "start_char_idx": 0, "end_char_idx": 1254, "metadata_seperator": "\n", "text_template": "{metadata_str}\n\n{content}", "class_name": "TextNode"}, "__type__": "1"}, "3e40b9dc-8ae7-4942-8453-e13255a37580": {"__data__": {"id_": "3e40b9dc-8ae7-4942-8453-e13255a37580", "embedding": null, "metadata": {}, "excluded_embed_metadata_keys": [], "excluded_llm_metadata_keys": [], "relationships": {"1": {"node_id": "786dc0d9-dd19-4be2-8027-005b54d09842", "node_type": "4", "metadata": {}, "hash": "ed022f5a93cadb684fc4406cd0f8c89e891cd27ab480fe74ddc16de7b928c698", "class_name": "RelatedNodeInfo"}}, "metadata_template": "{key}: {value}", "metadata_separator": "\n", "text": "# Projects\n\n# EcoTrack | GitHub\n\n- Built full-stack application for tracking carbon footprint using React, Node.js, and MongoDB\n- Implemented machine learning algorithm for providing personalized sustainability recommendations\n- Featured in TechCrunch's \"Top 10 Environmental Impact Apps of 2023\"\n\n# ChatFlow | Demo\n\n- Developed real-time chat application using WebSocket protocol and React\n- Implemented end-to-end encryption and message persistence\n- Serves 5000+ monthly active users\n\n# Certifications\n\n- AWS Certified Solutions Architect (2023)\n- Google Cloud Professional Developer (2022)\n- MongoDB Certified Developer (2021)\n\n# Languages\n\n- English (Native)\n- Mandarin Chinese (Fluent)\n- Spanish (Intermediate)\n\n# Interests\n\n- Open source contribution\n- Tech blogging (15K+ Medium followers)\n- Hackathon mentoring\n- Rock climbing", "mimetype": "text/plain", "start_char_idx": 0, "end_char_idx": 835, "metadata_seperator": "\n", "text_template": "{metadata_str}\n\n{content}", "class_name": "TextNode"}, "__type__": "1"}}, "docstore/ref_doc_info": {"23e28b4b-62c3-4e17-b3a0-f830f4f1dca6": {"node_ids": ["949fb843-d2e1-4df7-858d-6ea740348615"], "metadata": {}}, "915e49b4-52d4-4b83-8234-6eb520aa40b7": {"node_ids": ["eda5445f-43af-4348-a05b-a7c16f03cc4c"], "metadata": {}}, "786dc0d9-dd19-4be2-8027-005b54d09842": {"node_ids": ["3e40b9dc-8ae7-4942-8453-e13255a37580"], "metadata": {}}}}
|
storage/graph_store.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"graph_dict": {}}
|
storage/image__vector_store.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"embedding_dict": {}, "text_id_to_ref_doc_id": {}, "metadata_dict": {}}
|
storage/index_store.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"index_store/data": {"53cc9987-aaba-4c79-8378-e72adbdc654f": {"__type__": "vector_store", "__data__": "{\"index_id\": \"53cc9987-aaba-4c79-8378-e72adbdc654f\", \"summary\": null, \"nodes_dict\": {\"949fb843-d2e1-4df7-858d-6ea740348615\": \"949fb843-d2e1-4df7-858d-6ea740348615\", \"eda5445f-43af-4348-a05b-a7c16f03cc4c\": \"eda5445f-43af-4348-a05b-a7c16f03cc4c\", \"3e40b9dc-8ae7-4942-8453-e13255a37580\": \"3e40b9dc-8ae7-4942-8453-e13255a37580\"}, \"doc_id_dict\": {}, \"embeddings_dict\": {}}"}}}
|
workflows/RAG-EventDriven.html
CHANGED
|
@@ -88,8 +88,8 @@
|
|
| 88 |
|
| 89 |
|
| 90 |
// parsing and collecting nodes and edges from the python
|
| 91 |
-
nodes = new vis.DataSet([{"color": "#FFA07A", "id": "StopEvent", "label": "StopEvent", "shape": "ellipse"}, {"color": "#ADD8E6", "id": "_done", "label": "_done", "shape": "box"}, {"color": "#ADD8E6", "id": "
|
| 92 |
-
edges = new vis.DataSet([{"arrows": "to", "from": "StopEvent", "to": "_done"}, {"arrows": "to", "from": "
|
| 93 |
|
| 94 |
nodeColors = {};
|
| 95 |
allNodes = nodes.get({ returnType: "Object" });
|
|
|
|
| 88 |
|
| 89 |
|
| 90 |
// parsing and collecting nodes and edges from the python
|
| 91 |
+
nodes = new vis.DataSet([{"color": "#FFA07A", "id": "StopEvent", "label": "StopEvent", "shape": "ellipse"}, {"color": "#ADD8E6", "id": "_done", "label": "_done", "shape": "box"}, {"color": "#ADD8E6", "id": "step_one", "label": "step_one", "shape": "box"}, {"color": "#E27AFF", "id": "StartEvent", "label": "StartEvent", "shape": "ellipse"}, {"color": "#ADD8E6", "id": "step_three", "label": "step_three", "shape": "box"}, {"color": "#90EE90", "id": "SecondEvent", "label": "SecondEvent", "shape": "ellipse"}, {"color": "#ADD8E6", "id": "step_two", "label": "step_two", "shape": "box"}, {"color": "#90EE90", "id": "FirstEvent", "label": "FirstEvent", "shape": "ellipse"}]);
|
| 92 |
+
edges = new vis.DataSet([{"arrows": "to", "from": "StopEvent", "to": "_done"}, {"arrows": "to", "from": "step_one", "to": "FirstEvent"}, {"arrows": "to", "from": "StartEvent", "to": "step_one"}, {"arrows": "to", "from": "step_three", "to": "StopEvent"}, {"arrows": "to", "from": "SecondEvent", "to": "step_three"}, {"arrows": "to", "from": "step_two", "to": "SecondEvent"}, {"arrows": "to", "from": "FirstEvent", "to": "step_two"}]);
|
| 93 |
|
| 94 |
nodeColors = {};
|
| 95 |
allNodes = nodes.get({ returnType: "Object" });
|