pharmassistant 1.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pharmassistant-1.0.0/.gitignore +9 -0
- pharmassistant-1.0.0/CHANGELOG.md +15 -0
- pharmassistant-1.0.0/LICENSE +21 -0
- pharmassistant-1.0.0/PKG-INFO +203 -0
- pharmassistant-1.0.0/README.md +166 -0
- pharmassistant-1.0.0/docs/README.md +43 -0
- pharmassistant-1.0.0/docs/asynchrone.md +76 -0
- pharmassistant-1.0.0/docs/citations.md +98 -0
- pharmassistant-1.0.0/docs/cli.md +106 -0
- pharmassistant-1.0.0/docs/confidentialite.md +21 -0
- pharmassistant-1.0.0/docs/configuration.md +99 -0
- pharmassistant-1.0.0/docs/conversations.md +87 -0
- pharmassistant-1.0.0/docs/demarrage.md +86 -0
- pharmassistant-1.0.0/docs/erreurs.md +129 -0
- pharmassistant-1.0.0/docs/fichier-unique.md +54 -0
- pharmassistant-1.0.0/docs/flux.md +97 -0
- pharmassistant-1.0.0/docs/questions.md +133 -0
- pharmassistant-1.0.0/docs/recettes.md +239 -0
- pharmassistant-1.0.0/docs/reference.md +150 -0
- pharmassistant-1.0.0/pyproject.toml +76 -0
- pharmassistant-1.0.0/src/pharmassistant/__init__.py +107 -0
- pharmassistant-1.0.0/src/pharmassistant/__main__.py +3 -0
- pharmassistant-1.0.0/src/pharmassistant/_aide.py +330 -0
- pharmassistant-1.0.0/src/pharmassistant/_base.py +262 -0
- pharmassistant-1.0.0/src/pharmassistant/_cli.py +638 -0
- pharmassistant-1.0.0/src/pharmassistant/_client.py +574 -0
- pharmassistant-1.0.0/src/pharmassistant/_conversation.py +61 -0
- pharmassistant-1.0.0/src/pharmassistant/_errors.py +235 -0
- pharmassistant-1.0.0/src/pharmassistant/_models.py +573 -0
- pharmassistant-1.0.0/src/pharmassistant/_streaming.py +293 -0
- pharmassistant-1.0.0/src/pharmassistant/_version.py +1 -0
- pharmassistant-1.0.0/src/pharmassistant/py.typed +0 -0
- pharmassistant-1.0.0/tests/_outils.py +117 -0
- pharmassistant-1.0.0/tests/test_aide.py +120 -0
- pharmassistant-1.0.0/tests/test_asynchrone.py +82 -0
- pharmassistant-1.0.0/tests/test_cli.py +241 -0
- pharmassistant-1.0.0/tests/test_client.py +180 -0
- pharmassistant-1.0.0/tests/test_contrat.py +79 -0
- pharmassistant-1.0.0/tests/test_conversation.py +84 -0
- pharmassistant-1.0.0/tests/test_erreurs.py +107 -0
- pharmassistant-1.0.0/tests/test_flux.py +116 -0
- pharmassistant-1.0.0/tests/test_modeles.py +99 -0
- pharmassistant-1.0.0/tests/test_reessais.py +98 -0
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# Journal des versions
|
|
2
|
+
|
|
3
|
+
## 1.0.0
|
|
4
|
+
|
|
5
|
+
Première version publiée sur PyPI.
|
|
6
|
+
|
|
7
|
+
- Clients `PharmAssistant` (synchrone) et `AsyncPharmAssistant` (asynchrone), mêmes méthodes : `ask`, `ask_stream`, `me`, `health`, `conversations.list / retrieve / delete`, `with_options`.
|
|
8
|
+
- Réponses typées (`Answer`, `KeyInfo`…) : le JSON de l'API, lisible par clés comme par attributs ; `iter_citations`, `answer_without_markers`, `all_sources`, `rate_limit`.
|
|
9
|
+
- Réponse en flux (`AnswerStream`) : `text_stream`, `get_final_answer`, événements typés qui se déballent en `event, data`.
|
|
10
|
+
- Conversations suivies (`start_conversation`, `resume_conversation`), historique chez le client ou gardé par le serveur.
|
|
11
|
+
- Demande de précision : `Clarification.corrected_question`, même règle que le chat.
|
|
12
|
+
- Erreurs typées, chacune avec son `aide` ; nouveaux essais automatiques sur connexion impossible, rafale et 5xx, jamais sur ce qui a pu être décompté.
|
|
13
|
+
- Commande `pharmassistant` : question, discussion, conversations, cle, service, aide.
|
|
14
|
+
- Aide intégrée par sujet et par code d'erreur : `pharmassistant.aide()`.
|
|
15
|
+
- Compatible avec le code écrit pour le fichier unique servi par l'API.
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Johan Natter (PharmAssistant)
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: pharmassistant
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Client Python officiel de l'API PharmAssistant, l'assistant pharmaceutique pour l'officine : synchrone, asynchrone, flux, conversations, ligne de commande.
|
|
5
|
+
Project-URL: Homepage, https://pharmassistant.fr/developpeurs
|
|
6
|
+
Project-URL: Documentation, https://github.com/Vitruves/pharmassistant-python/blob/main/docs/README.md
|
|
7
|
+
Project-URL: API HTTP, https://api.pharmassistant.fr/docs
|
|
8
|
+
Project-URL: Source, https://github.com/Vitruves/pharmassistant-python
|
|
9
|
+
Project-URL: Changelog, https://github.com/Vitruves/pharmassistant-python/blob/main/CHANGELOG.md
|
|
10
|
+
Project-URL: Issues, https://github.com/Vitruves/pharmassistant-python/issues
|
|
11
|
+
Author: PharmAssistant
|
|
12
|
+
License-Expression: MIT
|
|
13
|
+
License-File: LICENSE
|
|
14
|
+
Keywords: api,client,officine,pharmacie,pharmacien,pharmassistant,sdk
|
|
15
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
16
|
+
Classifier: Environment :: Console
|
|
17
|
+
Classifier: Framework :: AsyncIO
|
|
18
|
+
Classifier: Intended Audience :: Developers
|
|
19
|
+
Classifier: Intended Audience :: Healthcare Industry
|
|
20
|
+
Classifier: Natural Language :: French
|
|
21
|
+
Classifier: Operating System :: OS Independent
|
|
22
|
+
Classifier: Programming Language :: Python :: 3
|
|
23
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
24
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
25
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
26
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
27
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
28
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
29
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
30
|
+
Classifier: Programming Language :: Python :: 3.15
|
|
31
|
+
Classifier: Topic :: Scientific/Engineering :: Medical Science Apps.
|
|
32
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
33
|
+
Classifier: Typing :: Typed
|
|
34
|
+
Requires-Python: >=3.9
|
|
35
|
+
Requires-Dist: httpx<1,>=0.27
|
|
36
|
+
Description-Content-Type: text/markdown
|
|
37
|
+
|
|
38
|
+
<p align="center">
|
|
39
|
+
<a href="https://pharmassistant.fr">
|
|
40
|
+
<img src="https://raw.githubusercontent.com/Vitruves/pharmassistant-python/main/.github/images/monogramme.png" alt="PharmAssistant" width="96">
|
|
41
|
+
</a>
|
|
42
|
+
</p>
|
|
43
|
+
|
|
44
|
+
<h1 align="center">pharmassistant</h1>
|
|
45
|
+
|
|
46
|
+
<p align="center">
|
|
47
|
+
Client Python officiel de l'API <a href="https://pharmassistant.fr">PharmAssistant</a>, l'assistant pharmaceutique de l'officine.
|
|
48
|
+
</p>
|
|
49
|
+
|
|
50
|
+
<p align="center">
|
|
51
|
+
<a href="https://pypi.org/project/pharmassistant/"><img src="https://img.shields.io/pypi/v/pharmassistant?color=17693F" alt="Version sur PyPI"></a>
|
|
52
|
+
<a href="https://pypi.org/project/pharmassistant/"><img src="https://img.shields.io/pypi/pyversions/pharmassistant?color=17693F" alt="Versions de Python"></a>
|
|
53
|
+
<a href="https://github.com/Vitruves/pharmassistant-python/actions/workflows/ci.yml"><img src="https://github.com/Vitruves/pharmassistant-python/actions/workflows/ci.yml/badge.svg" alt="CI"></a>
|
|
54
|
+
<a href="https://github.com/Vitruves/pharmassistant-python/blob/main/LICENSE"><img src="https://img.shields.io/badge/licence-MIT-17693F" alt="Licence MIT"></a>
|
|
55
|
+
</p>
|
|
56
|
+
|
|
57
|
+
<p align="center">
|
|
58
|
+
<a href="https://github.com/Vitruves/pharmassistant-python/blob/main/docs/README.md">Documentation</a> ·
|
|
59
|
+
<a href="https://github.com/Vitruves/pharmassistant-python/blob/main/docs/reference.md">Référence</a> ·
|
|
60
|
+
<a href="https://github.com/Vitruves/pharmassistant-python/blob/main/docs/recettes.md">Recettes</a> ·
|
|
61
|
+
<a href="https://api.pharmassistant.fr/docs">API HTTP</a>
|
|
62
|
+
</p>
|
|
63
|
+
|
|
64
|
+
---
|
|
65
|
+
|
|
66
|
+
PharmAssistant répond aux questions du comptoir à partir des bases documentaires de référence, et cite ses sources. Ce paquet en fait quelques lignes de Python : réponses typées, flux, conversations, citations dans le texte, erreurs qui disent quoi faire.
|
|
67
|
+
|
|
68
|
+
```bash
|
|
69
|
+
pip install pharmassistant
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
```python
|
|
73
|
+
from pharmassistant import PharmAssistant
|
|
74
|
+
|
|
75
|
+
client = PharmAssistant() # clé lue dans PHARMASSISTANT_API_KEY
|
|
76
|
+
|
|
77
|
+
reponse = client.ask("Amoxicilline et allaitement ?")
|
|
78
|
+
|
|
79
|
+
print(reponse.answer) # markdown, prêt à afficher
|
|
80
|
+
print(reponse.patient_advice) # discours à tenir au patient
|
|
81
|
+
for source in reponse.all_sources():
|
|
82
|
+
print("·", source.title, source.url)
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
Python 3.9 ou plus récent, une seule dépendance ([httpx](https://www.python-httpx.org)). La clé se demande à [contact@pharmassistant.fr](mailto:contact@pharmassistant.fr) : voir [Démarrage](https://github.com/Vitruves/pharmassistant-python/blob/main/docs/demarrage.md).
|
|
86
|
+
|
|
87
|
+
## En un coup d'œil
|
|
88
|
+
|
|
89
|
+
### Des réponses typées
|
|
90
|
+
|
|
91
|
+
Chaque réponse est le JSON de l'API, lisible par attributs avec la complétion de l'éditeur : titre, réponse markdown, points clés à polarité, discours patient, vente associée, pistes, sources, quota.
|
|
92
|
+
|
|
93
|
+
```python
|
|
94
|
+
for point in reponse.key_points:
|
|
95
|
+
print("✔" if point.is_positive else "✘", point.text)
|
|
96
|
+
print(reponse.usage.daily_requests_used, "questions posées aujourd'hui")
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
→ [Poser une question](https://github.com/Vitruves/pharmassistant-python/blob/main/docs/questions.md)
|
|
100
|
+
|
|
101
|
+
### Des sources citées phrase par phrase
|
|
102
|
+
|
|
103
|
+
```python
|
|
104
|
+
reponse = client.ask("Ibuprofène et grossesse ?", citations="inline")
|
|
105
|
+
|
|
106
|
+
for c in reponse.iter_citations(): # [S1], [S2]… dans l'ordre du texte
|
|
107
|
+
titre = c.reference.title if c.reference else ""
|
|
108
|
+
print(c.n, titre, "→", c.passage.quote if c.passage else "")
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
Chaque repère renvoie à sa source et à l'extrait qui porte la phrase. Sans source, l'API le dit au lieu de répondre de mémoire.
|
|
112
|
+
|
|
113
|
+
→ [Sources et citations](https://github.com/Vitruves/pharmassistant-python/blob/main/docs/citations.md)
|
|
114
|
+
|
|
115
|
+
### La réponse au fil de la rédaction
|
|
116
|
+
|
|
117
|
+
```python
|
|
118
|
+
with client.ask_stream("Tramadol et sertraline ?") as flux:
|
|
119
|
+
for texte in flux.text_stream:
|
|
120
|
+
print(texte, end="", flush=True)
|
|
121
|
+
reponse = flux.get_final_answer()
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
→ [Réponse en flux](https://github.com/Vitruves/pharmassistant-python/blob/main/docs/flux.md)
|
|
125
|
+
|
|
126
|
+
### Des échanges suivis
|
|
127
|
+
|
|
128
|
+
```python
|
|
129
|
+
conv = client.start_conversation()
|
|
130
|
+
conv.ask("Amoxicilline et allaitement ?")
|
|
131
|
+
conv.ask("Et pendant la grossesse ?") # tient compte de la question précédente
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
Historique chez vous, ou gardé par le serveur et repris plus tard (`store=True`).
|
|
135
|
+
|
|
136
|
+
→ [Conversations](https://github.com/Vitruves/pharmassistant-python/blob/main/docs/conversations.md)
|
|
137
|
+
|
|
138
|
+
### Des erreurs qui disent quoi faire
|
|
139
|
+
|
|
140
|
+
```python
|
|
141
|
+
from pharmassistant import PharmAssistantError, QuotaExceededError
|
|
142
|
+
|
|
143
|
+
try:
|
|
144
|
+
reponse = client.ask("Amoxicilline et allaitement ?")
|
|
145
|
+
except QuotaExceededError as e:
|
|
146
|
+
print(e.aide) # « Attendez minuit (heure de Paris), ou relevez le plafond… »
|
|
147
|
+
except PharmAssistantError as e:
|
|
148
|
+
print(e.code, e.request_id)
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
Rafales, pannes passagères et coupures réseau sont réessayées seules, jamais ce qui a pu être décompté.
|
|
152
|
+
|
|
153
|
+
→ [Erreurs, quotas et nouveaux essais](https://github.com/Vitruves/pharmassistant-python/blob/main/docs/erreurs.md)
|
|
154
|
+
|
|
155
|
+
### Asynchrone
|
|
156
|
+
|
|
157
|
+
```python
|
|
158
|
+
from pharmassistant import AsyncPharmAssistant
|
|
159
|
+
|
|
160
|
+
async with AsyncPharmAssistant() as client:
|
|
161
|
+
reponse = await client.ask("Amoxicilline et allaitement ?")
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
→ [Client asynchrone](https://github.com/Vitruves/pharmassistant-python/blob/main/docs/asynchrone.md), et les recettes [FastAPI et Django](https://github.com/Vitruves/pharmassistant-python/blob/main/docs/recettes.md)
|
|
165
|
+
|
|
166
|
+
### Une aide intégrée, et une commande pour essayer
|
|
167
|
+
|
|
168
|
+
```python
|
|
169
|
+
import pharmassistant
|
|
170
|
+
pharmassistant.aide("citations") # aussi : un code d'erreur, ou aide() pour le sommaire
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
```bash
|
|
174
|
+
pharmassistant "Amoxicilline et allaitement ?"
|
|
175
|
+
pharmassistant aide
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
→ [Ligne de commande](https://github.com/Vitruves/pharmassistant-python/blob/main/docs/cli.md)
|
|
179
|
+
|
|
180
|
+
## Documentation
|
|
181
|
+
|
|
182
|
+
| Guide | Pour |
|
|
183
|
+
|---|---|
|
|
184
|
+
| [Démarrage](https://github.com/Vitruves/pharmassistant-python/blob/main/docs/demarrage.md) | installer, poser la clé, première question |
|
|
185
|
+
| [Poser une question](https://github.com/Vitruves/pharmassistant-python/blob/main/docs/questions.md) | options, champs de la réponse, demande de précision |
|
|
186
|
+
| [Sources et citations](https://github.com/Vitruves/pharmassistant-python/blob/main/docs/citations.md) | références par base, repères `[S1]`, extraits |
|
|
187
|
+
| [Réponse en flux](https://github.com/Vitruves/pharmassistant-python/blob/main/docs/flux.md) | texte au fil de l'eau, étapes, erreurs en cours de flux |
|
|
188
|
+
| [Conversations](https://github.com/Vitruves/pharmassistant-python/blob/main/docs/conversations.md) | historique local ou gardé par le serveur |
|
|
189
|
+
| [Client asynchrone](https://github.com/Vitruves/pharmassistant-python/blob/main/docs/asynchrone.md) | `asyncio`, questions en parallèle |
|
|
190
|
+
| [Erreurs, quotas et nouveaux essais](https://github.com/Vitruves/pharmassistant-python/blob/main/docs/erreurs.md) | chaque exception et chaque code |
|
|
191
|
+
| [Configuration](https://github.com/Vitruves/pharmassistant-python/blob/main/docs/configuration.md) | délais, proxy, certificats, journal |
|
|
192
|
+
| [Ligne de commande](https://github.com/Vitruves/pharmassistant-python/blob/main/docs/cli.md) | la commande `pharmassistant` |
|
|
193
|
+
| [Recettes](https://github.com/Vitruves/pharmassistant-python/blob/main/docs/recettes.md) | FastAPI, Django, lots, rendu HTML, tests sans réseau |
|
|
194
|
+
| [Référence](https://github.com/Vitruves/pharmassistant-python/blob/main/docs/reference.md) | chaque classe, méthode et attribut |
|
|
195
|
+
| [Venir du fichier unique](https://github.com/Vitruves/pharmassistant-python/blob/main/docs/fichier-unique.md) | passer du `curl -O` au paquet |
|
|
196
|
+
|
|
197
|
+
## Données patient
|
|
198
|
+
|
|
199
|
+
Les conditions d'utilisation de l'API interdisent d'y envoyer toute donnée identifiant un patient. Posez la question sur la situation clinique, jamais sur la personne : voir [Données patient](https://github.com/Vitruves/pharmassistant-python/blob/main/docs/confidentialite.md).
|
|
200
|
+
|
|
201
|
+
## Licence
|
|
202
|
+
|
|
203
|
+
MIT, voir [LICENSE](https://github.com/Vitruves/pharmassistant-python/blob/main/LICENSE). L'usage du service relève des [conditions d'utilisation de l'API](https://pharmassistant.fr/developpeurs).
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<a href="https://pharmassistant.fr">
|
|
3
|
+
<img src="https://raw.githubusercontent.com/Vitruves/pharmassistant-python/main/.github/images/monogramme.png" alt="PharmAssistant" width="96">
|
|
4
|
+
</a>
|
|
5
|
+
</p>
|
|
6
|
+
|
|
7
|
+
<h1 align="center">pharmassistant</h1>
|
|
8
|
+
|
|
9
|
+
<p align="center">
|
|
10
|
+
Client Python officiel de l'API <a href="https://pharmassistant.fr">PharmAssistant</a>, l'assistant pharmaceutique de l'officine.
|
|
11
|
+
</p>
|
|
12
|
+
|
|
13
|
+
<p align="center">
|
|
14
|
+
<a href="https://pypi.org/project/pharmassistant/"><img src="https://img.shields.io/pypi/v/pharmassistant?color=17693F" alt="Version sur PyPI"></a>
|
|
15
|
+
<a href="https://pypi.org/project/pharmassistant/"><img src="https://img.shields.io/pypi/pyversions/pharmassistant?color=17693F" alt="Versions de Python"></a>
|
|
16
|
+
<a href="https://github.com/Vitruves/pharmassistant-python/actions/workflows/ci.yml"><img src="https://github.com/Vitruves/pharmassistant-python/actions/workflows/ci.yml/badge.svg" alt="CI"></a>
|
|
17
|
+
<a href="https://github.com/Vitruves/pharmassistant-python/blob/main/LICENSE"><img src="https://img.shields.io/badge/licence-MIT-17693F" alt="Licence MIT"></a>
|
|
18
|
+
</p>
|
|
19
|
+
|
|
20
|
+
<p align="center">
|
|
21
|
+
<a href="https://github.com/Vitruves/pharmassistant-python/blob/main/docs/README.md">Documentation</a> ·
|
|
22
|
+
<a href="https://github.com/Vitruves/pharmassistant-python/blob/main/docs/reference.md">Référence</a> ·
|
|
23
|
+
<a href="https://github.com/Vitruves/pharmassistant-python/blob/main/docs/recettes.md">Recettes</a> ·
|
|
24
|
+
<a href="https://api.pharmassistant.fr/docs">API HTTP</a>
|
|
25
|
+
</p>
|
|
26
|
+
|
|
27
|
+
---
|
|
28
|
+
|
|
29
|
+
PharmAssistant répond aux questions du comptoir à partir des bases documentaires de référence, et cite ses sources. Ce paquet en fait quelques lignes de Python : réponses typées, flux, conversations, citations dans le texte, erreurs qui disent quoi faire.
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
pip install pharmassistant
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
```python
|
|
36
|
+
from pharmassistant import PharmAssistant
|
|
37
|
+
|
|
38
|
+
client = PharmAssistant() # clé lue dans PHARMASSISTANT_API_KEY
|
|
39
|
+
|
|
40
|
+
reponse = client.ask("Amoxicilline et allaitement ?")
|
|
41
|
+
|
|
42
|
+
print(reponse.answer) # markdown, prêt à afficher
|
|
43
|
+
print(reponse.patient_advice) # discours à tenir au patient
|
|
44
|
+
for source in reponse.all_sources():
|
|
45
|
+
print("·", source.title, source.url)
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
Python 3.9 ou plus récent, une seule dépendance ([httpx](https://www.python-httpx.org)). La clé se demande à [contact@pharmassistant.fr](mailto:contact@pharmassistant.fr) : voir [Démarrage](https://github.com/Vitruves/pharmassistant-python/blob/main/docs/demarrage.md).
|
|
49
|
+
|
|
50
|
+
## En un coup d'œil
|
|
51
|
+
|
|
52
|
+
### Des réponses typées
|
|
53
|
+
|
|
54
|
+
Chaque réponse est le JSON de l'API, lisible par attributs avec la complétion de l'éditeur : titre, réponse markdown, points clés à polarité, discours patient, vente associée, pistes, sources, quota.
|
|
55
|
+
|
|
56
|
+
```python
|
|
57
|
+
for point in reponse.key_points:
|
|
58
|
+
print("✔" if point.is_positive else "✘", point.text)
|
|
59
|
+
print(reponse.usage.daily_requests_used, "questions posées aujourd'hui")
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
→ [Poser une question](https://github.com/Vitruves/pharmassistant-python/blob/main/docs/questions.md)
|
|
63
|
+
|
|
64
|
+
### Des sources citées phrase par phrase
|
|
65
|
+
|
|
66
|
+
```python
|
|
67
|
+
reponse = client.ask("Ibuprofène et grossesse ?", citations="inline")
|
|
68
|
+
|
|
69
|
+
for c in reponse.iter_citations(): # [S1], [S2]… dans l'ordre du texte
|
|
70
|
+
titre = c.reference.title if c.reference else ""
|
|
71
|
+
print(c.n, titre, "→", c.passage.quote if c.passage else "")
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
Chaque repère renvoie à sa source et à l'extrait qui porte la phrase. Sans source, l'API le dit au lieu de répondre de mémoire.
|
|
75
|
+
|
|
76
|
+
→ [Sources et citations](https://github.com/Vitruves/pharmassistant-python/blob/main/docs/citations.md)
|
|
77
|
+
|
|
78
|
+
### La réponse au fil de la rédaction
|
|
79
|
+
|
|
80
|
+
```python
|
|
81
|
+
with client.ask_stream("Tramadol et sertraline ?") as flux:
|
|
82
|
+
for texte in flux.text_stream:
|
|
83
|
+
print(texte, end="", flush=True)
|
|
84
|
+
reponse = flux.get_final_answer()
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
→ [Réponse en flux](https://github.com/Vitruves/pharmassistant-python/blob/main/docs/flux.md)
|
|
88
|
+
|
|
89
|
+
### Des échanges suivis
|
|
90
|
+
|
|
91
|
+
```python
|
|
92
|
+
conv = client.start_conversation()
|
|
93
|
+
conv.ask("Amoxicilline et allaitement ?")
|
|
94
|
+
conv.ask("Et pendant la grossesse ?") # tient compte de la question précédente
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
Historique chez vous, ou gardé par le serveur et repris plus tard (`store=True`).
|
|
98
|
+
|
|
99
|
+
→ [Conversations](https://github.com/Vitruves/pharmassistant-python/blob/main/docs/conversations.md)
|
|
100
|
+
|
|
101
|
+
### Des erreurs qui disent quoi faire
|
|
102
|
+
|
|
103
|
+
```python
|
|
104
|
+
from pharmassistant import PharmAssistantError, QuotaExceededError
|
|
105
|
+
|
|
106
|
+
try:
|
|
107
|
+
reponse = client.ask("Amoxicilline et allaitement ?")
|
|
108
|
+
except QuotaExceededError as e:
|
|
109
|
+
print(e.aide) # « Attendez minuit (heure de Paris), ou relevez le plafond… »
|
|
110
|
+
except PharmAssistantError as e:
|
|
111
|
+
print(e.code, e.request_id)
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
Rafales, pannes passagères et coupures réseau sont réessayées seules, jamais ce qui a pu être décompté.
|
|
115
|
+
|
|
116
|
+
→ [Erreurs, quotas et nouveaux essais](https://github.com/Vitruves/pharmassistant-python/blob/main/docs/erreurs.md)
|
|
117
|
+
|
|
118
|
+
### Asynchrone
|
|
119
|
+
|
|
120
|
+
```python
|
|
121
|
+
from pharmassistant import AsyncPharmAssistant
|
|
122
|
+
|
|
123
|
+
async with AsyncPharmAssistant() as client:
|
|
124
|
+
reponse = await client.ask("Amoxicilline et allaitement ?")
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
→ [Client asynchrone](https://github.com/Vitruves/pharmassistant-python/blob/main/docs/asynchrone.md), et les recettes [FastAPI et Django](https://github.com/Vitruves/pharmassistant-python/blob/main/docs/recettes.md)
|
|
128
|
+
|
|
129
|
+
### Une aide intégrée, et une commande pour essayer
|
|
130
|
+
|
|
131
|
+
```python
|
|
132
|
+
import pharmassistant
|
|
133
|
+
pharmassistant.aide("citations") # aussi : un code d'erreur, ou aide() pour le sommaire
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
```bash
|
|
137
|
+
pharmassistant "Amoxicilline et allaitement ?"
|
|
138
|
+
pharmassistant aide
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
→ [Ligne de commande](https://github.com/Vitruves/pharmassistant-python/blob/main/docs/cli.md)
|
|
142
|
+
|
|
143
|
+
## Documentation
|
|
144
|
+
|
|
145
|
+
| Guide | Pour |
|
|
146
|
+
|---|---|
|
|
147
|
+
| [Démarrage](https://github.com/Vitruves/pharmassistant-python/blob/main/docs/demarrage.md) | installer, poser la clé, première question |
|
|
148
|
+
| [Poser une question](https://github.com/Vitruves/pharmassistant-python/blob/main/docs/questions.md) | options, champs de la réponse, demande de précision |
|
|
149
|
+
| [Sources et citations](https://github.com/Vitruves/pharmassistant-python/blob/main/docs/citations.md) | références par base, repères `[S1]`, extraits |
|
|
150
|
+
| [Réponse en flux](https://github.com/Vitruves/pharmassistant-python/blob/main/docs/flux.md) | texte au fil de l'eau, étapes, erreurs en cours de flux |
|
|
151
|
+
| [Conversations](https://github.com/Vitruves/pharmassistant-python/blob/main/docs/conversations.md) | historique local ou gardé par le serveur |
|
|
152
|
+
| [Client asynchrone](https://github.com/Vitruves/pharmassistant-python/blob/main/docs/asynchrone.md) | `asyncio`, questions en parallèle |
|
|
153
|
+
| [Erreurs, quotas et nouveaux essais](https://github.com/Vitruves/pharmassistant-python/blob/main/docs/erreurs.md) | chaque exception et chaque code |
|
|
154
|
+
| [Configuration](https://github.com/Vitruves/pharmassistant-python/blob/main/docs/configuration.md) | délais, proxy, certificats, journal |
|
|
155
|
+
| [Ligne de commande](https://github.com/Vitruves/pharmassistant-python/blob/main/docs/cli.md) | la commande `pharmassistant` |
|
|
156
|
+
| [Recettes](https://github.com/Vitruves/pharmassistant-python/blob/main/docs/recettes.md) | FastAPI, Django, lots, rendu HTML, tests sans réseau |
|
|
157
|
+
| [Référence](https://github.com/Vitruves/pharmassistant-python/blob/main/docs/reference.md) | chaque classe, méthode et attribut |
|
|
158
|
+
| [Venir du fichier unique](https://github.com/Vitruves/pharmassistant-python/blob/main/docs/fichier-unique.md) | passer du `curl -O` au paquet |
|
|
159
|
+
|
|
160
|
+
## Données patient
|
|
161
|
+
|
|
162
|
+
Les conditions d'utilisation de l'API interdisent d'y envoyer toute donnée identifiant un patient. Posez la question sur la situation clinique, jamais sur la personne : voir [Données patient](https://github.com/Vitruves/pharmassistant-python/blob/main/docs/confidentialite.md).
|
|
163
|
+
|
|
164
|
+
## Licence
|
|
165
|
+
|
|
166
|
+
MIT, voir [LICENSE](https://github.com/Vitruves/pharmassistant-python/blob/main/LICENSE). L'usage du service relève des [conditions d'utilisation de l'API](https://pharmassistant.fr/developpeurs).
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# Documentation de pharmassistant
|
|
2
|
+
|
|
3
|
+
Client Python officiel de l'API PharmAssistant. Chaque page traite un sujet de bout en bout, avec des exemples prêts à copier.
|
|
4
|
+
|
|
5
|
+
## Guides
|
|
6
|
+
|
|
7
|
+
| Page | Pour |
|
|
8
|
+
|---|---|
|
|
9
|
+
| [Démarrage](demarrage.md) | installer, poser une clé, première question en trente secondes |
|
|
10
|
+
| [Poser une question](questions.md) | toutes les options d'`ask`, lire la réponse, demande de précision |
|
|
11
|
+
| [Sources et citations](citations.md) | références par base, repères `[S1]` dans le texte, extraits qui portent chaque phrase |
|
|
12
|
+
| [Réponse en flux](flux.md) | afficher la réponse au fil de la rédaction, suivre chaque étape |
|
|
13
|
+
| [Conversations](conversations.md) | poursuivre un échange, historique chez vous ou gardé par le serveur |
|
|
14
|
+
| [Client asynchrone](asynchrone.md) | `asyncio`, serveurs web, questions en parallèle |
|
|
15
|
+
| [Erreurs, quotas et nouveaux essais](erreurs.md) | chaque exception, chaque code, ce qui est décompté, ce qui est réessayé |
|
|
16
|
+
| [Configuration](configuration.md) | délais, proxy, certificats, journal, client httpx fourni |
|
|
17
|
+
| [Ligne de commande](cli.md) | la commande `pharmassistant` et son aide |
|
|
18
|
+
|
|
19
|
+
## Pour aller plus loin
|
|
20
|
+
|
|
21
|
+
| Page | Pour |
|
|
22
|
+
|---|---|
|
|
23
|
+
| [Recettes](recettes.md) | FastAPI, Django, traitement par lots, rendu HTML des citations, tableau de bord de quota |
|
|
24
|
+
| [Référence](reference.md) | chaque classe, méthode et attribut public |
|
|
25
|
+
| [Venir du fichier unique](fichier-unique.md) | passer du `curl -O` au paquet sans rien réécrire |
|
|
26
|
+
| [Données patient](confidentialite.md) | ce qui ne doit jamais partir vers l'API |
|
|
27
|
+
|
|
28
|
+
## Aide sans quitter le code
|
|
29
|
+
|
|
30
|
+
La même aide est intégrée au paquet :
|
|
31
|
+
|
|
32
|
+
```python
|
|
33
|
+
import pharmassistant
|
|
34
|
+
pharmassistant.aide() # sommaire
|
|
35
|
+
pharmassistant.aide("flux") # un sujet
|
|
36
|
+
pharmassistant.aide("scope_denied") # un code d'erreur
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
pharmassistant aide citations
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
Le contrat HTTP complet (routes, schémas, en-têtes) est décrit sur [api.pharmassistant.fr/docs](https://api.pharmassistant.fr/docs).
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
# Client asynchrone
|
|
2
|
+
|
|
3
|
+
`AsyncPharmAssistant` a les mêmes méthodes que `PharmAssistant`, à attendre avec `await`. C'est le bon choix dans un serveur `asyncio` (FastAPI, Starlette, aiohttp) ou pour poser plusieurs questions en parallèle.
|
|
4
|
+
|
|
5
|
+
```python
|
|
6
|
+
import asyncio
|
|
7
|
+
from pharmassistant import AsyncPharmAssistant
|
|
8
|
+
|
|
9
|
+
async def main():
|
|
10
|
+
async with AsyncPharmAssistant() as client:
|
|
11
|
+
reponse = await client.ask("Amoxicilline et allaitement ?")
|
|
12
|
+
print(reponse.answer)
|
|
13
|
+
|
|
14
|
+
asyncio.run(main())
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Correspondance
|
|
18
|
+
|
|
19
|
+
| Synchrone | Asynchrone |
|
|
20
|
+
|---|---|
|
|
21
|
+
| `client.ask(...)` | `await client.ask(...)` |
|
|
22
|
+
| `client.ask_stream(...)` | `await client.ask_stream(...)` |
|
|
23
|
+
| `with flux:` | `async with flux:` |
|
|
24
|
+
| `for texte in flux.text_stream:` | `async for texte in flux.text_stream:` |
|
|
25
|
+
| `flux.get_final_answer()` | `await flux.get_final_answer()` |
|
|
26
|
+
| `client.me()`, `client.health()` | `await client.me()`, `await client.health()` |
|
|
27
|
+
| `client.conversations.list()` | `await client.conversations.list()` |
|
|
28
|
+
| `conv.ask(...)` | `await conv.ask(...)` |
|
|
29
|
+
| `client.close()` | `await client.close()` |
|
|
30
|
+
|
|
31
|
+
`start_conversation`, `resume_conversation` et `with_options` ne font aucun appel réseau : ils ne s'attendent pas.
|
|
32
|
+
|
|
33
|
+
## Flux
|
|
34
|
+
|
|
35
|
+
```python
|
|
36
|
+
flux = await client.ask_stream("Tramadol et sertraline ?", citations="inline")
|
|
37
|
+
async with flux:
|
|
38
|
+
async for evenement in flux:
|
|
39
|
+
if evenement.event == "chunk":
|
|
40
|
+
print(evenement.text, end="")
|
|
41
|
+
reponse = flux.answer
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## Plusieurs questions en parallèle
|
|
45
|
+
|
|
46
|
+
La clé a un anti-rafale par minute. Bornez le parallélisme avec un sémaphore : le client réessaie de toute façon seul une rafale refusée, mais autant ne pas la provoquer.
|
|
47
|
+
|
|
48
|
+
```python
|
|
49
|
+
import asyncio
|
|
50
|
+
from pharmassistant import AsyncPharmAssistant, PharmAssistantError
|
|
51
|
+
|
|
52
|
+
QUESTIONS = ["Amoxicilline et allaitement ?", "Ibuprofène et grossesse ?",
|
|
53
|
+
"Tramadol et sertraline ?"]
|
|
54
|
+
|
|
55
|
+
async def poser(client, limite, question):
|
|
56
|
+
async with limite:
|
|
57
|
+
try:
|
|
58
|
+
return question, await client.ask(question)
|
|
59
|
+
except PharmAssistantError as e:
|
|
60
|
+
return question, e
|
|
61
|
+
|
|
62
|
+
async def main():
|
|
63
|
+
limite = asyncio.Semaphore(3)
|
|
64
|
+
async with AsyncPharmAssistant() as client:
|
|
65
|
+
resultats = await asyncio.gather(*(poser(client, limite, q) for q in QUESTIONS))
|
|
66
|
+
for question, resultat in resultats:
|
|
67
|
+
print(question, "→", resultat.title if not isinstance(resultat, Exception) else resultat.code)
|
|
68
|
+
|
|
69
|
+
asyncio.run(main())
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
Plus complet : la recette [Traiter une liste de questions](recettes.md#traiter-une-liste-de-questions).
|
|
73
|
+
|
|
74
|
+
## Un seul client par application
|
|
75
|
+
|
|
76
|
+
Créez le client au démarrage et fermez-le à l'arrêt : il garde un pool de connexions. Dans FastAPI, cela se fait dans le `lifespan`, voir la recette [FastAPI](recettes.md#fastapi).
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
# Sources et citations
|
|
2
|
+
|
|
3
|
+
Chaque réponse est rédigée à partir des bases documentaires interrogées pour la question. Le champ `citations` choisit comment ces sources vous reviennent.
|
|
4
|
+
|
|
5
|
+
## `citations="list"` (défaut)
|
|
6
|
+
|
|
7
|
+
La réponse ne porte aucune marque de source. Les références sont rendues à part, par base interrogée :
|
|
8
|
+
|
|
9
|
+
```python
|
|
10
|
+
reponse = client.ask("Amoxicilline et allaitement ?")
|
|
11
|
+
|
|
12
|
+
for base, references in reponse.sources.items():
|
|
13
|
+
print(base)
|
|
14
|
+
for ref in references:
|
|
15
|
+
print(" ", ref.title, ref.url or "(base locale, sans lien)")
|
|
16
|
+
|
|
17
|
+
for ref in reponse.all_sources(): # à plat, sans doublon
|
|
18
|
+
print(ref.title)
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
`url` vaut `None` pour une base sans adresse publique.
|
|
22
|
+
|
|
23
|
+
## `citations="inline"`
|
|
24
|
+
|
|
25
|
+
Chaque fait de la réponse se termine par le repère de sa source, `[S1]` ou `[S2][S4]`. Une question qu'aucune source ne couvre reçoit un aveu, jamais une réponse de mémoire.
|
|
26
|
+
|
|
27
|
+
```python
|
|
28
|
+
reponse = client.ask("Ibuprofène et grossesse ?", citations="inline")
|
|
29
|
+
print(reponse.answer)
|
|
30
|
+
# … contre-indiqué à partir du début du sixième mois.[S1][S2]
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
Trois champs résolvent les repères :
|
|
34
|
+
|
|
35
|
+
| Champ | Contenu |
|
|
36
|
+
|---|---|
|
|
37
|
+
| `references` | le registre numéroté : `[S3]` renvoie à la `Reference` dont `n` vaut 3 (`tool`, `title`, `url`, `empty`, `query`) |
|
|
38
|
+
| `passages` | pour chaque repère, l'extrait de la source qui porte la phrase, apparié par son rang dans le texte (`index`) |
|
|
39
|
+
| `answer` | le texte, avec ses repères |
|
|
40
|
+
|
|
41
|
+
### Parcourir les repères
|
|
42
|
+
|
|
43
|
+
`iter_citations()` rend chaque repère dans l'ordre du texte, avec sa référence et son extrait déjà appariés :
|
|
44
|
+
|
|
45
|
+
```python
|
|
46
|
+
for c in reponse.iter_citations():
|
|
47
|
+
ref = c.reference # Reference, ou None
|
|
48
|
+
extrait = c.passage # Passage, ou None
|
|
49
|
+
print(f"[S{c.n}] repère n° {c.rank} aux signes {c.start}-{c.end}")
|
|
50
|
+
if ref:
|
|
51
|
+
print(" source :", ref.title, ref.url)
|
|
52
|
+
if extrait and extrait.quote:
|
|
53
|
+
print(" extrait :", extrait.quote)
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
`start` et `end` sont les positions du repère dans `answer` : de quoi le remplacer par un lien, voir la recette [Rendre les citations en HTML](recettes.md#rendre-les-citations-en-html).
|
|
57
|
+
|
|
58
|
+
### Les extraits
|
|
59
|
+
|
|
60
|
+
Un `Passage` prend deux formes exclusives :
|
|
61
|
+
|
|
62
|
+
- de la prose : `quote`, avec son contexte `before` et `after` ;
|
|
63
|
+
- une fiche de données (`is_record` vaut `True`) : `record`, liste de lignes `label` / `value`, `cited` marquant celles qui portent un mot de la phrase, et `record_title`.
|
|
64
|
+
|
|
65
|
+
```python
|
|
66
|
+
for p in reponse.passages:
|
|
67
|
+
if p.is_record:
|
|
68
|
+
print(p.record_title)
|
|
69
|
+
for ligne in p.record:
|
|
70
|
+
marque = "→" if ligne.cited else " "
|
|
71
|
+
print(f" {marque} {ligne.label} : {ligne.value}")
|
|
72
|
+
else:
|
|
73
|
+
print(f"…{p.before or ''}«{p.quote}»{p.after or ''}…")
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
Un repère dont l'extrait n'a pas été retrouvé avec assez de certitude n'a pas de passage : jamais un extrait à côté. L'extrait vient de la copie du texte fournie au moteur, pas d'une relecture de la page d'origine.
|
|
77
|
+
|
|
78
|
+
### Bases interrogées sans résultat
|
|
79
|
+
|
|
80
|
+
Une référence dont `empty` vaut `True` est une base consultée qui n'a rien rendu ; `query` dit ce qui a été cherché. La phrase qui la cite rapporte cette absence (« aucune donnée dans… »), ce qui est une information en soi.
|
|
81
|
+
|
|
82
|
+
```python
|
|
83
|
+
for ref in reponse.references:
|
|
84
|
+
if ref.empty:
|
|
85
|
+
print(f"{ref.marker} {ref.tool} : rien sur « {ref.query} »")
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
### Le texte sans repères
|
|
89
|
+
|
|
90
|
+
```python
|
|
91
|
+
texte = reponse.answer_without_markers()
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
Utile pour une synthèse vocale, un SMS, ou un historique de conversation : c'est d'ailleurs ce que fait [`start_conversation`](conversations.md) pour l'historique local.
|
|
95
|
+
|
|
96
|
+
## En flux
|
|
97
|
+
|
|
98
|
+
Avec `ask_stream(..., citations="inline")`, le registre arrive avant le premier mot, dans l'événement `references` : vous pouvez préparer l'affichage des sources pendant que le texte se rédige. Voir [Réponse en flux](flux.md#suivre-chaque-étape).
|