-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFHIRBot.py
60 lines (50 loc) · 1.73 KB
/
FHIRBot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#This code was optimised for Google Colab.
!pip install groq
!pip install gradio
from groq import Groq
from google.colab import userdata
import gradio as gr
from groq import Groq
from google.colab import userdata
import gspread
from google.auth import default
from google.colab import auth
# Setting up Gradio UI elements.
def ask_fhir_question_gradio(question):
"""
Asks a question about FHIR to the LLM and saves the conversation in Google Sheets.
"""
client = Groq(api_key=userdata.get('Groq_Key'))
completion = client.chat.completions.create(
model="llama-3.2-90b-text-preview",
messages=[
{
"role": "system",
"content": "You are an expert on the FHIR documentation and can help healthcare developers quickly with any query about the FHIR protocol. Scrap every single sub-page on this website https://hl7.org/fhir/documentation.html and provide answers to the healthcare developers only faculty accurate answers from the website. Don't hallucinate. "
},
{
"role": "user",
"content": question
}
],
temperature=1,
max_tokens=1024,
top_p=1,
stream=True,
stop=None,
)
answer = ""
for chunk in completion:
answer += chunk.choices[0].delta.content or ""
# Save the question and answer to Google Sheets
row = [question, answer]
worksheet.append_row(row)
return answer
iface = gr.Interface(
fn=ask_fhir_question_gradio,
inputs=gr.Textbox(lines=2, placeholder="Ask your FHIR question here..."),
outputs="text",
title="FHIR Chatbot",
description="Ask any question about the FHIR protocol."
)
iface.launch(share=True)