Spaces:
Sleeping
Sleeping
Create chat.py
Browse files- src/chat.py +44 -0
src/chat.py
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from src.ai_functions import client
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
def chat_section():
|
| 6 |
+
|
| 7 |
+
st.header("💬 Chat With Papers")
|
| 8 |
+
|
| 9 |
+
context = "\n".join(
|
| 10 |
+
[
|
| 11 |
+
p["abstract"]
|
| 12 |
+
for p in st.session_state.papers
|
| 13 |
+
]
|
| 14 |
+
)
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
question = st.text_area(
|
| 18 |
+
"Ask your question"
|
| 19 |
+
)
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
if st.button("Ask"):
|
| 23 |
+
|
| 24 |
+
response = client.chat.completions.create(
|
| 25 |
+
model="llama-3.1-8b-instant",
|
| 26 |
+
messages=[
|
| 27 |
+
{
|
| 28 |
+
"role":"user",
|
| 29 |
+
"content":
|
| 30 |
+
f"""
|
| 31 |
+
Context:
|
| 32 |
+
{context}
|
| 33 |
+
|
| 34 |
+
Question:
|
| 35 |
+
{question}
|
| 36 |
+
"""
|
| 37 |
+
}
|
| 38 |
+
]
|
| 39 |
+
)
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
st.write(
|
| 43 |
+
response.choices[0].message.content
|
| 44 |
+
)
|