Update models.py
Browse files- repochat/models.py +29 -18
repochat/models.py
CHANGED
|
@@ -1,23 +1,34 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
from
|
| 4 |
-
from
|
|
|
|
| 5 |
|
| 6 |
def hf_embeddings():
|
|
|
|
| 7 |
return HuggingFaceEmbeddings(
|
| 8 |
-
model_name
|
|
|
|
| 9 |
)
|
| 10 |
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import streamlit as st
|
| 3 |
+
from langchain_huggingface import HuggingFaceEmbeddings
|
| 4 |
+
from langchain_groq import ChatGroq
|
| 5 |
+
|
| 6 |
|
| 7 |
def hf_embeddings():
|
| 8 |
+
"""Lightweight sentence-transformer embeddings (runs on CPU, no GPU needed)."""
|
| 9 |
return HuggingFaceEmbeddings(
|
| 10 |
+
model_name="sentence-transformers/all-mpnet-base-v2",
|
| 11 |
+
model_kwargs={"device": "cpu"},
|
| 12 |
)
|
| 13 |
|
| 14 |
+
|
| 15 |
+
def groq_llm():
|
| 16 |
+
"""
|
| 17 |
+
Fast, free Llama-3 inference via Groq.
|
| 18 |
+
Requires GROQ_API_KEY set as a HuggingFace Space secret.
|
| 19 |
+
"""
|
| 20 |
+
api_key = os.environ.get("GROQ_API_KEY", "")
|
| 21 |
+
if not api_key:
|
| 22 |
+
st.error(
|
| 23 |
+
"⚠️ GROQ_API_KEY secret is not set. "
|
| 24 |
+
"Add it in your Space → Settings → Repository secrets."
|
| 25 |
+
)
|
| 26 |
+
st.stop()
|
| 27 |
+
|
| 28 |
+
return ChatGroq(
|
| 29 |
+
model="llama3-8b-8192",
|
| 30 |
+
api_key=api_key,
|
| 31 |
+
temperature=0.2,
|
| 32 |
+
max_tokens=1024,
|
| 33 |
+
streaming=False,
|
| 34 |
+
)
|