fix inference provider show up in history
Browse files117 unmodified lines118119120121122123156 unmodified lines280281282283284285286287288289117 unmodified lines'import streamlit' in last_assistant_msg or'def ' in last_assistant_msg and 'app' in last_assistant_msg or'IMPORTED PROJECT FROM HUGGING FACE SPACE' in last_assistant_msg or'=== index.html ===' in last_assistant_msg or'=== index.js ===' in last_assistant_msg or'=== style.css ===' in last_assistant_msg or156 unmodified linesmessages = history_to_messages(_history, system_prompt)# Use the original query without search enhancementenhanced_query = query# Check if this is GLM-4.5 model and handle with simple HuggingFace InferenceClientif _current_model["id"] == "zai-org/GLM-4.5":117 unmodified lines118119120121122123124125126127156 unmodified lines284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315117 unmodified lines'import streamlit' in last_assistant_msg or'def ' in last_assistant_msg and 'app' in last_assistant_msg or'IMPORTED PROJECT FROM HUGGING FACE SPACE' in last_assistant_msg or'InferenceClient' in last_assistant_msg or # Inference provider code'from huggingface_hub import' in last_assistant_msg or # Inference provider code'from transformers import' in last_assistant_msg or # Transformers code'from diffusers import' in last_assistant_msg or # Diffusers code'=== index.html ===' in last_assistant_msg or'=== index.js ===' in last_assistant_msg or'=== style.css ===' in last_assistant_msg or156 unmodified linesmessages = history_to_messages(_history, system_prompt)# Check if user has imported inference provider or model code and enhance the queryhas_imported_model_code = Falseimported_model_info = ""if _history:for user_msg, assistant_msg in _history:# Check if this is an imported modelif "Imported model:" in user_msg or "Imported inference provider code" in assistant_msg:has_imported_model_code = True# Extract the model code from assistant messageif "InferenceClient" in assistant_msg or "from huggingface_hub import" in assistant_msg:# Provide specific instructions based on the type of app being createdif language == "gradio":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!**"else: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.**"breakelif "from transformers import" in assistant_msg or "from diffusers import" in assistant_msg:if language == "gradio":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!**"else: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.**"break# Use the original query, enhanced with context about imported code if applicableenhanced_query = query + imported_model_info# Check if this is GLM-4.5 model and handle with simple HuggingFace InferenceClientif _current_model["id"] == "zai-org/GLM-4.5":
anycoder_app/deploy.py+29-3