carrot model
Browse files1460 unmodified lines146114621463146414651466152 unmodified lines1619162016211622162316241625140 unmodified lines17661767176817691770177120 unmodified lines1792179317941795179617973366 unmodified lines51645165516651675168516951701 unmodified line51725173517451755176517751781 unmodified line518051815182518351845185518661 unmodified lines5248524952505251525252535254335 unmodified lines559055915592559355945595559623 unmodified lines56205621562256235624562556261460 unmodified lines"id": "kimi-k2-turbo-preview","description": "Moonshot AI Kimi K2 Turbo via OpenAI-compatible API"},{"name": "DeepSeek V3","id": "deepseek-ai/DeepSeek-V3-0324",152 unmodified lines]# Default model selectionDEFAULT_MODEL_NAME = "Qwen3-Coder-480B-A35B-Instruct"DEFAULT_MODEL = Nonefor _m in AVAILABLE_MODELS:if _m.get("name") == DEFAULT_MODEL_NAME:140 unmodified linesapi_key=os.getenv("MOONSHOT_API_KEY"),base_url="https://api.moonshot.ai/v1",)elif model_id == "openai/gpt-oss-120b":provider = "groq"elif model_id == "openai/gpt-oss-20b":20 unmodified linesbill_to="huggingface")# Type definitionsHistory = List[Tuple[str, str]]Messages = List[Dict[str, str]]3366 unmodified lines# Generate search/replace instructionsif _current_model.get('type') == 'openai':response = client.chat.completions.create(model=_current_model['id'],messages=messages,max_tokens=4000,temperature=0.11 unmodified linechanges_text = response.choices[0].message.contentelif _current_model.get('type') == 'mistral':response = client.chat.complete(model=_current_model['id'],messages=messages,max_tokens=4000,temperature=0.11 unmodified linechanges_text = response.choices[0].message.contentelse: # Hugging Face or othercompletion = client.chat.completions.create(model=_current_model['id'],messages=messages,max_tokens=4000,temperature=0.161 unmodified linesupdate_gradio_system_prompts()# Choose system prompt based on contextif has_existing_content:# Use follow-up prompt for modifying existing contentif language == "transformers.js":system_prompt = TransformersJSFollowUpSystemPrompt335 unmodified lines# Handle Mistral API method differenceif _current_model["id"] in ("codestral-2508", "mistral-medium-2508"):completion = client.chat.stream(model=_current_model["id"],messages=messages,max_tokens=16384)23 unmodified lines)else:completion = client.chat.completions.create(model=_current_model["id"],messages=messages,stream=True,max_tokens=163841460 unmodified lines14611462146314641465146614671468146914701471152 unmodified lines1624162516261627162816291630140 unmodified lines1771177217731774177517761777177817791780178117821783178417851786178717881789179020 unmodified lines1811181218131814181518161817181818191820182118221823182418251826182718283366 unmodified lines51955196519751985199520052011 unmodified line52035204520552065207520852091 unmodified line521152125213521452155216521761 unmodified lines5279528052815282528352845285528652875288335 unmodified lines562456255626562756285629563023 unmodified lines56545655565656575658565956601460 unmodified lines"id": "kimi-k2-turbo-preview","description": "Moonshot AI Kimi K2 Turbo via OpenAI-compatible API"},{"name": "Carrot","id": "stealth-model-1","description": "High-performance AI model for code generation and complex reasoning tasks"},{"name": "DeepSeek V3","id": "deepseek-ai/DeepSeek-V3-0324",152 unmodified lines]# Default model selectionDEFAULT_MODEL_NAME = "Carrot"DEFAULT_MODEL = Nonefor _m in AVAILABLE_MODELS:if _m.get("name") == DEFAULT_MODEL_NAME:140 unmodified linesapi_key=os.getenv("MOONSHOT_API_KEY"),base_url="https://api.moonshot.ai/v1",)elif model_id == "stealth-model-1":# Use stealth model with generic configurationapi_key = os.getenv("STEALTH_MODEL_1_API_KEY")if not api_key:raise ValueError("STEALTH_MODEL_1_API_KEY environment variable is required for Carrot model")base_url = os.getenv("STEALTH_MODEL_1_BASE_URL")if not base_url:raise ValueError("STEALTH_MODEL_1_BASE_URL environment variable is required for Carrot model")return OpenAI(api_key=api_key,base_url=base_url,)elif model_id == "openai/gpt-oss-120b":provider = "groq"elif model_id == "openai/gpt-oss-20b":20 unmodified linesbill_to="huggingface")# Helper function to get real model ID for stealth modelsdef get_real_model_id(model_id: str) -> str:"""Get the real model ID, checking environment variables for stealth models"""if model_id == "stealth-model-1":# Get the real model ID from environment variablereal_model_id = os.getenv("STEALTH_MODEL_1_ID")if not real_model_id:raise ValueError("STEALTH_MODEL_1_ID environment variable is required for Carrot model")return real_model_idreturn model_id# Type definitionsHistory = List[Tuple[str, str]]Messages = List[Dict[str, str]]3366 unmodified lines# Generate search/replace instructionsif _current_model.get('type') == 'openai':response = client.chat.completions.create(model=get_real_model_id(_current_model['id']),messages=messages,max_tokens=4000,temperature=0.11 unmodified linechanges_text = response.choices[0].message.contentelif _current_model.get('type') == 'mistral':response = client.chat.complete(model=get_real_model_id(_current_model['id']),messages=messages,max_tokens=4000,temperature=0.11 unmodified linechanges_text = response.choices[0].message.contentelse: # Hugging Face or othercompletion = client.chat.completions.create(model=get_real_model_id(_current_model['id']),messages=messages,max_tokens=4000,temperature=0.161 unmodified linesupdate_gradio_system_prompts()# Choose system prompt based on context# Special case: If user is asking about model identity, use neutral promptif query and any(phrase in query.lower() for phrase in ["what model are you", "who are you", "identify yourself", "what ai are you", "which model"]):system_prompt = "You are a helpful AI assistant. Please respond truthfully about your identity and capabilities."elif has_existing_content:# Use follow-up prompt for modifying existing contentif language == "transformers.js":system_prompt = TransformersJSFollowUpSystemPrompt335 unmodified lines# Handle Mistral API method differenceif _current_model["id"] in ("codestral-2508", "mistral-medium-2508"):completion = client.chat.stream(model=get_real_model_id(_current_model["id"]),messages=messages,max_tokens=16384)23 unmodified lines)else:completion = client.chat.completions.create(model=get_real_model_id(_current_model["id"]),messages=messages,stream=True,max_tokens=16384
app.py+41-7