KalooAI commited on
Commit
1609ba4
·
verified ·
1 Parent(s): 1d9246c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -16
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
- llm = ChatHuggingFace.from_model_id(
61
- model_id="mistralai/Mistral-7B-Instruct-v0.3",
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
- # 2. IMPORTANT: Manually set the model_id before wrapping
72
- # This bypasses the automated router check that's causing your ValueError
73
- llm_endpoint.model_id = "mistralai/Mistral-7B-Instruct-v0.3"
 
 
 
 
 
74
 
75
- # 3. Wrap in ChatHuggingFace
76
- # This will now handle the chat formatting without the router rejecting the task
77
- llm = ChatHuggingFace(llm=llm_endpoint)
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