Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -12,6 +12,7 @@ from langgraph.prebuilt import ToolNode, tools_condition
|
|
| 12 |
from langchain_core.messages import AnyMessage, SystemMessage, HumanMessage
|
| 13 |
from langchain_groq import ChatGroq
|
| 14 |
from langchain_huggingface import HuggingFaceEndpoint, ChatHuggingFace
|
|
|
|
| 15 |
|
| 16 |
# (Keep Constants as is)
|
| 17 |
# --- Constants ---
|
|
@@ -31,13 +32,23 @@ HF_TOKEN = os.getenv("HF_TOKEN")
|
|
| 31 |
# huggingfacehub_api_token=HF_TOKEN,
|
| 32 |
# provider='auto'
|
| 33 |
#)
|
| 34 |
-
llm = HuggingFaceEndpoint(
|
| 35 |
-
repo_id="mistralai/Mistral-7B-Instruct-v0.2",
|
| 36 |
-
huggingfacehub_api_token=HF_TOKEN,
|
| 37 |
-
provider="auto"
|
| 38 |
-
)
|
| 39 |
|
| 40 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
|
| 42 |
tools = []
|
| 43 |
chat_with_tools = chat.bind_tools(tools)
|
|
|
|
| 12 |
from langchain_core.messages import AnyMessage, SystemMessage, HumanMessage
|
| 13 |
from langchain_groq import ChatGroq
|
| 14 |
from langchain_huggingface import HuggingFaceEndpoint, ChatHuggingFace
|
| 15 |
+
from langchain_ollama import ChatOllama
|
| 16 |
|
| 17 |
# (Keep Constants as is)
|
| 18 |
# --- Constants ---
|
|
|
|
| 32 |
# huggingfacehub_api_token=HF_TOKEN,
|
| 33 |
# provider='auto'
|
| 34 |
#)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
|
| 36 |
+
checkpoint = "meta-llama/Llama-3.2-3B-Instruct"
|
| 37 |
+
tokenizer = AutoTokenizer.from_pretrained(checkpoint)
|
| 38 |
+
model = AutoModelForCausalLM.from_pretrained(checkpoint, token=HF_TOKEN)
|
| 39 |
+
|
| 40 |
+
#messages = [{"role": "user", "content": "Hello."}]
|
| 41 |
+
#input_text=tokenizer.apply_chat_template(messages, tokenize=False)
|
| 42 |
+
#print(input_text)
|
| 43 |
+
#inputs = tokenizer.encode(input_text, return_tensors="pt").to(device)
|
| 44 |
+
#outputs = model.generate(inputs, max_new_tokens=50, temperature=0.2, top_p=0.9, do_sample=True)
|
| 45 |
+
#print(tokenizer.decode(outputs[0]))
|
| 46 |
+
|
| 47 |
+
pipe = pipeline('text-generation', model=model, tokenizer=tokenizer, max_length=2048)
|
| 48 |
+
hf = HuggingFacePipeline(pipeline=pipe)
|
| 49 |
+
|
| 50 |
+
#chat = ChatHuggingFace(llm=llm, verbose=True)
|
| 51 |
+
chat = ChatOllama(llm=llm)
|
| 52 |
|
| 53 |
tools = []
|
| 54 |
chat_with_tools = chat.bind_tools(tools)
|