Spaces:
Running
Running
alvinhenrick
commited on
Commit
•
a122b37
1
Parent(s):
63f14b9
make streaming work end to end
Browse files- app.py +19 -7
- poetry.lock +49 -67
- pyproject.toml +1 -0
- tests/rag/test_wf.py +34 -0
app.py
CHANGED
@@ -1,6 +1,7 @@
|
|
1 |
from pathlib import Path
|
2 |
import gradio as gr
|
3 |
from dotenv import load_dotenv
|
|
|
4 |
from medirag.cache.local import SemanticCaching
|
5 |
from medirag.index.local import DailyMedIndexer
|
6 |
from medirag.rag.qa import RAG, DailyMedRetrieve
|
@@ -43,14 +44,25 @@ async def ask_med_question(query, enable_stream):
|
|
43 |
if enable_stream:
|
44 |
# Stream response using RAGWorkflow
|
45 |
result = await rag_workflow.run(query=query)
|
46 |
-
accumulated_response = ""
|
47 |
-
|
48 |
-
async for chunk in result.async_response_gen():
|
49 |
-
accumulated_response += chunk
|
50 |
-
yield accumulated_response # Accumulate and yield the updated response
|
51 |
|
52 |
-
#
|
53 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
54 |
else:
|
55 |
# Use RAG without streaming
|
56 |
response = rag(query).answer
|
|
|
1 |
from pathlib import Path
|
2 |
import gradio as gr
|
3 |
from dotenv import load_dotenv
|
4 |
+
|
5 |
from medirag.cache.local import SemanticCaching
|
6 |
from medirag.index.local import DailyMedIndexer
|
7 |
from medirag.rag.qa import RAG, DailyMedRetrieve
|
|
|
44 |
if enable_stream:
|
45 |
# Stream response using RAGWorkflow
|
46 |
result = await rag_workflow.run(query=query)
|
|
|
|
|
|
|
|
|
|
|
47 |
|
48 |
+
# Handle streaming response
|
49 |
+
if hasattr(result, 'async_response_gen'):
|
50 |
+
accumulated_response = ""
|
51 |
+
|
52 |
+
async for chunk in result.async_response_gen():
|
53 |
+
accumulated_response += chunk
|
54 |
+
yield accumulated_response # Accumulate and yield the updated response
|
55 |
+
|
56 |
+
# Save the accumulated response to the cache after streaming is complete
|
57 |
+
sm.save(query, accumulated_response)
|
58 |
+
elif isinstance(result, str):
|
59 |
+
# Handle non-streaming string response
|
60 |
+
yield result
|
61 |
+
sm.save(query, result)
|
62 |
+
else:
|
63 |
+
# Handle unexpected response types
|
64 |
+
print("Unexpected response type:", result)
|
65 |
+
yield "An unexpected error occurred."
|
66 |
else:
|
67 |
# Use RAG without streaming
|
68 |
response = rag(query).answer
|
poetry.lock
CHANGED
@@ -476,66 +476,29 @@ development = ["black", "flake8", "mypy", "pytest", "types-colorama"]
|
|
476 |
|
477 |
[[package]]
|
478 |
name = "contourpy"
|
479 |
-
version = "1.
|
480 |
description = "Python library for calculating contours of 2D quadrilateral grids"
|
481 |
optional = false
|
482 |
python-versions = ">=3.9"
|
483 |
files = [
|
484 |
-
{file = "contourpy-1.
|
485 |
-
{file = "contourpy-1.
|
486 |
-
{file = "contourpy-1.
|
487 |
-
{file = "contourpy-1.
|
488 |
-
{file = "contourpy-1.
|
489 |
-
{file = "contourpy-1.
|
490 |
-
{file = "contourpy-1.
|
491 |
-
{file = "contourpy-1.2.1-cp310-cp310-musllinux_1_1_x86_64.whl", hash = "sha256:457499c79fa84593f22454bbd27670227874cd2ff5d6c84e60575c8b50a69619"},
|
492 |
-
{file = "contourpy-1.2.1-cp310-cp310-win32.whl", hash = "sha256:ac58bdee53cbeba2ecad824fa8159493f0bf3b8ea4e93feb06c9a465d6c87da8"},
|
493 |
-
{file = "contourpy-1.2.1-cp310-cp310-win_amd64.whl", hash = "sha256:9cffe0f850e89d7c0012a1fb8730f75edd4320a0a731ed0c183904fe6ecfc3a9"},
|
494 |
-
{file = "contourpy-1.2.1-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:6022cecf8f44e36af10bd9118ca71f371078b4c168b6e0fab43d4a889985dbb5"},
|
495 |
-
{file = "contourpy-1.2.1-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:ef5adb9a3b1d0c645ff694f9bca7702ec2c70f4d734f9922ea34de02294fdf72"},
|
496 |
-
{file = "contourpy-1.2.1-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:6150ffa5c767bc6332df27157d95442c379b7dce3a38dff89c0f39b63275696f"},
|
497 |
-
{file = "contourpy-1.2.1-cp311-cp311-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:4c863140fafc615c14a4bf4efd0f4425c02230eb8ef02784c9a156461e62c965"},
|
498 |
-
{file = "contourpy-1.2.1-cp311-cp311-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:00e5388f71c1a0610e6fe56b5c44ab7ba14165cdd6d695429c5cd94021e390b2"},
|
499 |
-
{file = "contourpy-1.2.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:d4492d82b3bc7fbb7e3610747b159869468079fe149ec5c4d771fa1f614a14df"},
|
500 |
-
{file = "contourpy-1.2.1-cp311-cp311-musllinux_1_1_aarch64.whl", hash = "sha256:49e70d111fee47284d9dd867c9bb9a7058a3c617274900780c43e38d90fe1205"},
|
501 |
-
{file = "contourpy-1.2.1-cp311-cp311-musllinux_1_1_x86_64.whl", hash = "sha256:b59c0ffceff8d4d3996a45f2bb6f4c207f94684a96bf3d9728dbb77428dd8cb8"},
|
502 |
-
{file = "contourpy-1.2.1-cp311-cp311-win32.whl", hash = "sha256:7b4182299f251060996af5249c286bae9361fa8c6a9cda5efc29fe8bfd6062ec"},
|
503 |
-
{file = "contourpy-1.2.1-cp311-cp311-win_amd64.whl", hash = "sha256:2855c8b0b55958265e8b5888d6a615ba02883b225f2227461aa9127c578a4922"},
|
504 |
-
{file = "contourpy-1.2.1-cp312-cp312-macosx_10_9_x86_64.whl", hash = "sha256:62828cada4a2b850dbef89c81f5a33741898b305db244904de418cc957ff05dc"},
|
505 |
-
{file = "contourpy-1.2.1-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:309be79c0a354afff9ff7da4aaed7c3257e77edf6c1b448a779329431ee79d7e"},
|
506 |
-
{file = "contourpy-1.2.1-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:2e785e0f2ef0d567099b9ff92cbfb958d71c2d5b9259981cd9bee81bd194c9a4"},
|
507 |
-
{file = "contourpy-1.2.1-cp312-cp312-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:1cac0a8f71a041aa587410424ad46dfa6a11f6149ceb219ce7dd48f6b02b87a7"},
|
508 |
-
{file = "contourpy-1.2.1-cp312-cp312-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:af3f4485884750dddd9c25cb7e3915d83c2db92488b38ccb77dd594eac84c4a0"},
|
509 |
-
{file = "contourpy-1.2.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:9ce6889abac9a42afd07a562c2d6d4b2b7134f83f18571d859b25624a331c90b"},
|
510 |
-
{file = "contourpy-1.2.1-cp312-cp312-musllinux_1_1_aarch64.whl", hash = "sha256:a1eea9aecf761c661d096d39ed9026574de8adb2ae1c5bd7b33558af884fb2ce"},
|
511 |
-
{file = "contourpy-1.2.1-cp312-cp312-musllinux_1_1_x86_64.whl", hash = "sha256:187fa1d4c6acc06adb0fae5544c59898ad781409e61a926ac7e84b8f276dcef4"},
|
512 |
-
{file = "contourpy-1.2.1-cp312-cp312-win32.whl", hash = "sha256:c2528d60e398c7c4c799d56f907664673a807635b857df18f7ae64d3e6ce2d9f"},
|
513 |
-
{file = "contourpy-1.2.1-cp312-cp312-win_amd64.whl", hash = "sha256:1a07fc092a4088ee952ddae19a2b2a85757b923217b7eed584fdf25f53a6e7ce"},
|
514 |
-
{file = "contourpy-1.2.1-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:bb6834cbd983b19f06908b45bfc2dad6ac9479ae04abe923a275b5f48f1a186b"},
|
515 |
-
{file = "contourpy-1.2.1-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:1d59e739ab0e3520e62a26c60707cc3ab0365d2f8fecea74bfe4de72dc56388f"},
|
516 |
-
{file = "contourpy-1.2.1-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:bd3db01f59fdcbce5b22afad19e390260d6d0222f35a1023d9adc5690a889364"},
|
517 |
-
{file = "contourpy-1.2.1-cp39-cp39-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:a12a813949e5066148712a0626895c26b2578874e4cc63160bb007e6df3436fe"},
|
518 |
-
{file = "contourpy-1.2.1-cp39-cp39-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:fe0ccca550bb8e5abc22f530ec0466136379c01321fd94f30a22231e8a48d985"},
|
519 |
-
{file = "contourpy-1.2.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:e1d59258c3c67c865435d8fbeb35f8c59b8bef3d6f46c1f29f6123556af28445"},
|
520 |
-
{file = "contourpy-1.2.1-cp39-cp39-musllinux_1_1_aarch64.whl", hash = "sha256:f32c38afb74bd98ce26de7cc74a67b40afb7b05aae7b42924ea990d51e4dac02"},
|
521 |
-
{file = "contourpy-1.2.1-cp39-cp39-musllinux_1_1_x86_64.whl", hash = "sha256:d31a63bc6e6d87f77d71e1abbd7387ab817a66733734883d1fc0021ed9bfa083"},
|
522 |
-
{file = "contourpy-1.2.1-cp39-cp39-win32.whl", hash = "sha256:ddcb8581510311e13421b1f544403c16e901c4e8f09083c881fab2be80ee31ba"},
|
523 |
-
{file = "contourpy-1.2.1-cp39-cp39-win_amd64.whl", hash = "sha256:10a37ae557aabf2509c79715cd20b62e4c7c28b8cd62dd7d99e5ed3ce28c3fd9"},
|
524 |
-
{file = "contourpy-1.2.1-pp39-pypy39_pp73-macosx_10_9_x86_64.whl", hash = "sha256:a31f94983fecbac95e58388210427d68cd30fe8a36927980fab9c20062645609"},
|
525 |
-
{file = "contourpy-1.2.1-pp39-pypy39_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:ef2b055471c0eb466033760a521efb9d8a32b99ab907fc8358481a1dd29e3bd3"},
|
526 |
-
{file = "contourpy-1.2.1-pp39-pypy39_pp73-win_amd64.whl", hash = "sha256:b33d2bc4f69caedcd0a275329eb2198f560b325605810895627be5d4b876bf7f"},
|
527 |
-
{file = "contourpy-1.2.1.tar.gz", hash = "sha256:4d8908b3bee1c889e547867ca4cdc54e5ab6be6d3e078556814a22457f49423c"},
|
528 |
]
|
529 |
|
530 |
[package.dependencies]
|
531 |
-
numpy = ">=1.
|
532 |
|
533 |
[package.extras]
|
534 |
bokeh = ["bokeh", "selenium"]
|
535 |
docs = ["furo", "sphinx (>=7.2)", "sphinx-copybutton"]
|
536 |
-
mypy = ["contourpy[bokeh,docs]", "docutils-stubs", "mypy (==1.
|
537 |
test = ["Pillow", "contourpy[test-no-images]", "matplotlib"]
|
538 |
-
test-no-images = ["pytest", "pytest-cov", "pytest-xdist", "wurlitzer"]
|
539 |
|
540 |
[[package]]
|
541 |
name = "coverage"
|
@@ -1288,13 +1251,13 @@ trio = ["trio (>=0.22.0,<0.26.0)"]
|
|
1288 |
|
1289 |
[[package]]
|
1290 |
name = "httpx"
|
1291 |
-
version = "0.27.
|
1292 |
description = "The next generation HTTP client."
|
1293 |
optional = false
|
1294 |
python-versions = ">=3.8"
|
1295 |
files = [
|
1296 |
-
{file = "httpx-0.27.
|
1297 |
-
{file = "httpx-0.27.
|
1298 |
]
|
1299 |
|
1300 |
[package.dependencies]
|
@@ -1309,6 +1272,7 @@ brotli = ["brotli", "brotlicffi"]
|
|
1309 |
cli = ["click (==8.*)", "pygments (==2.*)", "rich (>=10,<14)"]
|
1310 |
http2 = ["h2 (>=3,<5)"]
|
1311 |
socks = ["socksio (==1.*)"]
|
|
|
1312 |
|
1313 |
[[package]]
|
1314 |
name = "huggingface-hub"
|
@@ -1776,13 +1740,13 @@ langchain-core = ">=0.2.10,<0.3.0"
|
|
1776 |
|
1777 |
[[package]]
|
1778 |
name = "langsmith"
|
1779 |
-
version = "0.1.
|
1780 |
description = "Client library to connect to the LangSmith LLM Tracing and Evaluation Platform."
|
1781 |
optional = false
|
1782 |
python-versions = "<4.0,>=3.8.1"
|
1783 |
files = [
|
1784 |
-
{file = "langsmith-0.1.
|
1785 |
-
{file = "langsmith-0.1.
|
1786 |
]
|
1787 |
|
1788 |
[package.dependencies]
|
@@ -2300,19 +2264,19 @@ files = [
|
|
2300 |
|
2301 |
[[package]]
|
2302 |
name = "minijinja"
|
2303 |
-
version = "2.0
|
2304 |
description = "An experimental Python binding of the Rust MiniJinja template engine."
|
2305 |
optional = false
|
2306 |
python-versions = ">=3.8"
|
2307 |
files = [
|
2308 |
-
{file = "minijinja-2.0
|
2309 |
-
{file = "minijinja-2.0
|
2310 |
-
{file = "minijinja-2.0
|
2311 |
-
{file = "minijinja-2.0
|
2312 |
-
{file = "minijinja-2.0
|
2313 |
-
{file = "minijinja-2.0
|
2314 |
-
{file = "minijinja-2.0
|
2315 |
-
{file = "minijinja-2.0.
|
2316 |
]
|
2317 |
|
2318 |
[[package]]
|
@@ -3464,6 +3428,24 @@ tomli = {version = ">=1", markers = "python_version < \"3.11\""}
|
|
3464 |
[package.extras]
|
3465 |
dev = ["argcomplete", "attrs (>=19.2)", "hypothesis (>=3.56)", "mock", "pygments (>=2.7.2)", "requests", "setuptools", "xmlschema"]
|
3466 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3467 |
[[package]]
|
3468 |
name = "pytest-cov"
|
3469 |
version = "5.0.0"
|
@@ -3741,13 +3723,13 @@ use-chardet-on-py3 = ["chardet (>=3.0.2,<6)"]
|
|
3741 |
|
3742 |
[[package]]
|
3743 |
name = "rich"
|
3744 |
-
version = "13.
|
3745 |
description = "Render rich text, tables, progress bars, syntax highlighting, markdown and more to the terminal"
|
3746 |
optional = false
|
3747 |
python-versions = ">=3.7.0"
|
3748 |
files = [
|
3749 |
-
{file = "rich-13.
|
3750 |
-
{file = "rich-13.
|
3751 |
]
|
3752 |
|
3753 |
[package.dependencies]
|
@@ -5278,4 +5260,4 @@ multidict = ">=4.0"
|
|
5278 |
[metadata]
|
5279 |
lock-version = "2.0"
|
5280 |
python-versions = ">=3.10,<3.13"
|
5281 |
-
content-hash = "
|
|
|
476 |
|
477 |
[[package]]
|
478 |
name = "contourpy"
|
479 |
+
version = "1.3.0"
|
480 |
description = "Python library for calculating contours of 2D quadrilateral grids"
|
481 |
optional = false
|
482 |
python-versions = ">=3.9"
|
483 |
files = [
|
484 |
+
{file = "contourpy-1.3.0-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:880ea32e5c774634f9fcd46504bf9f080a41ad855f4fef54f5380f5133d343c7"},
|
485 |
+
{file = "contourpy-1.3.0-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:76c905ef940a4474a6289c71d53122a4f77766eef23c03cd57016ce19d0f7b42"},
|
486 |
+
{file = "contourpy-1.3.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:92f8557cbb07415a4d6fa191f20fd9d2d9eb9c0b61d1b2f52a8926e43c6e9af7"},
|
487 |
+
{file = "contourpy-1.3.0-cp310-cp310-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:36f965570cff02b874773c49bfe85562b47030805d7d8360748f3eca570f4cab"},
|
488 |
+
{file = "contourpy-1.3.0-cp310-cp310-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:cacd81e2d4b6f89c9f8a5b69b86490152ff39afc58a95af002a398273e5ce589"},
|
489 |
+
{file = "contourpy-1.3.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:69375194457ad0fad3a839b9e29aa0b0ed53bb54db1bfb6c3ae43d111c31ce41"},
|
490 |
+
{file = "contourpy-1.3.0-cp310-cp310-musllinux_1_2_aarch64.whl", hash = "sha256:7a52040312b1a858b5e31ef28c2e865376a386c60c0e248370bbea2d3f3b760d"},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
491 |
]
|
492 |
|
493 |
[package.dependencies]
|
494 |
+
numpy = ">=1.23"
|
495 |
|
496 |
[package.extras]
|
497 |
bokeh = ["bokeh", "selenium"]
|
498 |
docs = ["furo", "sphinx (>=7.2)", "sphinx-copybutton"]
|
499 |
+
mypy = ["contourpy[bokeh,docs]", "docutils-stubs", "mypy (==1.11.1)", "types-Pillow"]
|
500 |
test = ["Pillow", "contourpy[test-no-images]", "matplotlib"]
|
501 |
+
test-no-images = ["pytest", "pytest-cov", "pytest-rerunfailures", "pytest-xdist", "wurlitzer"]
|
502 |
|
503 |
[[package]]
|
504 |
name = "coverage"
|
|
|
1251 |
|
1252 |
[[package]]
|
1253 |
name = "httpx"
|
1254 |
+
version = "0.27.2"
|
1255 |
description = "The next generation HTTP client."
|
1256 |
optional = false
|
1257 |
python-versions = ">=3.8"
|
1258 |
files = [
|
1259 |
+
{file = "httpx-0.27.2-py3-none-any.whl", hash = "sha256:7bb2708e112d8fdd7829cd4243970f0c223274051cb35ee80c03301ee29a3df0"},
|
1260 |
+
{file = "httpx-0.27.2.tar.gz", hash = "sha256:f7c2be1d2f3c3c3160d441802406b206c2b76f5947b11115e6df10c6c65e66c2"},
|
1261 |
]
|
1262 |
|
1263 |
[package.dependencies]
|
|
|
1272 |
cli = ["click (==8.*)", "pygments (==2.*)", "rich (>=10,<14)"]
|
1273 |
http2 = ["h2 (>=3,<5)"]
|
1274 |
socks = ["socksio (==1.*)"]
|
1275 |
+
zstd = ["zstandard (>=0.18.0)"]
|
1276 |
|
1277 |
[[package]]
|
1278 |
name = "huggingface-hub"
|
|
|
1740 |
|
1741 |
[[package]]
|
1742 |
name = "langsmith"
|
1743 |
+
version = "0.1.105"
|
1744 |
description = "Client library to connect to the LangSmith LLM Tracing and Evaluation Platform."
|
1745 |
optional = false
|
1746 |
python-versions = "<4.0,>=3.8.1"
|
1747 |
files = [
|
1748 |
+
{file = "langsmith-0.1.105-py3-none-any.whl", hash = "sha256:a0098d0bc60ee79792109b0c1fef8252e21fd2dc424f4d902b8d9eb75160438b"},
|
1749 |
+
{file = "langsmith-0.1.105.tar.gz", hash = "sha256:a8717ef90f3f740c202aa6878da89d4581ff28998336b48b831a92b855c460c3"},
|
1750 |
]
|
1751 |
|
1752 |
[package.dependencies]
|
|
|
2264 |
|
2265 |
[[package]]
|
2266 |
name = "minijinja"
|
2267 |
+
version = "2.2.0"
|
2268 |
description = "An experimental Python binding of the Rust MiniJinja template engine."
|
2269 |
optional = false
|
2270 |
python-versions = ">=3.8"
|
2271 |
files = [
|
2272 |
+
{file = "minijinja-2.2.0-cp38-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl", hash = "sha256:e4154fcf72e81be01c2733b770e6cb3e584851cb2fa73c58e347b04967d3d7c0"},
|
2273 |
+
{file = "minijinja-2.2.0-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:4b05e0070c08b550fa9a09ff9c051f47424674332dd56cc54b997dd602887907"},
|
2274 |
+
{file = "minijinja-2.2.0-cp38-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:360ea4a93fdf1fe327f3e70eed20ecb29f324ca28fae177de0605dcc29869300"},
|
2275 |
+
{file = "minijinja-2.2.0-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:c9cad5ccb021ef25b6a271158f4d6636474edb08cd1dd49355aac6b68a48aebb"},
|
2276 |
+
{file = "minijinja-2.2.0-cp38-abi3-manylinux_2_5_i686.manylinux1_i686.whl", hash = "sha256:7a85c67c519b413fc4892854782927e1244a24cbbb3a3cb0ac5e57d9fdb1868c"},
|
2277 |
+
{file = "minijinja-2.2.0-cp38-abi3-win32.whl", hash = "sha256:e431a2467dd6e1bcb7c511e9fbad012b02c6e5453acdd9fbd4c4af0d34a3d1c5"},
|
2278 |
+
{file = "minijinja-2.2.0-cp38-abi3-win_amd64.whl", hash = "sha256:d4df7e4a09be4249c8243207fa89e6f4d22b853c2b565a99f48e478a30713822"},
|
2279 |
+
{file = "minijinja-2.2.0.tar.gz", hash = "sha256:4411052c7a60f8d56468cc6d17d45d72be3d5e89e9578a04f8336cc56601523c"},
|
2280 |
]
|
2281 |
|
2282 |
[[package]]
|
|
|
3428 |
[package.extras]
|
3429 |
dev = ["argcomplete", "attrs (>=19.2)", "hypothesis (>=3.56)", "mock", "pygments (>=2.7.2)", "requests", "setuptools", "xmlschema"]
|
3430 |
|
3431 |
+
[[package]]
|
3432 |
+
name = "pytest-asyncio"
|
3433 |
+
version = "0.24.0"
|
3434 |
+
description = "Pytest support for asyncio"
|
3435 |
+
optional = false
|
3436 |
+
python-versions = ">=3.8"
|
3437 |
+
files = [
|
3438 |
+
{file = "pytest_asyncio-0.24.0-py3-none-any.whl", hash = "sha256:a811296ed596b69bf0b6f3dc40f83bcaf341b155a269052d82efa2b25ac7037b"},
|
3439 |
+
{file = "pytest_asyncio-0.24.0.tar.gz", hash = "sha256:d081d828e576d85f875399194281e92bf8a68d60d72d1a2faf2feddb6c46b276"},
|
3440 |
+
]
|
3441 |
+
|
3442 |
+
[package.dependencies]
|
3443 |
+
pytest = ">=8.2,<9"
|
3444 |
+
|
3445 |
+
[package.extras]
|
3446 |
+
docs = ["sphinx (>=5.3)", "sphinx-rtd-theme (>=1.0)"]
|
3447 |
+
testing = ["coverage (>=6.2)", "hypothesis (>=5.7.1)"]
|
3448 |
+
|
3449 |
[[package]]
|
3450 |
name = "pytest-cov"
|
3451 |
version = "5.0.0"
|
|
|
3723 |
|
3724 |
[[package]]
|
3725 |
name = "rich"
|
3726 |
+
version = "13.8.0"
|
3727 |
description = "Render rich text, tables, progress bars, syntax highlighting, markdown and more to the terminal"
|
3728 |
optional = false
|
3729 |
python-versions = ">=3.7.0"
|
3730 |
files = [
|
3731 |
+
{file = "rich-13.8.0-py3-none-any.whl", hash = "sha256:2e85306a063b9492dffc86278197a60cbece75bcb766022f3436f567cae11bdc"},
|
3732 |
+
{file = "rich-13.8.0.tar.gz", hash = "sha256:a5ac1f1cd448ade0d59cc3356f7db7a7ccda2c8cbae9c7a90c28ff463d3e91f4"},
|
3733 |
]
|
3734 |
|
3735 |
[package.dependencies]
|
|
|
5260 |
[metadata]
|
5261 |
lock-version = "2.0"
|
5262 |
python-versions = ">=3.10,<3.13"
|
5263 |
+
content-hash = "45accb38e74b5646d74896c8545504072d577c8a87b71d379753672353e613be"
|
pyproject.toml
CHANGED
@@ -38,6 +38,7 @@ pytest-cov = "^5.0.0"
|
|
38 |
types-requests = "^2.32.0.20240712"
|
39 |
mypy = "^1.11.1"
|
40 |
pytest-mock = "^3.14.0"
|
|
|
41 |
|
42 |
|
43 |
[tool.ruff]
|
|
|
38 |
types-requests = "^2.32.0.20240712"
|
39 |
mypy = "^1.11.1"
|
40 |
pytest-mock = "^3.14.0"
|
41 |
+
pytest-asyncio = "^0.24.0"
|
42 |
|
43 |
|
44 |
[tool.ruff]
|
tests/rag/test_wf.py
ADDED
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import pytest
|
2 |
+
from dotenv import load_dotenv
|
3 |
+
|
4 |
+
from medirag.index.local import DailyMedIndexer
|
5 |
+
from medirag.rag.wf import RAGWorkflow
|
6 |
+
|
7 |
+
load_dotenv() # take environment variables from .env.
|
8 |
+
|
9 |
+
|
10 |
+
@pytest.mark.asyncio
|
11 |
+
async def test_wf_with_example(data_dir):
|
12 |
+
# Example usage:
|
13 |
+
index_path = data_dir.joinpath("daily_bio_bert_indexed")
|
14 |
+
# Ensure the path is correct and the directory exists
|
15 |
+
assert index_path.exists(), f"Directory not found: {index_path}"
|
16 |
+
|
17 |
+
# Initialize the indexer and load the index
|
18 |
+
indexer = DailyMedIndexer(persist_dir=index_path)
|
19 |
+
indexer.load_index()
|
20 |
+
|
21 |
+
top_k = 3 # Adjust the number of documents to retrieve
|
22 |
+
top_n = 3 # Adjust the number of top-ranked documents to select
|
23 |
+
|
24 |
+
# Pass the indexer to the workflow
|
25 |
+
workflow = RAGWorkflow(indexer=indexer, timeout=60, top_k=top_k, top_n=top_n)
|
26 |
+
query = "What information do you have about Clopidogrel?"
|
27 |
+
|
28 |
+
result = await workflow.run(query=query)
|
29 |
+
accumulated_response = ""
|
30 |
+
if hasattr(result, 'async_response_gen'):
|
31 |
+
async for chunk in result.async_response_gen():
|
32 |
+
accumulated_response += chunk
|
33 |
+
|
34 |
+
assert len(accumulated_response) > 0
|