akhaliq HF Staff commited on
Commit
d4d57c4
·
1 Parent(s): d1efd8a

update gemini to poe

Browse files
anycoder_app/config.py CHANGED
@@ -48,9 +48,9 @@ _fastrtc_docs_last_fetched: Optional[datetime] = None
48
  # Available Models Configuration
49
  AVAILABLE_MODELS = [
50
  {
51
- "name": "Gemini 3 Pro Preview",
52
- "id": "gemini-3-pro-preview",
53
- "description": "Google Gemini 3 Pro Preview with deep thinking, Google Search integration, and advanced reasoning"
54
  },
55
  {
56
  "name": "DeepSeek V3.2-Exp",
 
48
  # Available Models Configuration
49
  AVAILABLE_MODELS = [
50
  {
51
+ "name": "Gemini 3.0 Pro",
52
+ "id": "gemini-3.0-pro",
53
+ "description": "Google Gemini 3.0 Pro via Poe with advanced reasoning"
54
  },
55
  {
56
  "name": "DeepSeek V3.2-Exp",
anycoder_app/deploy.py CHANGED
@@ -178,7 +178,7 @@ def _generation_code_impl(query: Optional[str], _setting: Dict[str, str], _histo
178
  if has_existing_content and query.strip():
179
  # Skip search/replace for models that use native clients (non-OpenAI-compatible)
180
  # These models need the full generation flow to work properly
181
- native_client_models = ["gemini-3-pro-preview"]
182
 
183
  if _current_model['id'] not in native_client_models:
184
  try:
@@ -463,42 +463,8 @@ Generate the exact search/replace blocks needed to make these changes."""
463
 
464
  messages.append({'role': 'user', 'content': enhanced_query})
465
  try:
466
- # Handle Gemini 3 Pro Preview with native SDK
467
- if _current_model["id"] == "gemini-3-pro-preview":
468
- # Convert messages to Gemini format
469
- from google.genai import types
470
- contents = []
471
- for msg in messages:
472
- if msg['role'] != 'system': # Gemini doesn't use system role the same way
473
- contents.append(
474
- types.Content(
475
- role="user" if msg['role'] == 'user' else "model",
476
- parts=[types.Part.from_text(text=msg['content'])]
477
- )
478
- )
479
-
480
- # Add system prompt as first user message if exists
481
- if messages and messages[0]['role'] == 'system':
482
- system_content = messages[0]['content']
483
- contents.insert(0, types.Content(
484
- role="user",
485
- parts=[types.Part.from_text(text=f"System instructions: {system_content}")]
486
- ))
487
-
488
- tools = [types.Tool(googleSearch=types.GoogleSearch())]
489
- generate_content_config = types.GenerateContentConfig(
490
- thinkingConfig=types.ThinkingConfig(thinkingLevel="HIGH"),
491
- tools=tools,
492
- max_output_tokens=16384
493
- )
494
-
495
- completion = client.models.generate_content_stream(
496
- model="gemini-3-pro-preview",
497
- contents=contents,
498
- config=generate_content_config,
499
- )
500
  # Handle Mistral API method difference
501
- elif _current_model["id"] in ("codestral-2508", "mistral-medium-2508"):
502
  completion = client.chat.stream(
503
  model=get_real_model_id(_current_model["id"]),
504
  messages=messages,
@@ -556,11 +522,7 @@ Generate the exact search/replace blocks needed to make these changes."""
556
  for chunk in completion:
557
  # Handle different response formats for Mistral vs others
558
  chunk_content = None
559
- if _current_model["id"] == "gemini-3-pro-preview":
560
- # Gemini native SDK format: chunk.text
561
- if hasattr(chunk, 'text') and chunk.text:
562
- chunk_content = chunk.text
563
- elif _current_model["id"] in ("codestral-2508", "mistral-medium-2508"):
564
  # Mistral format: chunk.data.choices[0].delta.content
565
  if (
566
  hasattr(chunk, "data") and chunk.data and
@@ -2338,7 +2300,7 @@ def _fetch_inference_provider_code(model_id: str) -> Optional[str]:
2338
  """
2339
  # Skip non-HuggingFace models (external APIs)
2340
  non_hf_models = [
2341
- "gemini-3-pro-preview", "gemini-2.5-flash", "gemini-2.5-pro",
2342
  "gemini-flash-latest", "gemini-flash-lite-latest",
2343
  "gpt-5", "gpt-5.1", "gpt-5.1-instant", "gpt-5.1-codex", "gpt-5.1-codex-mini",
2344
  "grok-4", "Grok-Code-Fast-1",
@@ -2442,7 +2404,7 @@ def import_model_from_hf(model_id: str, prefer_local: bool = False) -> Tuple[str
2442
 
2443
  # Skip non-HuggingFace models (external APIs) - these are not importable
2444
  non_hf_models = [
2445
- "gemini-3-pro-preview", "gemini-2.5-flash", "gemini-2.5-pro",
2446
  "gemini-flash-latest", "gemini-flash-lite-latest",
2447
  "gpt-5", "gpt-5.1", "gpt-5.1-instant", "gpt-5.1-codex", "gpt-5.1-codex-mini",
2448
  "grok-4", "Grok-Code-Fast-1",
 
178
  if has_existing_content and query.strip():
179
  # Skip search/replace for models that use native clients (non-OpenAI-compatible)
180
  # These models need the full generation flow to work properly
181
+ native_client_models = [] # All models now use OpenAI-compatible APIs
182
 
183
  if _current_model['id'] not in native_client_models:
184
  try:
 
463
 
464
  messages.append({'role': 'user', 'content': enhanced_query})
465
  try:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
466
  # Handle Mistral API method difference
467
+ if _current_model["id"] in ("codestral-2508", "mistral-medium-2508"):
468
  completion = client.chat.stream(
469
  model=get_real_model_id(_current_model["id"]),
470
  messages=messages,
 
522
  for chunk in completion:
523
  # Handle different response formats for Mistral vs others
524
  chunk_content = None
525
+ if _current_model["id"] in ("codestral-2508", "mistral-medium-2508"):
 
 
 
 
526
  # Mistral format: chunk.data.choices[0].delta.content
527
  if (
528
  hasattr(chunk, "data") and chunk.data and
 
2300
  """
2301
  # Skip non-HuggingFace models (external APIs)
2302
  non_hf_models = [
2303
+ "gemini-3.0-pro", "gemini-2.5-flash", "gemini-2.5-pro",
2304
  "gemini-flash-latest", "gemini-flash-lite-latest",
2305
  "gpt-5", "gpt-5.1", "gpt-5.1-instant", "gpt-5.1-codex", "gpt-5.1-codex-mini",
2306
  "grok-4", "Grok-Code-Fast-1",
 
2404
 
2405
  # Skip non-HuggingFace models (external APIs) - these are not importable
2406
  non_hf_models = [
2407
+ "gemini-3.0-pro", "gemini-2.5-flash", "gemini-2.5-pro",
2408
  "gemini-flash-latest", "gemini-flash-lite-latest",
2409
  "gpt-5", "gpt-5.1", "gpt-5.1-instant", "gpt-5.1-codex", "gpt-5.1-codex-mini",
2410
  "grok-4", "Grok-Code-Fast-1",
anycoder_app/models.py CHANGED
@@ -22,11 +22,11 @@ Messages = List[Dict[str, str]]
22
 
23
  def get_inference_client(model_id, provider="auto"):
24
  """Return an InferenceClient with provider based on model_id and user selection."""
25
- if model_id == "gemini-3-pro-preview":
26
- # Use native Google GenAI client for Gemini 3 Pro Preview with v1alpha API
27
- return genai.Client(
28
- api_key=os.getenv("GEMINI_API_KEY"),
29
- http_options={'api_version': 'v1alpha'}
30
  )
31
  elif model_id == "qwen3-30b-a3b-instruct-2507":
32
  # Use DashScope OpenAI client
 
22
 
23
  def get_inference_client(model_id, provider="auto"):
24
  """Return an InferenceClient with provider based on model_id and user selection."""
25
+ if model_id == "gemini-3.0-pro":
26
+ # Use Poe (OpenAI-compatible) client for Gemini 3.0 Pro
27
+ return OpenAI(
28
+ api_key=os.getenv("POE_API_KEY"),
29
+ base_url="https://api.poe.com/v1"
30
  )
31
  elif model_id == "qwen3-30b-a3b-instruct-2507":
32
  # Use DashScope OpenAI client
backend_api.py CHANGED
@@ -62,7 +62,7 @@ print("[Startup] System prompts initialization complete")
62
 
63
  # Define models and languages here to avoid importing Gradio UI
64
  AVAILABLE_MODELS = [
65
- {"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"},
66
  {"name": "Sherlock Dash Alpha", "id": "openrouter/sherlock-dash-alpha", "description": "Sherlock Dash Alpha model via OpenRouter"},
67
  {"name": "MiniMax M2", "id": "MiniMaxAI/MiniMax-M2", "description": "MiniMax M2 model via HuggingFace InferenceClient with Novita provider"},
68
  {"name": "DeepSeek V3.2-Exp", "id": "deepseek-ai/DeepSeek-V3.2-Exp", "description": "DeepSeek V3.2 Experimental via HuggingFace"},
@@ -112,7 +112,7 @@ user_sessions = {}
112
  class CodeGenerationRequest(BaseModel):
113
  query: str
114
  language: str = "html"
115
- model_id: str = "gemini-3-pro-preview"
116
  provider: str = "auto"
117
  history: List[List[str]] = []
118
  agent_mode: bool = False
@@ -389,19 +389,8 @@ async def generate_code(
389
 
390
  # Stream the response
391
  try:
392
- # Handle Gemini 3 Pro Preview with native SDK
393
- if selected_model_id == "gemini-3-pro-preview":
394
- print("[Generate] Using Gemini 3 native SDK")
395
- contents, config = create_gemini3_messages(messages)
396
-
397
- stream = client.models.generate_content_stream(
398
- model="gemini-3-pro-preview",
399
- contents=contents,
400
- config=config,
401
- )
402
-
403
  # Handle Mistral models with different API
404
- elif is_mistral_model(selected_model_id):
405
  print("[Generate] Using Mistral SDK")
406
  stream = client.chat.stream(
407
  model=actual_model_id,
@@ -426,11 +415,7 @@ async def generate_code(
426
  # Handle different response formats
427
  chunk_content = None
428
 
429
- if selected_model_id == "gemini-3-pro-preview":
430
- # Gemini native SDK format: chunk.text
431
- if hasattr(chunk, 'text') and chunk.text:
432
- chunk_content = chunk.text
433
- elif is_mistral_model(selected_model_id):
434
  # Mistral format: chunk.data.choices[0].delta.content
435
  if (hasattr(chunk, "data") and chunk.data and
436
  hasattr(chunk.data, "choices") and chunk.data.choices and
 
62
 
63
  # Define models and languages here to avoid importing Gradio UI
64
  AVAILABLE_MODELS = [
65
+ {"name": "Gemini 3.0 Pro", "id": "gemini-3.0-pro", "description": "Google Gemini 3.0 Pro via Poe with advanced reasoning"},
66
  {"name": "Sherlock Dash Alpha", "id": "openrouter/sherlock-dash-alpha", "description": "Sherlock Dash Alpha model via OpenRouter"},
67
  {"name": "MiniMax M2", "id": "MiniMaxAI/MiniMax-M2", "description": "MiniMax M2 model via HuggingFace InferenceClient with Novita provider"},
68
  {"name": "DeepSeek V3.2-Exp", "id": "deepseek-ai/DeepSeek-V3.2-Exp", "description": "DeepSeek V3.2 Experimental via HuggingFace"},
 
112
  class CodeGenerationRequest(BaseModel):
113
  query: str
114
  language: str = "html"
115
+ model_id: str = "gemini-3.0-pro"
116
  provider: str = "auto"
117
  history: List[List[str]] = []
118
  agent_mode: bool = False
 
389
 
390
  # Stream the response
391
  try:
 
 
 
 
 
 
 
 
 
 
 
392
  # Handle Mistral models with different API
393
+ if is_mistral_model(selected_model_id):
394
  print("[Generate] Using Mistral SDK")
395
  stream = client.chat.stream(
396
  model=actual_model_id,
 
415
  # Handle different response formats
416
  chunk_content = None
417
 
418
+ if is_mistral_model(selected_model_id):
 
 
 
 
419
  # Mistral format: chunk.data.choices[0].delta.content
420
  if (hasattr(chunk, "data") and chunk.data and
421
  hasattr(chunk.data, "choices") and chunk.data.choices and
backend_models.py CHANGED
@@ -8,32 +8,25 @@ from typing import Optional
8
  from openai import OpenAI
9
  from mistralai import Mistral
10
 
11
- # Import genai for Gemini 3
12
  try:
13
  from google import genai
14
  from google.genai import types
15
  GEMINI_AVAILABLE = True
16
  except ImportError:
17
  GEMINI_AVAILABLE = False
18
- print("WARNING: google-genai not available, Gemini 3 will not work")
19
 
20
  def get_inference_client(model_id: str, provider: str = "auto"):
21
  """
22
  Return an appropriate client based on model_id.
23
 
24
- For Gemini 3: Returns genai.Client (native Google SDK)
25
- For others: Returns OpenAI-compatible client or raises error
26
  """
27
- if model_id == "gemini-3-pro-preview":
28
- if not GEMINI_AVAILABLE:
29
- raise ImportError("google-genai package required for Gemini 3. Install with: pip install google-genai")
30
- # Use native Google GenAI client for Gemini 3 Pro Preview with v1alpha API
31
- api_key = os.getenv("GEMINI_API_KEY")
32
- if not api_key:
33
- raise ValueError("GEMINI_API_KEY environment variable required for Gemini 3")
34
- return genai.Client(
35
- api_key=api_key,
36
- http_options={'api_version': 'v1alpha'}
37
  )
38
 
39
  elif model_id == "qwen3-30b-a3b-instruct-2507":
@@ -328,7 +321,7 @@ def create_gemini3_messages(messages: list) -> tuple:
328
 
329
  def is_native_sdk_model(model_id: str) -> bool:
330
  """Check if model uses native SDK (not OpenAI-compatible)"""
331
- return model_id in ["gemini-3-pro-preview"]
332
 
333
 
334
  def is_mistral_model(model_id: str) -> bool:
 
8
  from openai import OpenAI
9
  from mistralai import Mistral
10
 
11
+ # Import genai for Gemini (legacy - no longer used with Poe API)
12
  try:
13
  from google import genai
14
  from google.genai import types
15
  GEMINI_AVAILABLE = True
16
  except ImportError:
17
  GEMINI_AVAILABLE = False
 
18
 
19
  def get_inference_client(model_id: str, provider: str = "auto"):
20
  """
21
  Return an appropriate client based on model_id.
22
 
23
+ Returns OpenAI-compatible client for all models or raises error if not configured.
 
24
  """
25
+ if model_id == "gemini-3.0-pro":
26
+ # Use Poe (OpenAI-compatible) client for Gemini 3.0 Pro
27
+ return OpenAI(
28
+ api_key=os.getenv("POE_API_KEY"),
29
+ base_url="https://api.poe.com/v1"
 
 
 
 
 
30
  )
31
 
32
  elif model_id == "qwen3-30b-a3b-instruct-2507":
 
321
 
322
  def is_native_sdk_model(model_id: str) -> bool:
323
  """Check if model uses native SDK (not OpenAI-compatible)"""
324
+ return False # All models now use OpenAI-compatible APIs
325
 
326
 
327
  def is_mistral_model(model_id: str) -> bool:
frontend/src/app/page.tsx CHANGED
@@ -14,7 +14,7 @@ export default function Home() {
14
  const [messages, setMessages] = useState<Message[]>([]);
15
  const [generatedCode, setGeneratedCode] = useState('');
16
  const [selectedLanguage, setSelectedLanguage] = useState<Language>('html');
17
- const [selectedModel, setSelectedModel] = useState('gemini-3-pro-preview');
18
  const [isGenerating, setIsGenerating] = useState(false);
19
  const [isAuthenticated, setIsAuthenticated] = useState(false);
20
 
 
14
  const [messages, setMessages] = useState<Message[]>([]);
15
  const [generatedCode, setGeneratedCode] = useState('');
16
  const [selectedLanguage, setSelectedLanguage] = useState<Language>('html');
17
+ const [selectedModel, setSelectedModel] = useState('gemini-3.0-pro');
18
  const [isGenerating, setIsGenerating] = useState(false);
19
  const [isAuthenticated, setIsAuthenticated] = useState(false);
20