Skip to content

Commit ed95b58

Browse files
committed
Committing my hacky code
0 parents  commit ed95b58

File tree

9 files changed

+12195
-0
lines changed

9 files changed

+12195
-0
lines changed

.DS_Store

6 KB
Binary file not shown.

.gitignore

Lines changed: 182 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
1+
2+
# Byte-compiled / optimized / DLL files
3+
__pycache__/
4+
*.py[cod]
5+
*$py.class
6+
7+
# C extensions
8+
*.so
9+
10+
# Distribution / packaging
11+
.Python
12+
build/
13+
develop-eggs/
14+
dist/
15+
downloads/
16+
eggs/
17+
.eggs/
18+
lib/
19+
lib64/
20+
parts/
21+
sdist/
22+
var/
23+
wheels/
24+
share/python-wheels/
25+
*.egg-info/
26+
.installed.cfg
27+
*.egg
28+
MANIFEST
29+
30+
# PyInstaller
31+
# Usually these files are written by a python script from a template
32+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
33+
*.manifest
34+
*.spec
35+
36+
# Installer logs
37+
pip-log.txt
38+
pip-delete-this-directory.txt
39+
40+
# Unit test / coverage reports
41+
htmlcov/
42+
.tox/
43+
.nox/
44+
.coverage
45+
.coverage.*
46+
.cache
47+
nosetests.xml
48+
coverage.xml
49+
*.cover
50+
*.py,cover
51+
.hypothesis/
52+
.pytest_cache/
53+
cover/
54+
55+
# Translations
56+
*.mo
57+
*.pot
58+
59+
# Django stuff:
60+
*.log
61+
local_settings.py
62+
db.sqlite3
63+
db.sqlite3-journal
64+
65+
# Flask stuff:
66+
instance/
67+
.webassets-cache
68+
69+
# Scrapy stuff:
70+
.scrapy
71+
72+
# Sphinx documentation
73+
docs/_build/
74+
75+
# PyBuilder
76+
.pybuilder/
77+
target/
78+
79+
# Jupyter Notebook
80+
.ipynb_checkpoints
81+
82+
# IPython
83+
profile_default/
84+
ipython_config.py
85+
86+
# pyenv
87+
# For a library or package, you might want to ignore these files since the code is
88+
# intended to run in multiple environments; otherwise, check them in:
89+
# .python-version
90+
91+
# pipenv
92+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
93+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
94+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
95+
# install all needed dependencies.
96+
#Pipfile.lock
97+
98+
# UV
99+
# Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
100+
# This is especially recommended for binary packages to ensure reproducibility, and is more
101+
# commonly ignored for libraries.
102+
#uv.lock
103+
104+
# poetry
105+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
106+
# This is especially recommended for binary packages to ensure reproducibility, and is more
107+
# commonly ignored for libraries.
108+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
109+
#poetry.lock
110+
111+
# pdm
112+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
113+
#pdm.lock
114+
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
115+
# in version control.
116+
# https://pdm.fming.dev/latest/usage/project/#working-with-version-control
117+
.pdm.toml
118+
.pdm-python
119+
.pdm-build/
120+
121+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
122+
__pypackages__/
123+
124+
# Celery stuff
125+
celerybeat-schedule
126+
celerybeat.pid
127+
128+
# SageMath parsed files
129+
*.sage.py
130+
131+
# Environments
132+
.env
133+
.venv
134+
env/
135+
venv/
136+
ENV/
137+
env.bak/
138+
venv.bak/
139+
140+
# Spyder project settings
141+
.spyderproject
142+
.spyproject
143+
144+
# Rope project settings
145+
.ropeproject
146+
147+
# mkdocs documentation
148+
/site
149+
150+
# mypy
151+
.mypy_cache/
152+
.dmypy.json
153+
dmypy.json
154+
155+
# Pyre type checker
156+
.pyre/
157+
158+
# pytype static type analyzer
159+
.pytype/
160+
161+
# Cython debug symbols
162+
cython_debug/
163+
164+
# PyCharm
165+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
166+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
167+
# and can be added to the global gitignore or merged into this file. For a more nuclear
168+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
169+
#.idea/
170+
171+
# Ruff stuff:
172+
.ruff_cache/
173+
174+
# PyPI configuration file
175+
.pypirc
176+
177+
# Cursor
178+
# Cursor is an AI-powered code editor.`.cursorignore` specifies files/directories to
179+
# exclude from AI features like autocomplete and code analysis. Recommended for sensitive data
180+
# refer to https://docs.cursor.com/context/ignore-files
181+
.cursorignore
182+
.cursorindexingignore

