Spaces:
Runtime error
Runtime error
Commit Β·
bd1d7b2
1
Parent(s): 43d607a
Model Replacement
Browse filesReplaced Mistral with Nano(gpt-4.1-nano) for suggestions and the Mistral Generate, uses the gpt-4.1-mini for generating the business plan.
- app/main.py +12 -31
app/main.py
CHANGED
|
@@ -172,12 +172,19 @@ def get_llm(model_name: str):
|
|
| 172 |
logging.error("HUGGINGFACEHUB_API_TOKEN environment variable not set")
|
| 173 |
raise ValueError("HUGGINGFACEHUB_API_TOKEN environment variable is required for Hugging Face models")
|
| 174 |
|
| 175 |
-
if model_name == "
|
| 176 |
openai_api_key = os.getenv("OPENAI_API_KEY")
|
| 177 |
if not openai_api_key:
|
| 178 |
logging.error("OPENAI_API_KEY environment variable not set")
|
| 179 |
raise ValueError("OPENAI_API_KEY environment variable is required for GPT models")
|
| 180 |
-
return ChatOpenAI(model_name="gpt-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 181 |
elif model_name == "Llama":
|
| 182 |
logging.info("Initializing Llama model - note this is a gated model and requires special access")
|
| 183 |
try:
|
|
@@ -213,33 +220,6 @@ def get_llm(model_name: str):
|
|
| 213 |
raise ValueError("The Qwen-2.5-7B model (15GB) exceeds the free tier limit (10GB) for Hugging Face Inference API. You need to upgrade to Hugging Face Pro to use this model, or use a smaller model like Mistral.")
|
| 214 |
else:
|
| 215 |
raise ValueError(f"Failed to initialize Qwen model: {error_msg}")
|
| 216 |
-
elif model_name == "Mistral":
|
| 217 |
-
logging.info("Initializing Mistral model")
|
| 218 |
-
try:
|
| 219 |
-
return HFInferenceLLM(
|
| 220 |
-
model="mistralai/Mistral-7B-Instruct-v0.3",
|
| 221 |
-
provider="together",
|
| 222 |
-
api_key=hf_token,
|
| 223 |
-
max_tokens=4000
|
| 224 |
-
)
|
| 225 |
-
except Exception as e:
|
| 226 |
-
error_msg = str(e)
|
| 227 |
-
logging.error(f"Failed to initialize Mistral model: {error_msg}")
|
| 228 |
-
|
| 229 |
-
if "too large to be loaded automatically" in error_msg:
|
| 230 |
-
# Try a smaller fallback model
|
| 231 |
-
logging.info("Trying smaller Mistral model...")
|
| 232 |
-
try:
|
| 233 |
-
return HFInferenceLLM(
|
| 234 |
-
model="mistralai/Mistral-7B-Instruct-v0.1",
|
| 235 |
-
provider="hf-inference",
|
| 236 |
-
api_key=hf_token,
|
| 237 |
-
max_tokens=4000
|
| 238 |
-
)
|
| 239 |
-
except Exception:
|
| 240 |
-
pass
|
| 241 |
-
|
| 242 |
-
raise ValueError(f"Failed to initialize Mistral model: {error_msg}")
|
| 243 |
elif model_name == "Gemma":
|
| 244 |
logging.info("Initializing Gemma model")
|
| 245 |
try:
|
|
@@ -319,7 +299,8 @@ async def get_suggestions(
|
|
| 319 |
prompt += "\nSuggestions:\n-"
|
| 320 |
|
| 321 |
try:
|
| 322 |
-
llm = get_llm(model) # your existing get_llm
|
|
|
|
| 323 |
suggestion_prompt = PromptTemplate(
|
| 324 |
input_variables=["prompt"],
|
| 325 |
template=prompt
|
|
@@ -464,7 +445,7 @@ def health_check():
|
|
| 464 |
for model_name in models_to_check:
|
| 465 |
try:
|
| 466 |
# Just initialize the model without running inference
|
| 467 |
-
if model_name == "
|
| 468 |
client = InferenceClient(provider="hf-inference", api_key=hf_token)
|
| 469 |
# Just a simple check that the model exists
|
| 470 |
client.model_info("mistralai/Mistral-7B-Instruct-v0.3")
|
|
|
|
| 172 |
logging.error("HUGGINGFACEHUB_API_TOKEN environment variable not set")
|
| 173 |
raise ValueError("HUGGINGFACEHUB_API_TOKEN environment variable is required for Hugging Face models")
|
| 174 |
|
| 175 |
+
if model_name == "Mistral": #Front end fix, Mistral Calls GPT
|
| 176 |
openai_api_key = os.getenv("OPENAI_API_KEY")
|
| 177 |
if not openai_api_key:
|
| 178 |
logging.error("OPENAI_API_KEY environment variable not set")
|
| 179 |
raise ValueError("OPENAI_API_KEY environment variable is required for GPT models")
|
| 180 |
+
return ChatOpenAI(model_name="gpt-4.1-mini", temperature=0.7, max_tokens=6000)
|
| 181 |
+
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 182 |
+
elif model_name.lower() == "gpt-4.1-nano": #πππ: support GPT-4.1 Nano
|
| 183 |
+
openai_api_key = os.getenv("OPENAI_API_KEY")
|
| 184 |
+
if not openai_api_key:
|
| 185 |
+
raise ValueError("OPENAI_API_KEY is required for GPT models")
|
| 186 |
+
return ChatOpenAI(model_name="gpt-4.1-nano", temperature=0.7, max_tokens=4000)
|
| 187 |
+
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 188 |
elif model_name == "Llama":
|
| 189 |
logging.info("Initializing Llama model - note this is a gated model and requires special access")
|
| 190 |
try:
|
|
|
|
| 220 |
raise ValueError("The Qwen-2.5-7B model (15GB) exceeds the free tier limit (10GB) for Hugging Face Inference API. You need to upgrade to Hugging Face Pro to use this model, or use a smaller model like Mistral.")
|
| 221 |
else:
|
| 222 |
raise ValueError(f"Failed to initialize Qwen model: {error_msg}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 223 |
elif model_name == "Gemma":
|
| 224 |
logging.info("Initializing Gemma model")
|
| 225 |
try:
|
|
|
|
| 299 |
prompt += "\nSuggestions:\n-"
|
| 300 |
|
| 301 |
try:
|
| 302 |
+
#llm = get_llm(model) # your existing get_llm which would now call gpt-4.1-mini
|
| 303 |
+
llm = get_llm("gpt-4.1-nano") #now we force it to use gpt-4.1-nano
|
| 304 |
suggestion_prompt = PromptTemplate(
|
| 305 |
input_variables=["prompt"],
|
| 306 |
template=prompt
|
|
|
|
| 445 |
for model_name in models_to_check:
|
| 446 |
try:
|
| 447 |
# Just initialize the model without running inference
|
| 448 |
+
if model_name == "":
|
| 449 |
client = InferenceClient(provider="hf-inference", api_key=hf_token)
|
| 450 |
# Just a simple check that the model exists
|
| 451 |
client.model_info("mistralai/Mistral-7B-Instruct-v0.3")
|