Spaces:
Running
Running
Update app.py
Browse files
agent.py
CHANGED
@@ -55,6 +55,8 @@ from transformers import AutoTokenizer, AutoModelForCausalLM, pipeline
|
|
55 |
from huggingface_hub import login
|
56 |
from transformers import AutoTokenizer, AutoModelForCausalLM, pipeline, BitsAndBytesConfig
|
57 |
|
|
|
|
|
58 |
load_dotenv()
|
59 |
|
60 |
@tool
|
@@ -459,47 +461,17 @@ tools = [wiki_tool, calc_tool, file_tool, web_tool, arvix_tool, youtube_tool, vi
|
|
459 |
|
460 |
|
461 |
# Get the Hugging Face API token from the environment variable
|
462 |
-
hf_token = os.getenv("HF_TOKEN")
|
463 |
-
|
464 |
-
# Load Hugging Face token
|
465 |
-
login(token=hf_token)
|
466 |
-
|
467 |
-
# Model name
|
468 |
-
model_name = "mistralai/Mistral-7B-Instruct-v0.1"
|
469 |
-
|
470 |
-
# Load tokenizer
|
471 |
-
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
472 |
|
473 |
-
# 🔧 Use 4-bit or 8-bit quantization
|
474 |
-
bnb_config = BitsAndBytesConfig(
|
475 |
-
load_in_4bit=True, # or use load_in_8bit=True
|
476 |
-
bnb_4bit_compute_dtype="float16",
|
477 |
-
bnb_4bit_use_double_quant=True,
|
478 |
-
bnb_4bit_quant_type="nf4",
|
479 |
-
)
|
480 |
-
|
481 |
-
# Load model with quantization
|
482 |
-
model = AutoModelForCausalLM.from_pretrained(
|
483 |
-
model_name,
|
484 |
-
device_map="auto",
|
485 |
-
quantization_config=bnb_config,
|
486 |
-
token=hf_token
|
487 |
-
)
|
488 |
|
489 |
-
|
490 |
-
|
491 |
-
"text-generation",
|
492 |
-
|
493 |
-
tokenizer=tokenizer,
|
494 |
-
max_new_tokens=512,
|
495 |
temperature=0.7,
|
496 |
-
|
497 |
-
repetition_penalty=1.15
|
498 |
)
|
499 |
|
500 |
-
# LangChain wrapper
|
501 |
-
llm = HuggingFacePipeline(pipeline=pipe)
|
502 |
-
|
503 |
# Initialize LangChain agent
|
504 |
agent = initialize_agent(
|
505 |
tools=tools,
|
|
|
55 |
from huggingface_hub import login
|
56 |
from transformers import AutoTokenizer, AutoModelForCausalLM, pipeline, BitsAndBytesConfig
|
57 |
|
58 |
+
from langchain_huggingface import HuggingFaceEndpoint
|
59 |
+
|
60 |
load_dotenv()
|
61 |
|
62 |
@tool
|
|
|
461 |
|
462 |
|
463 |
# Get the Hugging Face API token from the environment variable
|
464 |
+
#hf_token = os.getenv("HF_TOKEN")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
465 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
466 |
|
467 |
+
llm = HuggingFaceEndpoint(
|
468 |
+
repo_id="HuggingFaceH4/zephyr-7b-beta",
|
469 |
+
task="text-generation",
|
470 |
+
huggingfacehub_api_token=os.getenv("HF_TOKEN"),
|
|
|
|
|
471 |
temperature=0.7,
|
472 |
+
max_new_tokens=512
|
|
|
473 |
)
|
474 |
|
|
|
|
|
|
|
475 |
# Initialize LangChain agent
|
476 |
agent = initialize_agent(
|
477 |
tools=tools,
|