dotimplement / HealthChain

Simplify prototyping and testing LLM applications in healthcare context 💫 🏥
https://dotimplement.github.io/HealthChain/
Apache License 2.0
10 stars 1 forks source link

Service and sandbox orchestrator #7

Closed jenniferjiangkells closed 3 months ago

jenniferjiangkells commented 3 months ago

What is the purpose of this PR?

This PR adds the sandbox and service orchestration layer through the use of decorators @api and @sandbox.

Users can decorate their function with the @api decorator to mark it as the primary A/LLM processing function of their service. The decorator will mark the function as a route to a FastAPI app and mount it to the correct endpoint as defined in the UseCase.

The @sandbox decorator marks the entire class as a sandbox orchestrator. It will set up the client and service with the configurations defined in Service, Client, and UseCase. The class must be derived from BaseUseCase, i.e. inherit fromClinicalDecisionSupport. Typically, The @ehr function will define the synthetic data the users want to test with, and @api function will be where the actual processing logic lies. .start_sabdbox() will then start the service and client on separate async threads.

Example use:

@sandbox
class myCDS(ClinicalDecisionSupport):
        def __init__(self) -> None:
            self.data_generator = DataGenerator()

        @ehr(workflow="encounter-discharge", num=3)
        def load_data(self):
            data = self.data_generator.generate()
            return data

        @api
        def llm(self, text: str):
            chain = prompt | llm | JsonOutputParser()
            result = chain.invoke(text)
            return result

cds = myCDS()
cds.start_sandbox()
print(cds.responses)

Next steps

Integrating with actual data generator (it needs to also include meta data for the CDSRequest) Export request/responses to a directory, or visualise through a streamlit dashboard