11"""Define tasks for the hftest study"""
22
3- import cumulus_fhir_support as cfs
4- import httpx
53import pyarrow
64import rich .progress
75
8- from cumulus_etl import common , errors , nlp
6+ from cumulus_etl import common , nlp
97from cumulus_etl .etl import tasks
108
119
@@ -17,48 +15,35 @@ class HuggingFaceTestTask(tasks.BaseNlpTask):
1715 task_version = 0
1816 # Task Version History:
1917 # ** 0 **
20- # This is fluid until we actually promote this to a real task - feel free to update without bumping the version.
21- # container: ghcr.io/huggingface/text-generation-inference
22- # container reversion: 09eca6422788b1710c54ee0d05dd6746f16bb681
18+ # This is fluid until we actually promote this to a real task - feel free to update without
19+ # bumping the version.
20+ # container: vllm/vllm-openai
21+ # container revision: v0.10.0
2322 # container properties:
24- # QUANTIZE=bitsandbytes-nf4
23+ # QUANTIZE=bitsandbytes
2524 # model: meta-llama/Llama-2-13b-chat-hf
26- # model revision: 0ba94ac9b9e1d5a0037780667e8b219adde1908c
25+ # model revision: a2cb7a712bb6e5e736ca7f8cd98167f81a0b5bd8
2726 # system prompt:
28- # "You will be given a clinical note, and you should reply with a short summary of that note."
27+ # "You will be given a clinical note, and you should reply with a short summary of that
28+ # note."
2929 # user prompt: a clinical note
3030
3131 @classmethod
3232 async def init_check (cls ) -> None :
33- try :
34- raw_info = await nlp .hf_info ()
35- except cfs .NetworkError :
36- errors .fatal (
37- "Llama2 NLP server is unreachable.\n Try running 'docker compose up llama2 --wait'." ,
38- errors .SERVICE_MISSING ,
39- )
40-
41- # Sanity check a few of the properties, to make sure we don't accidentally get pointed at an unexpected model.
42- expected_info_present = (
43- raw_info .get ("model_id" ) == "meta-llama/Llama-2-13b-chat-hf"
44- and raw_info .get ("model_sha" ) == "0ba94ac9b9e1d5a0037780667e8b219adde1908c"
45- and raw_info .get ("sha" ) == "09eca6422788b1710c54ee0d05dd6746f16bb681"
46- )
47- if not expected_info_present :
48- errors .fatal (
49- "LLama2 NLP server is using an unexpected model setup." ,
50- errors .SERVICE_MISSING ,
51- )
33+ await nlp .Llama2Model ().check ()
5234
5335 async def read_entries (self , * , progress : rich .progress .Progress = None ) -> tasks .EntryIterator :
5436 """Passes clinical notes through HF and returns any symptoms found"""
55- http_client = httpx . AsyncClient ( timeout = 300 )
37+ client = nlp . Llama2Model ( )
5638
5739 async for _ , docref , clinical_note in self .read_notes (progress = progress ):
5840 timestamp = common .datetime_now ().isoformat ()
5941
6042 # If you change this prompt, consider updating task_version.
61- system_prompt = "You will be given a clinical note, and you should reply with a short summary of that note."
43+ system_prompt = (
44+ "You will be given a clinical note, "
45+ "and you should reply with a short summary of that note."
46+ )
6247 user_prompt = clinical_note
6348
6449 summary = await nlp .cache_wrapper (
@@ -67,18 +52,17 @@ async def read_entries(self, *, progress: rich.progress.Progress = None) -> task
6752 clinical_note ,
6853 lambda x : x , # from file: just store the string
6954 lambda x : x , # to file: just read it back
70- nlp . llama2_prompt ,
55+ client . prompt ,
7156 system_prompt ,
7257 user_prompt ,
73- client = http_client ,
7458 )
7559
7660 # Debugging
77- # logging.warning("\n\n\n\n" "********************************************************** ")
61+ # logging.warning("\n\n\n\n" "********************************************************")
7862 # logging.warning(user_prompt)
79- # logging.warning("========================================================== ")
63+ # logging.warning("========================================================")
8064 # logging.warning(summary)
81- # logging.warning("********************************************************** ")
65+ # logging.warning("********************************************************")
8266
8367 yield {
8468 "id" : docref ["id" ], # just copy the docref
0 commit comments