Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -57,24 +57,21 @@ client = InferenceClient(HF_MODEL_ID, token=os.getenv("HF_TOKEN"))
|
|
| 57 |
# We use 'text-generation' because that's what the LangChain client expects
|
| 58 |
# Use the dedicated Chat constructor
|
| 59 |
# This handles the model_id and the conversational task mapping automatically
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
model_kwargs={
|
| 63 |
-
"max_new_tokens": 512,
|
| 64 |
-
"huggingfacehub_api_token": os.getenv("HF_TOKEN"),
|
| 65 |
-
},
|
| 66 |
-
# This tells the server we are sending a Chat request
|
| 67 |
-
# but the local wrapper knows it's an "Instruct" model.
|
| 68 |
-
task="text-generation",
|
| 69 |
-
)
|
| 70 |
|
| 71 |
-
#
|
| 72 |
-
# This
|
| 73 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 74 |
|
| 75 |
-
#
|
| 76 |
-
#
|
| 77 |
-
llm = ChatHuggingFace(llm=
|
| 78 |
|
| 79 |
# -------------------------
|
| 80 |
# Document loader
|
|
|
|
| 57 |
# We use 'text-generation' because that's what the LangChain client expects
|
| 58 |
# Use the dedicated Chat constructor
|
| 59 |
# This handles the model_id and the conversational task mapping automatically
|
| 60 |
+
import os
|
| 61 |
+
from langchain_huggingface import HuggingFaceEndpoint, ChatHuggingFace
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
|
| 63 |
+
# 1. Define the endpoint with text-generation task
|
| 64 |
+
# This is the "engine" that talks to the Hugging Face servers
|
| 65 |
+
http_llm = HuggingFaceEndpoint(
|
| 66 |
+
repo_id="mistralai/Mistral-7B-Instruct-v0.3",
|
| 67 |
+
task="text-generation",
|
| 68 |
+
max_new_tokens=512,
|
| 69 |
+
huggingfacehub_api_token=os.getenv("HF_TOKEN"),
|
| 70 |
+
)
|
| 71 |
|
| 72 |
+
# 2. Wrap it manually in ChatHuggingFace
|
| 73 |
+
# We pass it as 'llm' to the constructor
|
| 74 |
+
llm = ChatHuggingFace(llm=http_llm)
|
| 75 |
|
| 76 |
# -------------------------
|
| 77 |
# Document loader
|