Spaces:
Sleeping
Sleeping
physics bot
Browse files- .gitattributes +2 -0
- Dockerfile +20 -0
- physics_bot/chainlit.md +14 -0
- physics_bot/faiss_index/index.faiss +3 -0
- physics_bot/faiss_index/index.pkl +3 -0
- physics_bot/physics_app.py +56 -0
- requirements.txt +6 -0
.gitattributes
CHANGED
|
@@ -33,3 +33,5 @@ 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 |
+
physics_bot/faiss_index/index.faiss filter=lfs diff=lfs merge=lfs -text
|
| 37 |
+
physics_bot/faiss_index/index.pkl filter=lfs diff=lfs merge=lfs -text
|
Dockerfile
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM python:3.9
|
| 2 |
+
|
| 3 |
+
WORKDIR /code
|
| 4 |
+
|
| 5 |
+
COPY ./requirements.txt /code/requirements.txt
|
| 6 |
+
|
| 7 |
+
RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
|
| 8 |
+
|
| 9 |
+
RUN useradd -m -u 1000 user
|
| 10 |
+
USER user
|
| 11 |
+
ENV HOME=/home/user \
|
| 12 |
+
PATH=/home/user/.local/bin:$PATH
|
| 13 |
+
|
| 14 |
+
WORKDIR $HOME/physics_bot
|
| 15 |
+
|
| 16 |
+
RUN chown -R user:user $HOME/physics_bot
|
| 17 |
+
|
| 18 |
+
ADD physics_bot $HOME/physics_bot
|
| 19 |
+
|
| 20 |
+
CMD ["chainlit", "run", "app.py", "--host", "0.0.0.0", "--port", "7860"]
|
physics_bot/chainlit.md
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Welcome to Chainlit! 🚀🤖
|
| 2 |
+
|
| 3 |
+
Hi there, Developer! 👋 We're excited to have you on board. Chainlit is a powerful tool designed to help you prototype, debug and share applications built on top of LLMs.
|
| 4 |
+
|
| 5 |
+
## Useful Links 🔗
|
| 6 |
+
|
| 7 |
+
- **Documentation:** Get started with our comprehensive [Chainlit Documentation](https://docs.chainlit.io) 📚
|
| 8 |
+
- **Discord Community:** Join our friendly [Chainlit Discord](https://discord.gg/k73SQ3FyUh) to ask questions, share your projects, and connect with other developers! 💬
|
| 9 |
+
|
| 10 |
+
We can't wait to see what you create with Chainlit! Happy coding! 💻😊
|
| 11 |
+
|
| 12 |
+
## Welcome screen
|
| 13 |
+
|
| 14 |
+
To modify the welcome screen, edit the `chainlit.md` file at the root of your project. If you do not want a welcome screen, just leave this file empty.
|
physics_bot/faiss_index/index.faiss
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:c7a1cc5ce370f0500a4dca5086dd4f140ac3d3788f0a6b3821d6c0cc10d75b87
|
| 3 |
+
size 1105965
|
physics_bot/faiss_index/index.pkl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:4c3f3fc8c3a888d691da14142d54c5599fe112c9ee4dcaa427d6fad10c922f35
|
| 3 |
+
size 87480
|
physics_bot/physics_app.py
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from langchain_community.chat_models import ChatOpenAI
|
| 2 |
+
from langchain.prompts import ChatPromptTemplate
|
| 3 |
+
from langchain.schema import StrOutputParser
|
| 4 |
+
from langchain.schema.runnable import Runnable
|
| 5 |
+
from langchain.schema.runnable.config import RunnableConfig
|
| 6 |
+
import chainlit as cl
|
| 7 |
+
from langchain_community.embeddings import OpenAIEmbeddings
|
| 8 |
+
from langchain_core.prompts import PromptTemplate
|
| 9 |
+
from langchain_community.vectorstores import FAISS
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
@cl.on_chat_start
|
| 13 |
+
async def on_chat_start():
|
| 14 |
+
embeddings = OpenAIEmbeddings(model="text-embedding-3-large")
|
| 15 |
+
vectorstore = FAISS.load_local("faiss_index", embeddings, allow_dangerous_deserialization=True)
|
| 16 |
+
retriever = vectorstore.as_retriever(search_kwargs={"k": 1})
|
| 17 |
+
|
| 18 |
+
model = ChatOpenAI(streaming=True)
|
| 19 |
+
|
| 20 |
+
prompt = ChatPromptTemplate.from_messages(
|
| 21 |
+
[
|
| 22 |
+
(
|
| 23 |
+
"system",
|
| 24 |
+
"You are an 8th grader physics teacher. "
|
| 25 |
+
"You are looking to create notes for the chapter, "
|
| 26 |
+
"Explain the concept in a separate paragraph with bullet points and examples."
|
| 27 |
+
"Keep it concise and to the point. "
|
| 28 |
+
"Example output format"
|
| 29 |
+
"Title: What is Motion?"
|
| 30 |
+
"Motion is a change in position over time."
|
| 31 |
+
"To be able to describe an object or individual’s motion, you need to be able to accurately describe its position. "
|
| 32 |
+
"In order to describe an object or individual’s position, you need to know the distance, direction and a reference point. A reference point can be used to describe an object or individual’s position in comparison to another location. "
|
| 33 |
+
"Example1: “The ball rolled towards the red car.” The red car would be the reference point."
|
| 34 |
+
"Example2: “The mall is two miles north of my house.” Your house would be the reference point.",
|
| 35 |
+
),
|
| 36 |
+
("human", "{question}"),
|
| 37 |
+
]
|
| 38 |
+
)
|
| 39 |
+
|
| 40 |
+
runnable = retriever| prompt | model | StrOutputParser()
|
| 41 |
+
cl.user_session.set("runnable", runnable)
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
@cl.on_message
|
| 45 |
+
async def on_message(message: cl.Message):
|
| 46 |
+
runnable = cl.user_session.get("runnable") # type: Runnable
|
| 47 |
+
|
| 48 |
+
msg = cl.Message(content="")
|
| 49 |
+
|
| 50 |
+
async for chunk in runnable.astream(
|
| 51 |
+
message.content,
|
| 52 |
+
config=RunnableConfig(callbacks=[cl.LangchainCallbackHandler()]),
|
| 53 |
+
):
|
| 54 |
+
await msg.stream_token(chunk)
|
| 55 |
+
|
| 56 |
+
await msg.send()
|
requirements.txt
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
langchain==0.2.0
|
| 2 |
+
langchain-community==0.2.0
|
| 3 |
+
langchain-core==0.2.0
|
| 4 |
+
langchain-openai==0.1.7
|
| 5 |
+
langchain-text-splitters==0.2.0
|
| 6 |
+
tiktoken==0.7.0
|