Created
July 6, 2025 19:39
-
-
Save dridk/bb9665f6ec2c89835193b43b8bf9b33f to your computer and use it in GitHub Desktop.
dspy extraction concepte médicaux avec contexte
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import dspy | |
| from pydantic import BaseModel, Field | |
| lm = dspy.LM("ollama_chat/deepseek-r1:14b", api_base="http://localhost:11434", api_key="") | |
| dspy.configure(lm=lm) | |
| class Maladie(BaseModel): | |
| """ | |
| Une maladie associé à son contexte. | |
| Si la maladie est dans une négation ou dans un antécédant familliale. | |
| """ | |
| nom: str = Field(description="Nom de la maladie ou du syndrome") | |
| negation: bool = Field(desciption="Vrai si la maladie est dans une négation") | |
| famille: bool = Field(description="Vrai si la maladie est présent dans la famille") | |
| class MaladieDetectionSignature(dspy.Signature): | |
| """ | |
| Extraction des maladies à partir d'un compte-rendu clinique. | |
| """ | |
| text : str = dspy.InputField(desc="Un compte-rendu clinique") | |
| maladies : list[Maladie] = dspy.OutputField(desc="Une liste de maladie extraite depuis le compte-rendu") | |
| model = dspy.ChainOfThought(MaladieDetectionSignature) | |
| text = """ | |
| J'ai vu en consultation Mr Claude pour une endocardite compliqué d'une septicémie. | |
| Ce patient n'a pas de diabète ni d'hypertension arterielle. Son père à eu un infarctus du myocarde. | |
| """ | |
| maladies = model(text=text).maladies | |
| for m in maladies: | |
| print(m.json()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment