Spaces:
Sleeping
Sleeping
Commit
·
07387fb
1
Parent(s):
b62c91f
Used Embedding model through API
Browse files
my_agent/utils/models_loader.py
CHANGED
|
@@ -1,16 +1,17 @@
|
|
| 1 |
|
| 2 |
from langchain_groq import ChatGroq
|
| 3 |
from sentence_transformers import SentenceTransformer
|
|
|
|
| 4 |
from huggingface_hub import login
|
| 5 |
from dotenv import load_dotenv
|
| 6 |
load_dotenv()
|
| 7 |
import os
|
|
|
|
| 8 |
# from langchain_huggingface import HuggingFaceEndpoint
|
| 9 |
os.environ['HUGGINGFACEHUB_ACCESS_TOKEN']=os.getenv('HUGGINGFACEHUB_ACCESS_TOKEN')
|
| 10 |
login(os.environ['HUGGINGFACEHUB_ACCESS_TOKEN'])
|
| 11 |
os.environ['GROQ_API_KEY']=os.getenv('GROQ_API_KEY')
|
| 12 |
|
| 13 |
-
ST = SentenceTransformer("mixedbread-ai/mxbai-embed-large-v1")
|
| 14 |
|
| 15 |
llm = ChatGroq(
|
| 16 |
model="llama3-8b-8192",
|
|
@@ -21,6 +22,30 @@ llm = ChatGroq(
|
|
| 21 |
|
| 22 |
)
|
| 23 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
|
| 25 |
|
| 26 |
|
|
|
|
| 1 |
|
| 2 |
from langchain_groq import ChatGroq
|
| 3 |
from sentence_transformers import SentenceTransformer
|
| 4 |
+
from huggingface_hub import InferenceClient
|
| 5 |
from huggingface_hub import login
|
| 6 |
from dotenv import load_dotenv
|
| 7 |
load_dotenv()
|
| 8 |
import os
|
| 9 |
+
import requests
|
| 10 |
# from langchain_huggingface import HuggingFaceEndpoint
|
| 11 |
os.environ['HUGGINGFACEHUB_ACCESS_TOKEN']=os.getenv('HUGGINGFACEHUB_ACCESS_TOKEN')
|
| 12 |
login(os.environ['HUGGINGFACEHUB_ACCESS_TOKEN'])
|
| 13 |
os.environ['GROQ_API_KEY']=os.getenv('GROQ_API_KEY')
|
| 14 |
|
|
|
|
| 15 |
|
| 16 |
llm = ChatGroq(
|
| 17 |
model="llama3-8b-8192",
|
|
|
|
| 22 |
|
| 23 |
)
|
| 24 |
|
| 25 |
+
class HFEmbeddingAPI:
|
| 26 |
+
def __init__(self, api_url, token):
|
| 27 |
+
self.api_url = api_url
|
| 28 |
+
self.headers = {
|
| 29 |
+
"Authorization": f"Bearer {os.environ.get("HUGGINGFACEHUB_ACCESS_TOKEN")}",
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
def encode(self, texts):
|
| 33 |
+
if isinstance(texts, str):
|
| 34 |
+
texts = [texts]
|
| 35 |
+
response = requests.post(
|
| 36 |
+
self.api_url,
|
| 37 |
+
headers=self.headers,
|
| 38 |
+
json={"inputs": texts}
|
| 39 |
+
)
|
| 40 |
+
response.raise_for_status()
|
| 41 |
+
return response.json()
|
| 42 |
+
|
| 43 |
+
# Instantiate your API-backed "SentenceTransformer"
|
| 44 |
+
ST = HFEmbeddingAPI(
|
| 45 |
+
api_url="https://router.huggingface.co/hf-inference/models/mixedbread-ai/mxbai-embed-large-v1/pipeline/feature-extraction",
|
| 46 |
+
token="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"
|
| 47 |
+
)
|
| 48 |
+
|
| 49 |
|
| 50 |
|
| 51 |
|