Spaces:
Paused
Paused
Changed to CCE Study Guide Bot
Browse files- .DS_Store +0 -0
- .chainlit/config.toml +66 -0
- .gitattributes +1 -0
- CCE_local_studyguide_index/index.faiss +3 -0
- CCE_local_studyguide_index/index.pkl +3 -0
- app.py +36 -47
- chainlit.md +2 -4
- requirements.txt +3 -0
.DS_Store
CHANGED
Binary files a/.DS_Store and b/.DS_Store differ
|
|
.chainlit/config.toml
ADDED
@@ -0,0 +1,66 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
[project]
|
2 |
+
# Whether to enable telemetry (default: true). No personal data is collected.
|
3 |
+
enable_telemetry = true
|
4 |
+
|
5 |
+
# List of environment variables to be provided by each user to use the app.
|
6 |
+
user_env = []
|
7 |
+
|
8 |
+
# Duration (in seconds) during which the session is saved when the connection is lost
|
9 |
+
session_timeout = 3600
|
10 |
+
|
11 |
+
# Enable third parties caching (e.g LangChain cache)
|
12 |
+
cache = false
|
13 |
+
|
14 |
+
# Follow symlink for asset mount (see https://github.com/Chainlit/chainlit/issues/317)
|
15 |
+
# follow_symlink = false
|
16 |
+
|
17 |
+
[features]
|
18 |
+
# Show the prompt playground
|
19 |
+
prompt_playground = true
|
20 |
+
|
21 |
+
[UI]
|
22 |
+
# Name of the app and chatbot.
|
23 |
+
name = "Chatbot"
|
24 |
+
|
25 |
+
# Description of the app and chatbot. This is used for HTML tags.
|
26 |
+
# description = ""
|
27 |
+
|
28 |
+
# Large size content are by default collapsed for a cleaner ui
|
29 |
+
default_collapse_content = true
|
30 |
+
|
31 |
+
# The default value for the expand messages settings.
|
32 |
+
default_expand_messages = false
|
33 |
+
|
34 |
+
# Hide the chain of thought details from the user in the UI.
|
35 |
+
hide_cot = false
|
36 |
+
|
37 |
+
# Link to your github repo. This will add a github button in the UI's header.
|
38 |
+
# github = ""
|
39 |
+
|
40 |
+
# Specify a CSS file that can be used to customize the user interface.
|
41 |
+
# The CSS file can be served from the public directory or via an external link.
|
42 |
+
# custom_css = "/public/test.css"
|
43 |
+
|
44 |
+
# Override default MUI light theme. (Check theme.ts)
|
45 |
+
[UI.theme.light]
|
46 |
+
#background = "#FAFAFA"
|
47 |
+
#paper = "#FFFFFF"
|
48 |
+
|
49 |
+
[UI.theme.light.primary]
|
50 |
+
#main = "#F80061"
|
51 |
+
#dark = "#980039"
|
52 |
+
#light = "#FFE7EB"
|
53 |
+
|
54 |
+
# Override default MUI dark theme. (Check theme.ts)
|
55 |
+
[UI.theme.dark]
|
56 |
+
#background = "#FAFAFA"
|
57 |
+
#paper = "#FFFFFF"
|
58 |
+
|
59 |
+
[UI.theme.dark.primary]
|
60 |
+
#main = "#F80061"
|
61 |
+
#dark = "#980039"
|
62 |
+
#light = "#FFE7EB"
|
63 |
+
|
64 |
+
|
65 |
+
[meta]
|
66 |
+
generated_by = "0.7.2"
|
.gitattributes
CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
36 |
+
CCE_local_studyguide_index/**/* filter=lfs diff=lfs merge=lfs -text
|
CCE_local_studyguide_index/index.faiss
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:53a28540374bbdf39131e14876078daf7e0aefd32143d4c5ed3773897c9b18b3
|
3 |
+
size 1615917
|
CCE_local_studyguide_index/index.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:a0f84577e67fd7b3e56b594db4397aecbfd56e1699c87de71ece15de0fcf399f
|
3 |
+
size 645420
|
app.py
CHANGED
@@ -8,6 +8,12 @@ from chainlit.input_widget import Select, Switch, Slider #importing chainlit set
|
|
8 |
from chainlit.prompt import Prompt, PromptMessage #importing prompt tools
|
9 |
from chainlit.playground.providers import ChatOpenAI #importing ChatOpenAI tools
|
10 |
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
# You only need the api key inserted here if it's not in your .env file
|
12 |
#openai.api_key = "YOUR_API_KEY"
|
13 |
|
@@ -18,56 +24,39 @@ system_template = """You are the greatest wizard the world has ever known. You l
|
|
18 |
user_template = """{input}
|
19 |
"""
|
20 |
|
|
|
|
|
|
|
|
|
|
|
21 |
@cl.on_chat_start # marks a function that will be executed at the start of a user session
|
22 |
async def start_chat():
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
"
|
29 |
-
"
|
30 |
-
|
31 |
-
|
32 |
-
cl.user_session.set("settings", settings)
|
33 |
-
|
34 |
-
@cl.on_message # marks a function that should be run each time the chatbot receives a message from a user
|
35 |
-
async def main(message: str):
|
36 |
-
|
37 |
-
settings = cl.user_session.get("settings")
|
38 |
-
|
39 |
-
prompt = Prompt(
|
40 |
-
provider=ChatOpenAI.id,
|
41 |
-
messages=[
|
42 |
-
PromptMessage(
|
43 |
-
role="system",
|
44 |
-
template=system_template,
|
45 |
-
formatted=system_template,
|
46 |
-
),
|
47 |
-
PromptMessage(
|
48 |
-
role="user",
|
49 |
-
template=user_template,
|
50 |
-
formatted=user_template.format(input=message),
|
51 |
-
)
|
52 |
-
],
|
53 |
-
inputs = {"input" : message},
|
54 |
-
settings=settings
|
55 |
)
|
|
|
|
|
|
|
56 |
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
)
|
65 |
-
token = stream_resp.choices[0]["delta"].get("content", "")
|
66 |
-
await msg.stream_token(token)
|
67 |
|
68 |
-
|
69 |
-
prompt.completion = msg.content
|
70 |
-
msg.prompt = prompt
|
71 |
|
72 |
-
|
73 |
-
|
|
|
|
|
|
8 |
from chainlit.prompt import Prompt, PromptMessage #importing prompt tools
|
9 |
from chainlit.playground.providers import ChatOpenAI #importing ChatOpenAI tools
|
10 |
|
11 |
+
from langchain.embeddings.openai import OpenAIEmbeddings
|
12 |
+
from langchain.chains import RetrievalQA
|
13 |
+
from langchain.vectorstores import FAISS
|
14 |
+
from langchain.chat_models import ChatOpenAI
|
15 |
+
from langchain.prompts import ChatPromptTemplate
|
16 |
+
|
17 |
# You only need the api key inserted here if it's not in your .env file
|
18 |
#openai.api_key = "YOUR_API_KEY"
|
19 |
|
|
|
24 |
user_template = """{input}
|
25 |
"""
|
26 |
|
27 |
+
@cl.author_rename
|
28 |
+
def rename(orig_author: str):
|
29 |
+
rename_dict = {"RetrievalQA": "The Study Guide", "Chatbot": "Certified Clinical Engineer Study Guide Assistant"}
|
30 |
+
return rename_dict.get(orig_author, orig_author)
|
31 |
+
|
32 |
@cl.on_chat_start # marks a function that will be executed at the start of a user session
|
33 |
async def start_chat():
|
34 |
+
msg=cl.Message(content=f"Starting up.")
|
35 |
+
await msg.send()
|
36 |
+
embeddings_model = OpenAIEmbeddings()
|
37 |
+
study_guide_index = FAISS.load_local("CCE_local_studyguide_index",embeddings_model)
|
38 |
+
chain = RetrievalQA.from_chain_type(
|
39 |
+
ChatOpenAI(model="gpt-3.5-turbo", temperature=0, streaming=True),
|
40 |
+
chain_type="stuff",
|
41 |
+
return_source_documents=True,
|
42 |
+
retriever=study_guide_index.as_retriever(),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
43 |
)
|
44 |
+
msg=cl.Message(content=f"Finished.")
|
45 |
+
await msg.send()
|
46 |
+
cl.user_session.set("chain", chain)
|
47 |
|
48 |
+
@cl.on_message
|
49 |
+
async def main(message):
|
50 |
+
chain = cl.user_session.get("chain")
|
51 |
+
cb = cl.AsyncLangchainCallbackHandler(
|
52 |
+
stream_final_answer=True, answer_prefix_tokens=["FINAL", "ANSWER"]
|
53 |
+
)
|
54 |
+
cb.answer_reached = True
|
55 |
+
res = await chain.acall(message, callbacks=[cb])
|
|
|
|
|
56 |
|
57 |
+
answer = res["result"]
|
|
|
|
|
58 |
|
59 |
+
if cb.has_streamed_final_answer:
|
60 |
+
await cb.final_stream.update()
|
61 |
+
else:
|
62 |
+
await cl.Message(content=answer).send()
|
chainlit.md
CHANGED
@@ -1,5 +1,3 @@
|
|
1 |
-
# Beyond ChatGPT -
|
2 |
|
3 |
-
|
4 |
-
|
5 |
-
Consult him and he may grant you his Wisdom!
|
|
|
1 |
+
# Beyond ChatGPT - Certified Clinical Engineer Study Guide Assistant
|
2 |
|
3 |
+
Study Guide Assistant! Based on CCE Study Guide v11 from ACCE.
|
|
|
|
requirements.txt
CHANGED
@@ -1,2 +1,5 @@
|
|
1 |
chainlit
|
2 |
openai
|
|
|
|
|
|
|
|
1 |
chainlit
|
2 |
openai
|
3 |
+
langchain
|
4 |
+
faiss_cpu
|
5 |
+
tiktoken
|