update gemini to poe
Browse filesFiles changed (6)
47 unmodified lines48495051525354555647 unmodified lines# Available Models ConfigurationAVAILABLE_MODELS = [{"name": "Gemini 3 Pro Preview","id": "gemini-3-pro-preview","description": "Google Gemini 3 Pro Preview with deep thinking, Google Search integration, and advanced reasoning"},{"name": "DeepSeek V3.2-Exp",47 unmodified lines48495051525354555647 unmodified lines# Available Models ConfigurationAVAILABLE_MODELS = [{"name": "Gemini 3.0 Pro","id": "gemini-3.0-pro","description": "Google Gemini 3.0 Pro via Poe with advanced reasoning"},{"name": "DeepSeek V3.2-Exp",
177 unmodified lines178179180181182183184278 unmodified lines46346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350451 unmodified lines5565575585595605615625635645655661771 unmodified lines233823392340234123422343234497 unmodified lines2442244324442445244624472448177 unmodified linesif has_existing_content and query.strip():# Skip search/replace for models that use native clients (non-OpenAI-compatible)# These models need the full generation flow to work properlynative_client_models = ["gemini-3-pro-preview"]if _current_model['id'] not in native_client_models:try:278 unmodified linesmessages.append({'role': 'user', 'content': enhanced_query})try:# Handle Gemini 3 Pro Preview with native SDKif _current_model["id"] == "gemini-3-pro-preview":# Convert messages to Gemini formatfrom google.genai import typescontents = []for msg in messages:if msg['role'] != 'system': # Gemini doesn't use system role the same waycontents.append(types.Content(role="user" if msg['role'] == 'user' else "model",parts=[types.Part.from_text(text=msg['content'])]))# Add system prompt as first user message if existsif messages and messages[0]['role'] == 'system':system_content = messages[0]['content']contents.insert(0, types.Content(role="user",parts=[types.Part.from_text(text=f"System instructions: {system_content}")]))tools = [types.Tool(googleSearch=types.GoogleSearch())]generate_content_config = types.GenerateContentConfig(thinkingConfig=types.ThinkingConfig(thinkingLevel="HIGH"),tools=tools,max_output_tokens=16384)completion = client.models.generate_content_stream(model="gemini-3-pro-preview",contents=contents,config=generate_content_config,)# Handle Mistral API method differenceelif _current_model["id"] in ("codestral-2508", "mistral-medium-2508"):completion = client.chat.stream(model=get_real_model_id(_current_model["id"]),messages=messages,51 unmodified linesfor chunk in completion:# Handle different response formats for Mistral vs otherschunk_content = Noneif _current_model["id"] == "gemini-3-pro-preview":# Gemini native SDK format: chunk.textif hasattr(chunk, 'text') and chunk.text:chunk_content = chunk.textelif _current_model["id"] in ("codestral-2508", "mistral-medium-2508"):# Mistral format: chunk.data.choices[0].delta.contentif (hasattr(chunk, "data") and chunk.data and1771 unmodified lines"""# Skip non-HuggingFace models (external APIs)non_hf_models = ["gemini-3-pro-preview", "gemini-2.5-flash", "gemini-2.5-pro","gemini-flash-latest", "gemini-flash-lite-latest","gpt-5", "gpt-5.1", "gpt-5.1-instant", "gpt-5.1-codex", "gpt-5.1-codex-mini","grok-4", "Grok-Code-Fast-1",97 unmodified lines# Skip non-HuggingFace models (external APIs) - these are not importablenon_hf_models = ["gemini-3-pro-preview", "gemini-2.5-flash", "gemini-2.5-pro","gemini-flash-latest", "gemini-flash-lite-latest","gpt-5", "gpt-5.1", "gpt-5.1-instant", "gpt-5.1-codex", "gpt-5.1-codex-mini","grok-4", "Grok-Code-Fast-1",177 unmodified lines178179180181182183184278 unmodified lines46346446546646746846947051 unmodified lines5225235245255265275281771 unmodified lines230023012302230323042305230697 unmodified lines2404240524062407240824092410177 unmodified linesif has_existing_content and query.strip():# Skip search/replace for models that use native clients (non-OpenAI-compatible)# These models need the full generation flow to work properlynative_client_models = [] # All models now use OpenAI-compatible APIsif _current_model['id'] not in native_client_models:try:278 unmodified linesmessages.append({'role': 'user', 'content': enhanced_query})try:# 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,51 unmodified linesfor chunk in completion:# Handle different response formats for Mistral vs otherschunk_content = Noneif _current_model["id"] in ("codestral-2508", "mistral-medium-2508"):# Mistral format: chunk.data.choices[0].delta.contentif (hasattr(chunk, "data") and chunk.data and1771 unmodified lines"""# Skip non-HuggingFace models (external APIs)non_hf_models = ["gemini-3.0-pro", "gemini-2.5-flash", "gemini-2.5-pro","gemini-flash-latest", "gemini-flash-lite-latest","gpt-5", "gpt-5.1", "gpt-5.1-instant", "gpt-5.1-codex", "gpt-5.1-codex-mini","grok-4", "Grok-Code-Fast-1",97 unmodified lines# Skip non-HuggingFace models (external APIs) - these are not importablenon_hf_models = ["gemini-3.0-pro", "gemini-2.5-flash", "gemini-2.5-pro","gemini-flash-latest", "gemini-flash-lite-latest","gpt-5", "gpt-5.1", "gpt-5.1-instant", "gpt-5.1-codex", "gpt-5.1-codex-mini","grok-4", "Grok-Code-Fast-1",
21 unmodified lines222324252627282930313221 unmodified linesdef get_inference_client(model_id, provider="auto"):"""Return an InferenceClient with provider based on model_id and user selection."""if model_id == "gemini-3-pro-preview":# Use native Google GenAI client for Gemini 3 Pro Preview with v1alpha APIreturn genai.Client(api_key=os.getenv("GEMINI_API_KEY"),http_options={'api_version': 'v1alpha'})elif model_id == "qwen3-30b-a3b-instruct-2507":# Use DashScope OpenAI client21 unmodified lines222324252627282930313221 unmodified linesdef get_inference_client(model_id, provider="auto"):"""Return an InferenceClient with provider based on model_id and user selection."""if model_id == "gemini-3.0-pro":# Use Poe (OpenAI-compatible) client for Gemini 3.0 Proreturn OpenAI(api_key=os.getenv("POE_API_KEY"),base_url="https://api.poe.com/v1")elif model_id == "qwen3-30b-a3b-instruct-2507":# Use DashScope OpenAI client
61 unmodified lines6263646566676843 unmodified lines112113114115116117118270 unmodified lines38939039139239339439539639739839940040140240340440540640718 unmodified lines42642742842943043143243343443543661 unmodified lines# Define models and languages here to avoid importing Gradio UIAVAILABLE_MODELS = [{"name": "Gemini 3 Pro Preview", "id": "gemini-3-pro-preview", "description": "Google Gemini 3 Pro Preview with deep thinking, Google Search integration, and advanced reasoning"},{"name": "Sherlock Dash Alpha", "id": "openrouter/sherlock-dash-alpha", "description": "Sherlock Dash Alpha model via OpenRouter"},{"name": "MiniMax M2", "id": "MiniMaxAI/MiniMax-M2", "description": "MiniMax M2 model via HuggingFace InferenceClient with Novita provider"},{"name": "DeepSeek V3.2-Exp", "id": "deepseek-ai/DeepSeek-V3.2-Exp", "description": "DeepSeek V3.2 Experimental via HuggingFace"},43 unmodified linesclass CodeGenerationRequest(BaseModel):query: strlanguage: str = "html"model_id: str = "gemini-3-pro-preview"provider: str = "auto"history: List[List[str]] = []agent_mode: bool = False270 unmodified lines# Stream the responsetry:# Handle Gemini 3 Pro Preview with native SDKif selected_model_id == "gemini-3-pro-preview":print("[Generate] Using Gemini 3 native SDK")contents, config = create_gemini3_messages(messages)stream = client.models.generate_content_stream(model="gemini-3-pro-preview",contents=contents,config=config,)# Handle Mistral models with different APIelif is_mistral_model(selected_model_id):print("[Generate] Using Mistral SDK")stream = client.chat.stream(model=actual_model_id,18 unmodified lines# Handle different response formatschunk_content = Noneif selected_model_id == "gemini-3-pro-preview":# Gemini native SDK format: chunk.textif hasattr(chunk, 'text') and chunk.text:chunk_content = chunk.textelif is_mistral_model(selected_model_id):# Mistral format: chunk.data.choices[0].delta.contentif (hasattr(chunk, "data") and chunk.data andhasattr(chunk.data, "choices") and chunk.data.choices and61 unmodified lines6263646566676843 unmodified lines112113114115116117118270 unmodified lines38939039139239339439539618 unmodified lines41541641741841942042161 unmodified lines# Define models and languages here to avoid importing Gradio UIAVAILABLE_MODELS = [{"name": "Gemini 3.0 Pro", "id": "gemini-3.0-pro", "description": "Google Gemini 3.0 Pro via Poe with advanced reasoning"},{"name": "Sherlock Dash Alpha", "id": "openrouter/sherlock-dash-alpha", "description": "Sherlock Dash Alpha model via OpenRouter"},{"name": "MiniMax M2", "id": "MiniMaxAI/MiniMax-M2", "description": "MiniMax M2 model via HuggingFace InferenceClient with Novita provider"},{"name": "DeepSeek V3.2-Exp", "id": "deepseek-ai/DeepSeek-V3.2-Exp", "description": "DeepSeek V3.2 Experimental via HuggingFace"},43 unmodified linesclass CodeGenerationRequest(BaseModel):query: strlanguage: str = "html"model_id: str = "gemini-3.0-pro"provider: str = "auto"history: List[List[str]] = []agent_mode: bool = False270 unmodified lines# Stream the responsetry:# Handle Mistral models with different APIif is_mistral_model(selected_model_id):print("[Generate] Using Mistral SDK")stream = client.chat.stream(model=actual_model_id,18 unmodified lines# Handle different response formatschunk_content = Noneif is_mistral_model(selected_model_id):# Mistral format: chunk.data.choices[0].delta.contentif (hasattr(chunk, "data") and chunk.data andhasattr(chunk.data, "choices") and chunk.data.choices and
7 unmodified lines89101112131415161718192021222324252627282930313233343536373839288 unmodified lines3283293303313323333347 unmodified linesfrom openai import OpenAIfrom mistralai import Mistral# Import genai for Gemini 3try:from google import genaifrom google.genai import typesGEMINI_AVAILABLE = Trueexcept ImportError:GEMINI_AVAILABLE = Falseprint("WARNING: google-genai not available, Gemini 3 will not work")def get_inference_client(model_id: str, provider: str = "auto"):"""Return an appropriate client based on model_id.For Gemini 3: Returns genai.Client (native Google SDK)For others: Returns OpenAI-compatible client or raises error"""if model_id == "gemini-3-pro-preview":if not GEMINI_AVAILABLE:raise ImportError("google-genai package required for Gemini 3. Install with: pip install google-genai")# Use native Google GenAI client for Gemini 3 Pro Preview with v1alpha APIapi_key = os.getenv("GEMINI_API_KEY")if not api_key:raise ValueError("GEMINI_API_KEY environment variable required for Gemini 3")return genai.Client(api_key=api_key,http_options={'api_version': 'v1alpha'})elif model_id == "qwen3-30b-a3b-instruct-2507":288 unmodified linesdef is_native_sdk_model(model_id: str) -> bool:"""Check if model uses native SDK (not OpenAI-compatible)"""return model_id in ["gemini-3-pro-preview"]def is_mistral_model(model_id: str) -> bool:7 unmodified lines891011121314151617181920212223242526272829303132288 unmodified lines3213223233243253263277 unmodified linesfrom openai import OpenAIfrom mistralai import Mistral# Import genai for Gemini (legacy - no longer used with Poe API)try:from google import genaifrom google.genai import typesGEMINI_AVAILABLE = Trueexcept ImportError:GEMINI_AVAILABLE = Falsedef get_inference_client(model_id: str, provider: str = "auto"):"""Return an appropriate client based on model_id.Returns OpenAI-compatible client for all models or raises error if not configured."""if model_id == "gemini-3.0-pro":# Use Poe (OpenAI-compatible) client for Gemini 3.0 Proreturn OpenAI(api_key=os.getenv("POE_API_KEY"),base_url="https://api.poe.com/v1")elif model_id == "qwen3-30b-a3b-instruct-2507":288 unmodified linesdef is_native_sdk_model(model_id: str) -> bool:"""Check if model uses native SDK (not OpenAI-compatible)"""return False # All models now use OpenAI-compatible APIsdef is_mistral_model(model_id: str) -> bool:
13 unmodified lines1415161718192013 unmodified linesconst [messages, setMessages] = useState<Message[]>([]);const [generatedCode, setGeneratedCode] = useState('');const [selectedLanguage, setSelectedLanguage] = useState<Language>('html');const [selectedModel, setSelectedModel] = useState('gemini-3-pro-preview');const [isGenerating, setIsGenerating] = useState(false);const [isAuthenticated, setIsAuthenticated] = useState(false);13 unmodified lines1415161718192013 unmodified linesconst [messages, setMessages] = useState<Message[]>([]);const [generatedCode, setGeneratedCode] = useState('');const [selectedLanguage, setSelectedLanguage] = useState<Language>('html');const [selectedModel, setSelectedModel] = useState('gemini-3.0-pro');const [isGenerating, setIsGenerating] = useState(false);const [isAuthenticated, setIsAuthenticated] = useState(false);
anycoder_app/config.py+3-3
anycoder_app/deploy.py+5-43
anycoder_app/models.py+5-5
backend_api.py+4-19
backend_models.py+8-15
frontend/src/app/page.tsx+1-1