wisemind-client 0.1.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.
- wisemind_client-0.1.0/PKG-INFO +69 -0
- wisemind_client-0.1.0/README.md +55 -0
- wisemind_client-0.1.0/pyproject.toml +22 -0
- wisemind_client-0.1.0/setup.cfg +4 -0
- wisemind_client-0.1.0/wisemind_client/__init__.py +21 -0
- wisemind_client-0.1.0/wisemind_client/cli.py +59 -0
- wisemind_client-0.1.0/wisemind_client/core.py +83 -0
- wisemind_client-0.1.0/wisemind_client/patient.py +55 -0
- wisemind_client-0.1.0/wisemind_client.egg-info/PKG-INFO +69 -0
- wisemind_client-0.1.0/wisemind_client.egg-info/SOURCES.txt +12 -0
- wisemind_client-0.1.0/wisemind_client.egg-info/dependency_links.txt +1 -0
- wisemind_client-0.1.0/wisemind_client.egg-info/entry_points.txt +2 -0
- wisemind_client-0.1.0/wisemind_client.egg-info/requires.txt +3 -0
- wisemind_client-0.1.0/wisemind_client.egg-info/top_level.txt +1 -0
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: wisemind-client
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Client for the WiseMind hosted psychiatric-diagnosis evaluation endpoint (bring your own LLM key).
|
|
5
|
+
License: Proprietary - academic evaluation only, see the WiseMind EULA
|
|
6
|
+
Project-URL: Paper, https://doi.org/10.1038/s41746-026-02559-9
|
|
7
|
+
Classifier: Programming Language :: Python :: 3
|
|
8
|
+
Classifier: Intended Audience :: Science/Research
|
|
9
|
+
Requires-Python: >=3.10
|
|
10
|
+
Description-Content-Type: text/markdown
|
|
11
|
+
Requires-Dist: websockets>=12
|
|
12
|
+
Requires-Dist: pandas>=2.0
|
|
13
|
+
Requires-Dist: openai>=1.0
|
|
14
|
+
|
|
15
|
+
# wisemind-client
|
|
16
|
+
|
|
17
|
+
Python client for the WiseMind hosted evaluation endpoint. You bring your own LLM
|
|
18
|
+
provider key; the server runs WiseMind's agents on it for the duration of one
|
|
19
|
+
interview and never stores it.
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
pip install ./wisemind-client
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Library
|
|
26
|
+
|
|
27
|
+
```python
|
|
28
|
+
from wisemind_client import run_interview, ProfilePatient
|
|
29
|
+
|
|
30
|
+
patient = ProfilePatient("MDD_0.csv", api_key=MY_KEY, provider="deepseek") # or any callable(question) -> reply
|
|
31
|
+
result = run_interview(
|
|
32
|
+
url="wss://HOST/wisemind/ws/diagnostic",
|
|
33
|
+
access_token=TOKEN,
|
|
34
|
+
tree="mdd", # "mdd" | "bp" | "anx"
|
|
35
|
+
backend="deepseek", # provider WiseMind's agents use
|
|
36
|
+
api_keys={"deepseek": MY_KEY},
|
|
37
|
+
patient=patient,
|
|
38
|
+
)
|
|
39
|
+
print(result.diagnosis, result.path, result.turns)
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
`patient` is called once per doctor utterance and returns the patient's reply
|
|
43
|
+
(sync or async). `result.transcript` holds every exchange; `result.node_actions`
|
|
44
|
+
the decision made at each node.
|
|
45
|
+
|
|
46
|
+
## Command line
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
export WISEMIND_URL=wss://HOST/wisemind/ws/diagnostic WISEMIND_ACCESS_TOKEN=...
|
|
50
|
+
export DEEPSEEK_API_KEY=...
|
|
51
|
+
wisemind-eval --tree mdd --profiles profiles/mdd/*.csv --backend deepseek --out results.jsonl
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Prints per-profile verdicts and top-1 accuracy. The ground truth is the file stem
|
|
55
|
+
without its `_N` suffix (`MDD_0.csv` → `MDD`).
|
|
56
|
+
|
|
57
|
+
## Protocol (if you do not use Python)
|
|
58
|
+
|
|
59
|
+
One WebSocket. First frame from the client, JSON:
|
|
60
|
+
|
|
61
|
+
```json
|
|
62
|
+
{"tree_type": "mdd", "llm_type": "deepseek", "ra_llm": "deepseek", "ea_llm": "deepseek",
|
|
63
|
+
"hci": true, "simulated": true, "access_token": "...", "api_keys": {"deepseek": "sk-..."}}
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
Then text frames from the server: `Doctor: ...` (reply with one text frame),
|
|
67
|
+
`Diagnosis Procedure Status: <action>,<node>` (bookkeeping, no reply),
|
|
68
|
+
`Diagnostic complete! Your result is: <LEAF>: <description>\nDiagnostic path: A -> B -> C`
|
|
69
|
+
(end), `Session Ended!\n<reason>` (refusal or failure).
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# wisemind-client
|
|
2
|
+
|
|
3
|
+
Python client for the WiseMind hosted evaluation endpoint. You bring your own LLM
|
|
4
|
+
provider key; the server runs WiseMind's agents on it for the duration of one
|
|
5
|
+
interview and never stores it.
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pip install ./wisemind-client
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Library
|
|
12
|
+
|
|
13
|
+
```python
|
|
14
|
+
from wisemind_client import run_interview, ProfilePatient
|
|
15
|
+
|
|
16
|
+
patient = ProfilePatient("MDD_0.csv", api_key=MY_KEY, provider="deepseek") # or any callable(question) -> reply
|
|
17
|
+
result = run_interview(
|
|
18
|
+
url="wss://HOST/wisemind/ws/diagnostic",
|
|
19
|
+
access_token=TOKEN,
|
|
20
|
+
tree="mdd", # "mdd" | "bp" | "anx"
|
|
21
|
+
backend="deepseek", # provider WiseMind's agents use
|
|
22
|
+
api_keys={"deepseek": MY_KEY},
|
|
23
|
+
patient=patient,
|
|
24
|
+
)
|
|
25
|
+
print(result.diagnosis, result.path, result.turns)
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
`patient` is called once per doctor utterance and returns the patient's reply
|
|
29
|
+
(sync or async). `result.transcript` holds every exchange; `result.node_actions`
|
|
30
|
+
the decision made at each node.
|
|
31
|
+
|
|
32
|
+
## Command line
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
export WISEMIND_URL=wss://HOST/wisemind/ws/diagnostic WISEMIND_ACCESS_TOKEN=...
|
|
36
|
+
export DEEPSEEK_API_KEY=...
|
|
37
|
+
wisemind-eval --tree mdd --profiles profiles/mdd/*.csv --backend deepseek --out results.jsonl
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
Prints per-profile verdicts and top-1 accuracy. The ground truth is the file stem
|
|
41
|
+
without its `_N` suffix (`MDD_0.csv` → `MDD`).
|
|
42
|
+
|
|
43
|
+
## Protocol (if you do not use Python)
|
|
44
|
+
|
|
45
|
+
One WebSocket. First frame from the client, JSON:
|
|
46
|
+
|
|
47
|
+
```json
|
|
48
|
+
{"tree_type": "mdd", "llm_type": "deepseek", "ra_llm": "deepseek", "ea_llm": "deepseek",
|
|
49
|
+
"hci": true, "simulated": true, "access_token": "...", "api_keys": {"deepseek": "sk-..."}}
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
Then text frames from the server: `Doctor: ...` (reply with one text frame),
|
|
53
|
+
`Diagnosis Procedure Status: <action>,<node>` (bookkeeping, no reply),
|
|
54
|
+
`Diagnostic complete! Your result is: <LEAF>: <description>\nDiagnostic path: A -> B -> C`
|
|
55
|
+
(end), `Session Ended!\n<reason>` (refusal or failure).
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=68"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "wisemind-client"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Client for the WiseMind hosted psychiatric-diagnosis evaluation endpoint (bring your own LLM key)."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = {text = "Proprietary - academic evaluation only, see the WiseMind EULA"}
|
|
11
|
+
requires-python = ">=3.10"
|
|
12
|
+
classifiers = ["Programming Language :: Python :: 3", "Intended Audience :: Science/Research"]
|
|
13
|
+
dependencies = ["websockets>=12", "pandas>=2.0", "openai>=1.0"]
|
|
14
|
+
|
|
15
|
+
[project.urls]
|
|
16
|
+
Paper = "https://doi.org/10.1038/s41746-026-02559-9"
|
|
17
|
+
|
|
18
|
+
[project.scripts]
|
|
19
|
+
wisemind-eval = "wisemind_client.cli:main"
|
|
20
|
+
|
|
21
|
+
[tool.setuptools.packages.find]
|
|
22
|
+
include = ["wisemind_client*"]
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"""Client for the WiseMind hosted evaluation endpoint.
|
|
2
|
+
|
|
3
|
+
from wisemind_client import run_interview
|
|
4
|
+
|
|
5
|
+
result = run_interview(
|
|
6
|
+
url="wss://HOST/wisemind/ws/diagnostic",
|
|
7
|
+
access_token="...", # issued by the research team
|
|
8
|
+
tree="mdd", # "mdd" | "bp" | "anx"
|
|
9
|
+
backend="deepseek", # which provider WiseMind's agents run on
|
|
10
|
+
api_keys={"deepseek": "sk-..."}, # YOUR key(s); sent once, held in memory on the server
|
|
11
|
+
patient=my_patient, # callable: doctor_utterance -> patient_reply (sync or async)
|
|
12
|
+
)
|
|
13
|
+
result.diagnosis, result.path, result.turns, result.transcript
|
|
14
|
+
|
|
15
|
+
The server never stores your key. Use a key with a spending limit and revoke it
|
|
16
|
+
after the evaluation.
|
|
17
|
+
"""
|
|
18
|
+
from .core import InterviewResult, run_interview, run_interview_async
|
|
19
|
+
from .patient import ProfilePatient
|
|
20
|
+
|
|
21
|
+
__all__ = ["run_interview", "run_interview_async", "InterviewResult", "ProfilePatient"]
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"""wisemind-eval: run one or many VSP profiles against the hosted endpoint.
|
|
2
|
+
|
|
3
|
+
export WISEMIND_URL=wss://HOST/wisemind/ws/diagnostic WISEMIND_ACCESS_TOKEN=...
|
|
4
|
+
export DEEPSEEK_API_KEY=...
|
|
5
|
+
wisemind-eval --tree mdd --profiles vsp/mdd/*.csv --backend deepseek --out results.jsonl
|
|
6
|
+
"""
|
|
7
|
+
import argparse
|
|
8
|
+
import json
|
|
9
|
+
import os
|
|
10
|
+
import sys
|
|
11
|
+
from pathlib import Path
|
|
12
|
+
|
|
13
|
+
from .core import WiseMindError, run_interview
|
|
14
|
+
from .patient import ProfilePatient
|
|
15
|
+
|
|
16
|
+
KEY_ENV = {"openai": "OPENAI_API_KEY", "deepseek": "DEEPSEEK_API_KEY",
|
|
17
|
+
"anthropic": "ANTHROPIC_API_KEY"}
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def main() -> int:
|
|
21
|
+
ap = argparse.ArgumentParser(prog="wisemind-eval")
|
|
22
|
+
ap.add_argument("--tree", required=True, choices=["mdd", "bp", "anx"])
|
|
23
|
+
ap.add_argument("--profiles", nargs="+", required=True, help="VSP profile CSV(s)")
|
|
24
|
+
ap.add_argument("--backend", default="deepseek", help="provider WiseMind's agents run on")
|
|
25
|
+
ap.add_argument("--patient-provider", default=None, help="provider for the reference patient (default: --backend)")
|
|
26
|
+
ap.add_argument("--url", default=os.getenv("WISEMIND_URL", "ws://127.0.0.1:8000/ws/diagnostic"))
|
|
27
|
+
ap.add_argument("--token", default=os.getenv("WISEMIND_ACCESS_TOKEN", ""))
|
|
28
|
+
ap.add_argument("--out", help="append one JSON record per profile")
|
|
29
|
+
ap.add_argument("--quiet", action="store_true")
|
|
30
|
+
args = ap.parse_args()
|
|
31
|
+
|
|
32
|
+
key = os.environ.get(KEY_ENV.get(args.backend, ""), "")
|
|
33
|
+
if not key:
|
|
34
|
+
sys.exit(f"set {KEY_ENV.get(args.backend, 'the provider key')} in the environment")
|
|
35
|
+
pprov = args.patient_provider or args.backend
|
|
36
|
+
pkey = os.environ.get(KEY_ENV.get(pprov, ""), key)
|
|
37
|
+
|
|
38
|
+
correct = total = 0
|
|
39
|
+
for path in args.profiles:
|
|
40
|
+
gt = Path(path).stem.rsplit("_", 1)[0]
|
|
41
|
+
patient = ProfilePatient(path, api_key=pkey, provider=pprov)
|
|
42
|
+
echo = None if args.quiet else (lambda q, a: print(f" DOCTOR: {q}\n PATIENT: {a}"))
|
|
43
|
+
try:
|
|
44
|
+
r = run_interview(args.url, args.token, args.tree, args.backend,
|
|
45
|
+
{args.backend: key}, patient, on_turn=echo)
|
|
46
|
+
except WiseMindError as exc:
|
|
47
|
+
print(f"[{gt}] ERROR {exc}")
|
|
48
|
+
continue
|
|
49
|
+
total += 1
|
|
50
|
+
correct += int(r.diagnosis == gt)
|
|
51
|
+
print(f"[{gt}] pred={r.diagnosis} correct={r.diagnosis == gt} turns={r.turns}")
|
|
52
|
+
if args.out:
|
|
53
|
+
with open(args.out, "a") as f:
|
|
54
|
+
f.write(json.dumps({"profile": Path(path).name, "gt": gt, "pred": r.diagnosis,
|
|
55
|
+
"correct": r.diagnosis == gt, "turns": r.turns, "path": r.path,
|
|
56
|
+
"transcript": r.transcript}) + "\n")
|
|
57
|
+
if total:
|
|
58
|
+
print(f"top-1 accuracy: {correct}/{total}")
|
|
59
|
+
return 0
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import asyncio
|
|
2
|
+
import inspect
|
|
3
|
+
import json
|
|
4
|
+
from dataclasses import dataclass, field
|
|
5
|
+
from typing import Awaitable, Callable, Dict, List, Optional, Union
|
|
6
|
+
|
|
7
|
+
import websockets
|
|
8
|
+
|
|
9
|
+
COMPLETE = "Diagnostic complete!"
|
|
10
|
+
ENDED = "Session Ended!"
|
|
11
|
+
STATUS = "Diagnosis Procedure Status:"
|
|
12
|
+
SAFETY = "Safety Notice!"
|
|
13
|
+
|
|
14
|
+
Patient = Callable[[str], Union[str, Awaitable[str]]]
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class WiseMindError(RuntimeError):
|
|
18
|
+
"""The server refused or ended the session (bad token, missing key, failure)."""
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
@dataclass
|
|
22
|
+
class InterviewResult:
|
|
23
|
+
diagnosis: str
|
|
24
|
+
description: str
|
|
25
|
+
path: List[str]
|
|
26
|
+
turns: int
|
|
27
|
+
transcript: List[Dict[str, str]] = field(default_factory=list) # [{"doctor": ..., "patient": ...}]
|
|
28
|
+
node_actions: List[Dict[str, str]] = field(default_factory=list) # [{"node": ..., "action": ...}]
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def _parse_complete(frame: str):
|
|
32
|
+
# "Diagnostic complete! Your result is: MDD: Major depressive disorder\nDiagnostic path: A -> B -> C"
|
|
33
|
+
head, _, tail = frame.partition("\nDiagnostic path:")
|
|
34
|
+
verdict = head.split("Your result is:", 1)[1].strip() if "Your result is:" in head else head
|
|
35
|
+
diagnosis, _, description = verdict.partition(":")
|
|
36
|
+
path = [p.strip() for p in tail.split("->") if p.strip()]
|
|
37
|
+
return diagnosis.strip(), description.strip(), path
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
async def run_interview_async(url: str, access_token: str, tree: str, backend: str,
|
|
41
|
+
api_keys: Dict[str, str], patient: Patient,
|
|
42
|
+
ra_backend: Optional[str] = None, ea_backend: Optional[str] = None,
|
|
43
|
+
simulated: bool = True, on_turn: Optional[Callable] = None,
|
|
44
|
+
ping_timeout: float = 300) -> InterviewResult:
|
|
45
|
+
"""Run one interview. `patient` receives each doctor utterance and returns the reply."""
|
|
46
|
+
setup = {
|
|
47
|
+
"tree_type": tree, "llm_type": backend,
|
|
48
|
+
"ra_llm": ra_backend or backend, "ea_llm": ea_backend or backend,
|
|
49
|
+
"hci": True, "simulated": simulated,
|
|
50
|
+
"access_token": access_token, "api_keys": api_keys,
|
|
51
|
+
}
|
|
52
|
+
transcript, actions, turns = [], [], 0
|
|
53
|
+
async with websockets.connect(url, max_size=2**20, ping_interval=20,
|
|
54
|
+
ping_timeout=ping_timeout) as ws:
|
|
55
|
+
await ws.send(json.dumps(setup))
|
|
56
|
+
async for frame in ws:
|
|
57
|
+
if frame.startswith(COMPLETE):
|
|
58
|
+
diagnosis, description, path = _parse_complete(frame)
|
|
59
|
+
return InterviewResult(diagnosis, description, path, turns, transcript, actions)
|
|
60
|
+
if frame.startswith(ENDED):
|
|
61
|
+
raise WiseMindError(frame[len(ENDED):].strip())
|
|
62
|
+
if frame.startswith(STATUS):
|
|
63
|
+
action, _, node = frame[len(STATUS):].strip().partition(",")
|
|
64
|
+
actions.append({"node": node, "action": action})
|
|
65
|
+
continue
|
|
66
|
+
if frame.startswith(SAFETY):
|
|
67
|
+
continue
|
|
68
|
+
question = frame[len("Doctor: "):] if frame.startswith("Doctor: ") else frame
|
|
69
|
+
reply = patient(question)
|
|
70
|
+
if inspect.isawaitable(reply):
|
|
71
|
+
reply = await reply
|
|
72
|
+
reply = str(reply).strip()
|
|
73
|
+
transcript.append({"doctor": question, "patient": reply})
|
|
74
|
+
turns += 1
|
|
75
|
+
if on_turn:
|
|
76
|
+
on_turn(question, reply)
|
|
77
|
+
await ws.send(reply)
|
|
78
|
+
raise WiseMindError("connection closed before the interview completed")
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def run_interview(*args, **kwargs) -> InterviewResult:
|
|
82
|
+
"""Synchronous wrapper around run_interview_async."""
|
|
83
|
+
return asyncio.run(run_interview_async(*args, **kwargs))
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"""A reference simulated patient that answers from a VSP profile CSV with an LLM.
|
|
2
|
+
|
|
3
|
+
Replace it with your own simulator: anything callable as `reply = patient(question)`.
|
|
4
|
+
"""
|
|
5
|
+
from typing import Optional
|
|
6
|
+
|
|
7
|
+
import pandas as pd
|
|
8
|
+
from openai import AsyncOpenAI
|
|
9
|
+
|
|
10
|
+
PROVIDERS = {
|
|
11
|
+
"openai": {"base_url": None, "model": "gpt-4o-2024-11-20"},
|
|
12
|
+
"deepseek": {"base_url": "https://api.deepseek.com/v1", "model": "deepseek-chat"},
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
SYSTEM = (
|
|
16
|
+
"You are role-playing a patient in a psychiatric interview. You answer ONLY from your profile.\n"
|
|
17
|
+
"Steps for every doctor message: (1) decide which symptom_area(s) it asks about; (2) if every "
|
|
18
|
+
"matching area says you_have_this: NO, or nothing matches, give a plain denial in the patient's "
|
|
19
|
+
"voice; (3) if an area says YES, answer only with facts from its your_experience, in your own words; "
|
|
20
|
+
"(4) small talk or greetings: answer like an ordinary person, briefly. Never invent symptoms, "
|
|
21
|
+
"events or durations that are not in the profile, never exaggerate, never use diagnostic labels, "
|
|
22
|
+
"never mention that you have a profile. 1 to 3 natural sentences.\n\nYOUR PROFILE:\n{profile}"
|
|
23
|
+
)
|
|
24
|
+
USER = "DIALOGUE SO FAR:\n{dialogue}\n\nTHE DOCTOR JUST SAID:\n{question}\n\nAnswer as the patient."
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def render_profile(path: str) -> str:
|
|
28
|
+
df = pd.read_csv(path, keep_default_na=False)
|
|
29
|
+
rows = []
|
|
30
|
+
for _, r in df.iterrows():
|
|
31
|
+
met = str(r.Met_Criteria).strip().upper() in ("TRUE", "YES", "1")
|
|
32
|
+
rows.append(f"- symptom_area: {r.Description}\n you_have_this: {'YES' if met else 'NO'}\n"
|
|
33
|
+
f" your_experience: {r.Patient_Story or 'NONE'}")
|
|
34
|
+
return "\n".join(rows)
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
class ProfilePatient:
|
|
38
|
+
def __init__(self, profile_csv: str, api_key: str, provider: str = "deepseek",
|
|
39
|
+
model: Optional[str] = None, temperature: float = 0.2):
|
|
40
|
+
spec = PROVIDERS[provider]
|
|
41
|
+
self.llm = AsyncOpenAI(api_key=api_key, base_url=spec["base_url"])
|
|
42
|
+
self.model = model or spec["model"]
|
|
43
|
+
self.temperature = temperature
|
|
44
|
+
self.system = SYSTEM.format(profile=render_profile(profile_csv))
|
|
45
|
+
self.history = []
|
|
46
|
+
|
|
47
|
+
async def __call__(self, question: str) -> str:
|
|
48
|
+
dialogue = "\n".join(self.history[-16:]) or "(start of interview)"
|
|
49
|
+
resp = await self.llm.chat.completions.create(
|
|
50
|
+
model=self.model, temperature=self.temperature,
|
|
51
|
+
messages=[{"role": "system", "content": self.system},
|
|
52
|
+
{"role": "user", "content": USER.format(dialogue=dialogue, question=question)}])
|
|
53
|
+
answer = resp.choices[0].message.content.strip()
|
|
54
|
+
self.history += [f"Doctor: {question}", f"Patient: {answer}"]
|
|
55
|
+
return answer
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: wisemind-client
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Client for the WiseMind hosted psychiatric-diagnosis evaluation endpoint (bring your own LLM key).
|
|
5
|
+
License: Proprietary - academic evaluation only, see the WiseMind EULA
|
|
6
|
+
Project-URL: Paper, https://doi.org/10.1038/s41746-026-02559-9
|
|
7
|
+
Classifier: Programming Language :: Python :: 3
|
|
8
|
+
Classifier: Intended Audience :: Science/Research
|
|
9
|
+
Requires-Python: >=3.10
|
|
10
|
+
Description-Content-Type: text/markdown
|
|
11
|
+
Requires-Dist: websockets>=12
|
|
12
|
+
Requires-Dist: pandas>=2.0
|
|
13
|
+
Requires-Dist: openai>=1.0
|
|
14
|
+
|
|
15
|
+
# wisemind-client
|
|
16
|
+
|
|
17
|
+
Python client for the WiseMind hosted evaluation endpoint. You bring your own LLM
|
|
18
|
+
provider key; the server runs WiseMind's agents on it for the duration of one
|
|
19
|
+
interview and never stores it.
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
pip install ./wisemind-client
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Library
|
|
26
|
+
|
|
27
|
+
```python
|
|
28
|
+
from wisemind_client import run_interview, ProfilePatient
|
|
29
|
+
|
|
30
|
+
patient = ProfilePatient("MDD_0.csv", api_key=MY_KEY, provider="deepseek") # or any callable(question) -> reply
|
|
31
|
+
result = run_interview(
|
|
32
|
+
url="wss://HOST/wisemind/ws/diagnostic",
|
|
33
|
+
access_token=TOKEN,
|
|
34
|
+
tree="mdd", # "mdd" | "bp" | "anx"
|
|
35
|
+
backend="deepseek", # provider WiseMind's agents use
|
|
36
|
+
api_keys={"deepseek": MY_KEY},
|
|
37
|
+
patient=patient,
|
|
38
|
+
)
|
|
39
|
+
print(result.diagnosis, result.path, result.turns)
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
`patient` is called once per doctor utterance and returns the patient's reply
|
|
43
|
+
(sync or async). `result.transcript` holds every exchange; `result.node_actions`
|
|
44
|
+
the decision made at each node.
|
|
45
|
+
|
|
46
|
+
## Command line
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
export WISEMIND_URL=wss://HOST/wisemind/ws/diagnostic WISEMIND_ACCESS_TOKEN=...
|
|
50
|
+
export DEEPSEEK_API_KEY=...
|
|
51
|
+
wisemind-eval --tree mdd --profiles profiles/mdd/*.csv --backend deepseek --out results.jsonl
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Prints per-profile verdicts and top-1 accuracy. The ground truth is the file stem
|
|
55
|
+
without its `_N` suffix (`MDD_0.csv` → `MDD`).
|
|
56
|
+
|
|
57
|
+
## Protocol (if you do not use Python)
|
|
58
|
+
|
|
59
|
+
One WebSocket. First frame from the client, JSON:
|
|
60
|
+
|
|
61
|
+
```json
|
|
62
|
+
{"tree_type": "mdd", "llm_type": "deepseek", "ra_llm": "deepseek", "ea_llm": "deepseek",
|
|
63
|
+
"hci": true, "simulated": true, "access_token": "...", "api_keys": {"deepseek": "sk-..."}}
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
Then text frames from the server: `Doctor: ...` (reply with one text frame),
|
|
67
|
+
`Diagnosis Procedure Status: <action>,<node>` (bookkeeping, no reply),
|
|
68
|
+
`Diagnostic complete! Your result is: <LEAF>: <description>\nDiagnostic path: A -> B -> C`
|
|
69
|
+
(end), `Session Ended!\n<reason>` (refusal or failure).
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
README.md
|
|
2
|
+
pyproject.toml
|
|
3
|
+
wisemind_client/__init__.py
|
|
4
|
+
wisemind_client/cli.py
|
|
5
|
+
wisemind_client/core.py
|
|
6
|
+
wisemind_client/patient.py
|
|
7
|
+
wisemind_client.egg-info/PKG-INFO
|
|
8
|
+
wisemind_client.egg-info/SOURCES.txt
|
|
9
|
+
wisemind_client.egg-info/dependency_links.txt
|
|
10
|
+
wisemind_client.egg-info/entry_points.txt
|
|
11
|
+
wisemind_client.egg-info/requires.txt
|
|
12
|
+
wisemind_client.egg-info/top_level.txt
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
wisemind_client
|