Spaces:
Running
Running
fix inference provider show up in history
Browse files- anycoder_app/deploy.py +29 -3
anycoder_app/deploy.py
CHANGED
|
@@ -118,6 +118,10 @@ def generation_code(query: Optional[str], _setting: Dict[str, str], _history: Op
|
|
| 118 |
'import streamlit' in last_assistant_msg or
|
| 119 |
'def ' in last_assistant_msg and 'app' in last_assistant_msg or
|
| 120 |
'IMPORTED PROJECT FROM HUGGING FACE SPACE' in last_assistant_msg or
|
|
|
|
|
|
|
|
|
|
|
|
|
| 121 |
'=== index.html ===' in last_assistant_msg or
|
| 122 |
'=== index.js ===' in last_assistant_msg or
|
| 123 |
'=== style.css ===' in last_assistant_msg or
|
|
@@ -280,10 +284,32 @@ Generate the exact search/replace blocks needed to make these changes."""
|
|
| 280 |
|
| 281 |
messages = history_to_messages(_history, system_prompt)
|
| 282 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 283 |
|
| 284 |
-
|
| 285 |
-
|
| 286 |
-
enhanced_query = query
|
| 287 |
|
| 288 |
# Check if this is GLM-4.5 model and handle with simple HuggingFace InferenceClient
|
| 289 |
if _current_model["id"] == "zai-org/GLM-4.5":
|
|
|
|
| 118 |
'import streamlit' in last_assistant_msg or
|
| 119 |
'def ' in last_assistant_msg and 'app' in last_assistant_msg or
|
| 120 |
'IMPORTED PROJECT FROM HUGGING FACE SPACE' in last_assistant_msg or
|
| 121 |
+
'InferenceClient' in last_assistant_msg or # Inference provider code
|
| 122 |
+
'from huggingface_hub import' in last_assistant_msg or # Inference provider code
|
| 123 |
+
'from transformers import' in last_assistant_msg or # Transformers code
|
| 124 |
+
'from diffusers import' in last_assistant_msg or # Diffusers code
|
| 125 |
'=== index.html ===' in last_assistant_msg or
|
| 126 |
'=== index.js ===' in last_assistant_msg or
|
| 127 |
'=== style.css ===' in last_assistant_msg or
|
|
|
|
| 284 |
|
| 285 |
messages = history_to_messages(_history, system_prompt)
|
| 286 |
|
| 287 |
+
# Check if user has imported inference provider or model code and enhance the query
|
| 288 |
+
has_imported_model_code = False
|
| 289 |
+
imported_model_info = ""
|
| 290 |
+
|
| 291 |
+
if _history:
|
| 292 |
+
for user_msg, assistant_msg in _history:
|
| 293 |
+
# Check if this is an imported model
|
| 294 |
+
if "Imported model:" in user_msg or "Imported inference provider code" in assistant_msg:
|
| 295 |
+
has_imported_model_code = True
|
| 296 |
+
# Extract the model code from assistant message
|
| 297 |
+
if "InferenceClient" in assistant_msg or "from huggingface_hub import" in assistant_msg:
|
| 298 |
+
# Provide specific instructions based on the type of app being created
|
| 299 |
+
if language == "gradio":
|
| 300 |
+
imported_model_info = f"\n\n**CRITICAL INSTRUCTION: The user has imported HuggingFace Inference Provider code in the previous message. You MUST use this code as the backend for the Gradio application. Create a Gradio interface that:**\n1. Uses the InferenceClient from the imported code\n2. Creates a chatbot interface with gr.ChatInterface or gr.Blocks\n3. Implements a function that calls the model using client.chat.completions.create()\n4. Handles streaming responses properly\n5. Includes proper error handling\n\n**DO NOT ignore the imported code - integrate it into your Gradio app!**"
|
| 301 |
+
else:
|
| 302 |
+
imported_model_info = f"\n\n**IMPORTANT: The user has already imported model inference code in the conversation history. When creating the {language} application, USE the imported inference code as the backend. Integrate it properly into your application.**"
|
| 303 |
+
break
|
| 304 |
+
elif "from transformers import" in assistant_msg or "from diffusers import" in assistant_msg:
|
| 305 |
+
if language == "gradio":
|
| 306 |
+
imported_model_info = f"\n\n**CRITICAL INSTRUCTION: The user has imported transformers/diffusers model code in the previous message. You MUST use this code as the backend for the Gradio application. Create a Gradio interface that:**\n1. Uses the model loading code from the imported code\n2. Creates an appropriate interface based on the model type\n3. Implements inference functions that use the imported model\n4. Includes proper error handling\n\n**DO NOT ignore the imported code - integrate it into your Gradio app!**"
|
| 307 |
+
else:
|
| 308 |
+
imported_model_info = f"\n\n**IMPORTANT: The user has already imported transformers/diffusers model code in the conversation history. When creating the {language} application, USE the imported model code as the backend. Integrate it properly into your application.**"
|
| 309 |
+
break
|
| 310 |
|
| 311 |
+
# Use the original query, enhanced with context about imported code if applicable
|
| 312 |
+
enhanced_query = query + imported_model_info
|
|
|
|
| 313 |
|
| 314 |
# Check if this is GLM-4.5 model and handle with simple HuggingFace InferenceClient
|
| 315 |
if _current_model["id"] == "zai-org/GLM-4.5":
|