.tool-versions

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
python 3.12.7
2+
poetry 2.1.1

cli/main.py

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
from langchain_core.messages import HumanMessage, SystemMessage
2+
from langchain_aws import BedrockLLM, ChatBedrock
3+
import typer
4+
import logging
5+
import pathlib
6+
import speech_recognition as sr
7+
8+
logging.basicConfig(level=logging.INFO)
9+
10+
app = typer.Typer()
11+
12+
ALL_PATHWAYS = pathlib.Path("pathways(out).txt").read_text()
13+
14+
15+
def get_llm():
16+
return ChatBedrock(model="anthropic.claude-3-haiku-20240307-v1:0")
17+
18+
19+
def get_system_prompt():
20+
return SystemMessage(
21+
content=(
22+
"You are a medical assistant. Given a their symptoms, you will provide an initial triage. Always convert the users terms into the most accurate clinical terminology. "
23+
"If you are unsure, always ask the user a question for more information before making a recommendation. "
24+
"You will provide a list of symptoms weighted by their severity. "
25+
"You will also provide a recommended pathway that the user should follow. Only one pathway should be selected and it should be from the list below. "
26+
"Never return a pathway that is not in the list. "
27+
"All pathways are listed below:\n\n"
28+
f"{ALL_PATHWAYS}\n\n"
29+
"When you are ready to provide an answer, return a JSON object with the following keys: "
30+
"'symptoms' (a list of symptoms with their severity) and 'pathway' (the recommended pathway). "
31+
"The 'symptoms' key should be a list of JSON objects with the following keys: "
32+
"'symptom' (the symptom name), 'severity' (a score from 1 to 10), and 'body_part' (the body part affected). "
33+
"The 'pathway' key should be a string with the recommended pathway ID. "
34+
"Provide only the JSON object in the response, without any additional text or explanation. "
35+
"\nExamples: "
36+
"\nInput: 'I have a fever and a sore throat.'"
37+
"\nOutput: {'symptoms': [{'symptom': 'fever', 'severity': 8, 'body_part': null}, {'symptom': 'sore throat', 'severity': 5, 'body_part': 'throat'}], 'pathway': 'PW_12345'}"
38+
)
39+
)
40+
41+
42+
@app.command()
43+
def text():
44+
"""
45+
Run the LLM in text mode.
46+
"""
47+
llm = get_llm()
48+
system_prompt = get_system_prompt()
49+
50+
messages = [system_prompt]
51+
52+
while (user_in := input("User: ")) != "exit":
53+
messages.append(HumanMessage(content=user_in))
54+
ai_msg = llm.predict_messages(messages)
55+
print(ai_msg.content)
56+
57+
58+
@app.command()
59+
def voice():
60+
"""
61+
Run the LLM in voice mode.
62+
"""
63+
with sr.Microphone() as source:
64+
recognizer = sr.Recognizer()
65+
recognizer.adjust_for_ambient_noise(source)
66+
print("Listening...")
67+
audio = recognizer.listen(source)
68+
69+
print("Recognizing...")
70+
text = recognizer.recognize_whisper(audio, language="en")
71+
72+
print("You said:", text)
73+
print("Processing...")
74+
75+
llm = get_llm()
76+
system_prompt = get_system_prompt()
77+
78+
messages = [system_prompt, HumanMessage(content=text)]
79+
ai_msg = llm.predict_messages(messages)
80+
print(ai_msg.content)
81+
82+
83+
if __name__ == "__main__":
84+
app()
85+
86+
# while (user_in := input("User: ")) != "exit":
87+
# messages.append(HumanMessage(content=user_in))
88+
# ai_msg = llm.predict_messages(messages)
89+
90+
# print(ai_msg.content)

0 commit comments

Comments
 (0)