Update app.py
Browse files
app.py
CHANGED
@@ -110,20 +110,38 @@ def init_db():
|
|
110 |
def initialize_llm():
|
111 |
"""Initialize the language model"""
|
112 |
try:
|
113 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
114 |
llm = HuggingFaceHub(
|
115 |
repo_id="mistralai/Mistral-7B-Instruct-v0.1",
|
116 |
-
huggingfacehub_api_token=
|
|
|
117 |
model_kwargs={
|
118 |
"temperature": 0.7,
|
119 |
"max_new_tokens": 512,
|
120 |
"top_p": 0.95,
|
121 |
-
"repetition_penalty": 1.15
|
|
|
122 |
}
|
123 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
124 |
return llm
|
|
|
125 |
except Exception as e:
|
126 |
-
print(f"Error initializing LLM: {e}")
|
|
|
|
|
127 |
raise
|
128 |
|
129 |
|
|
|
110 |
def initialize_llm():
|
111 |
"""Initialize the language model"""
|
112 |
try:
|
113 |
+
print("Starting LLM initialization...")
|
114 |
+
|
115 |
+
api_token = os.environ.get('HUGGINGFACE_API_TOKEN')
|
116 |
+
if not api_token:
|
117 |
+
raise ValueError("HUGGINGFACE_API_TOKEN not found in environment variables")
|
118 |
+
print("API token found")
|
119 |
+
|
120 |
+
# Initialize with specific task parameters
|
121 |
llm = HuggingFaceHub(
|
122 |
repo_id="mistralai/Mistral-7B-Instruct-v0.1",
|
123 |
+
huggingfacehub_api_token=api_token,
|
124 |
+
task="text-generation", # Specify the task
|
125 |
model_kwargs={
|
126 |
"temperature": 0.7,
|
127 |
"max_new_tokens": 512,
|
128 |
"top_p": 0.95,
|
129 |
+
"repetition_penalty": 1.15,
|
130 |
+
"return_full_text": False,
|
131 |
}
|
132 |
)
|
133 |
+
|
134 |
+
# Test the LLM
|
135 |
+
print("Testing LLM with a simple prompt...")
|
136 |
+
test_response = llm("Hello, please reply with a short greeting.")
|
137 |
+
print(f"Test response received: {test_response}")
|
138 |
+
|
139 |
return llm
|
140 |
+
|
141 |
except Exception as e:
|
142 |
+
print(f"Error initializing LLM: {str(e)}")
|
143 |
+
import traceback
|
144 |
+
print(f"Traceback: {traceback.format_exc()}")
|
145 |
raise
|
146 |
|
147 |
|