Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,12 +1,10 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
import faiss
|
| 3 |
from sentence_transformers import SentenceTransformer
|
| 4 |
-
|
| 5 |
|
| 6 |
# Initialize Groq API
|
| 7 |
-
|
| 8 |
-
groq_base_url = "https://api.groq.ai/v1"
|
| 9 |
-
client = groq.Client(api_key=groq_api_key, base_url=groq_base_url)
|
| 10 |
|
| 11 |
# Initialize Sentence Transformer
|
| 12 |
embedding_model = SentenceTransformer('all-MiniLM-L6-v2')
|
|
@@ -35,10 +33,11 @@ def embed_and_store(chunks):
|
|
| 35 |
embeddings = embedding_model.encode(chunks)
|
| 36 |
index.add(embeddings)
|
| 37 |
|
| 38 |
-
# Query handling using
|
| 39 |
def query_llm(prompt):
|
| 40 |
-
|
| 41 |
-
|
|
|
|
| 42 |
messages=[
|
| 43 |
{
|
| 44 |
"role": "system",
|
|
@@ -50,10 +49,18 @@ def query_llm(prompt):
|
|
| 50 |
},
|
| 51 |
{"role": "user", "content": prompt},
|
| 52 |
],
|
| 53 |
-
temperature=0.
|
| 54 |
-
|
|
|
|
|
|
|
|
|
|
| 55 |
)
|
| 56 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
|
| 58 |
# Streamlit App
|
| 59 |
st.title("AI Relationship Counsellor")
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
import faiss
|
| 3 |
from sentence_transformers import SentenceTransformer
|
| 4 |
+
from groq import Groq
|
| 5 |
|
| 6 |
# Initialize Groq API
|
| 7 |
+
client = Groq(api_key="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") # Ensure your API key is valid
|
|
|
|
|
|
|
| 8 |
|
| 9 |
# Initialize Sentence Transformer
|
| 10 |
embedding_model = SentenceTransformer('all-MiniLM-L6-v2')
|
|
|
|
| 33 |
embeddings = embedding_model.encode(chunks)
|
| 34 |
index.add(embeddings)
|
| 35 |
|
| 36 |
+
# Query handling using Groq's streaming completions
|
| 37 |
def query_llm(prompt):
|
| 38 |
+
# Create a completion request using the Groq model
|
| 39 |
+
completion = client.chat.completions.create(
|
| 40 |
+
model="deepseek-r1-distill-llama-70b", # Use the provided Groq model
|
| 41 |
messages=[
|
| 42 |
{
|
| 43 |
"role": "system",
|
|
|
|
| 49 |
},
|
| 50 |
{"role": "user", "content": prompt},
|
| 51 |
],
|
| 52 |
+
temperature=0.6,
|
| 53 |
+
max_completion_tokens=1024,
|
| 54 |
+
top_p=0.95,
|
| 55 |
+
stream=True,
|
| 56 |
+
reasoning_format="raw"
|
| 57 |
)
|
| 58 |
+
|
| 59 |
+
# Stream and collect the response
|
| 60 |
+
full_response = ""
|
| 61 |
+
for chunk in completion:
|
| 62 |
+
full_response += chunk.choices[0].delta.content or ""
|
| 63 |
+
return full_response
|
| 64 |
|
| 65 |
# Streamlit App
|
| 66 |
st.title("AI Relationship Counsellor")
|