Update app.py
Browse files
app.py
CHANGED
@@ -11,6 +11,9 @@ import torch
|
|
11 |
from transformers import AutoTokenizer, AutoModelForCausalLM, BitsAndBytesConfig
|
12 |
import os
|
13 |
from dotenv import load_dotenv
|
|
|
|
|
|
|
14 |
|
15 |
warnings.filterwarnings("ignore")
|
16 |
load_dotenv()
|
@@ -64,16 +67,28 @@ def create_llm():
|
|
64 |
|
65 |
# llm = HuggingFacePipeline(pipeline=text_generation_pipeline)
|
66 |
|
67 |
-
return HuggingFaceHub(
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
75 |
)
|
76 |
# return llm
|
|
|
|
|
|
|
77 |
|
78 |
# Improved prompt template with better context handling and response structure
|
79 |
PROMPT_TEMPLATE = """
|
|
|
11 |
from transformers import AutoTokenizer, AutoModelForCausalLM, BitsAndBytesConfig
|
12 |
import os
|
13 |
from dotenv import load_dotenv
|
14 |
+
from langchain_huggingface import ChatHuggingFace, HuggingFacePipeline
|
15 |
+
|
16 |
+
|
17 |
|
18 |
warnings.filterwarnings("ignore")
|
19 |
load_dotenv()
|
|
|
67 |
|
68 |
# llm = HuggingFacePipeline(pipeline=text_generation_pipeline)
|
69 |
|
70 |
+
# return HuggingFaceHub(
|
71 |
+
# repo_id=MODEL_NAME,
|
72 |
+
# model_kwargs={
|
73 |
+
# "temperature": 0.7, # Balanced between creativity and accuracy
|
74 |
+
# "max_new_tokens": 1024,
|
75 |
+
# "top_p": 0.9,
|
76 |
+
# "frequency_penalty": 0.5
|
77 |
+
# }
|
78 |
+
# )
|
79 |
+
llm = HuggingFacePipeline.from_model_id(
|
80 |
+
model_id=MODEL_NAME,
|
81 |
+
task="text-generation",
|
82 |
+
pipeline_kwargs=dict(
|
83 |
+
max_new_tokens=512,
|
84 |
+
do_sample=False,
|
85 |
+
repetition_penalty=1.03,
|
86 |
+
),
|
87 |
)
|
88 |
# return llm
|
89 |
+
|
90 |
+
|
91 |
+
# chat_model = ChatHuggingFace(llm=llm)
|
92 |
|
93 |
# Improved prompt template with better context handling and response structure
|
94 |
PROMPT_TEMPLATE = """
|