Spaces:
Running
Running
add gemini 3
Browse files- README.md +8 -0
- anycoder_app/config.py +6 -1
- anycoder_app/deploy.py +40 -2
- anycoder_app/models.py +8 -1
- requirements.txt +2 -1
README.md
CHANGED
|
@@ -58,6 +58,7 @@ anycoder/
|
|
| 58 |
1. **Backend**:
|
| 59 |
```bash
|
| 60 |
export HF_TOKEN="your_huggingface_token"
|
|
|
|
| 61 |
python backend_api.py
|
| 62 |
```
|
| 63 |
|
|
@@ -73,6 +74,7 @@ npm run dev
|
|
| 73 |
### Using start script:
|
| 74 |
```bash
|
| 75 |
export HF_TOKEN="your_token"
|
|
|
|
| 76 |
./start_fullstack.sh
|
| 77 |
```
|
| 78 |
|
|
@@ -100,6 +102,7 @@ This app runs as a Docker Space on HuggingFace. The Dockerfile:
|
|
| 100 |
|
| 101 |
## 🤖 Available Models
|
| 102 |
|
|
|
|
| 103 |
- MiniMax M2 (via HF router with Novita)
|
| 104 |
- DeepSeek V3/V3.1
|
| 105 |
- DeepSeek R1
|
|
@@ -116,6 +119,11 @@ This app runs as a Docker Space on HuggingFace. The Dockerfile:
|
|
| 116 |
## 🛠️ Environment Variables
|
| 117 |
|
| 118 |
- `HF_TOKEN` - HuggingFace API token (required)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 119 |
|
| 120 |
## 📦 Tech Stack
|
| 121 |
|
|
|
|
| 58 |
1. **Backend**:
|
| 59 |
```bash
|
| 60 |
export HF_TOKEN="your_huggingface_token"
|
| 61 |
+
export GEMINI_API_KEY="your_gemini_api_key"
|
| 62 |
python backend_api.py
|
| 63 |
```
|
| 64 |
|
|
|
|
| 74 |
### Using start script:
|
| 75 |
```bash
|
| 76 |
export HF_TOKEN="your_token"
|
| 77 |
+
export GEMINI_API_KEY="your_gemini_api_key"
|
| 78 |
./start_fullstack.sh
|
| 79 |
```
|
| 80 |
|
|
|
|
| 102 |
|
| 103 |
## 🤖 Available Models
|
| 104 |
|
| 105 |
+
- **Gemini 3 Pro Preview** (Default) - Google's latest with deep thinking & Google Search
|
| 106 |
- MiniMax M2 (via HF router with Novita)
|
| 107 |
- DeepSeek V3/V3.1
|
| 108 |
- DeepSeek R1
|
|
|
|
| 119 |
## 🛠️ Environment Variables
|
| 120 |
|
| 121 |
- `HF_TOKEN` - HuggingFace API token (required)
|
| 122 |
+
- `GEMINI_API_KEY` - Google Gemini API key (required for Gemini 3 Pro Preview)
|
| 123 |
+
- `POE_API_KEY` - Poe API key (optional, for GPT-5 and Claude models)
|
| 124 |
+
- `DASHSCOPE_API_KEY` - DashScope API key (optional, for Qwen models)
|
| 125 |
+
- `OPENROUTER_API_KEY` - OpenRouter API key (optional, for Sherlock models)
|
| 126 |
+
- `MISTRAL_API_KEY` - Mistral API key (optional, for Mistral models)
|
| 127 |
|
| 128 |
## 📦 Tech Stack
|
| 129 |
|
anycoder_app/config.py
CHANGED
|
@@ -47,6 +47,11 @@ _fastrtc_docs_last_fetched: Optional[datetime] = None
|
|
| 47 |
|
| 48 |
# Available Models Configuration
|
| 49 |
AVAILABLE_MODELS = [
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
{
|
| 51 |
"name": "DeepSeek V3.2-Exp",
|
| 52 |
"id": "deepseek-ai/DeepSeek-V3.2-Exp",
|
|
@@ -152,7 +157,7 @@ AVAILABLE_MODELS = [
|
|
| 152 |
k2_model_name_tag = "moonshotai/Kimi-K2-Thinking"
|
| 153 |
|
| 154 |
# Default model selection
|
| 155 |
-
DEFAULT_MODEL_NAME = "
|
| 156 |
DEFAULT_MODEL = None
|
| 157 |
for _m in AVAILABLE_MODELS:
|
| 158 |
if _m.get("name") == DEFAULT_MODEL_NAME:
|
|
|
|
| 47 |
|
| 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",
|
| 57 |
"id": "deepseek-ai/DeepSeek-V3.2-Exp",
|
|
|
|
| 157 |
k2_model_name_tag = "moonshotai/Kimi-K2-Thinking"
|
| 158 |
|
| 159 |
# Default model selection
|
| 160 |
+
DEFAULT_MODEL_NAME = "Gemini 3 Pro Preview"
|
| 161 |
DEFAULT_MODEL = None
|
| 162 |
for _m in AVAILABLE_MODELS:
|
| 163 |
if _m.get("name") == DEFAULT_MODEL_NAME:
|
anycoder_app/deploy.py
CHANGED
|
@@ -420,8 +420,42 @@ Generate the exact search/replace blocks needed to make these changes."""
|
|
| 420 |
|
| 421 |
messages.append({'role': 'user', 'content': enhanced_query})
|
| 422 |
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 423 |
# Handle Mistral API method difference
|
| 424 |
-
|
| 425 |
completion = client.chat.stream(
|
| 426 |
model=get_real_model_id(_current_model["id"]),
|
| 427 |
messages=messages,
|
|
@@ -479,7 +513,11 @@ Generate the exact search/replace blocks needed to make these changes."""
|
|
| 479 |
for chunk in completion:
|
| 480 |
# Handle different response formats for Mistral vs others
|
| 481 |
chunk_content = None
|
| 482 |
-
if _current_model["id"]
|
|
|
|
|
|
|
|
|
|
|
|
|
| 483 |
# Mistral format: chunk.data.choices[0].delta.content
|
| 484 |
if (
|
| 485 |
hasattr(chunk, "data") and chunk.data and
|
|
|
|
| 420 |
|
| 421 |
messages.append({'role': 'user', 'content': enhanced_query})
|
| 422 |
try:
|
| 423 |
+
# Handle Gemini 3 Pro Preview with native SDK
|
| 424 |
+
if _current_model["id"] == "gemini-3-pro-preview":
|
| 425 |
+
# Convert messages to Gemini format
|
| 426 |
+
from google.genai import types
|
| 427 |
+
contents = []
|
| 428 |
+
for msg in messages:
|
| 429 |
+
if msg['role'] != 'system': # Gemini doesn't use system role the same way
|
| 430 |
+
contents.append(
|
| 431 |
+
types.Content(
|
| 432 |
+
role="user" if msg['role'] == 'user' else "model",
|
| 433 |
+
parts=[types.Part.from_text(text=msg['content'])]
|
| 434 |
+
)
|
| 435 |
+
)
|
| 436 |
+
|
| 437 |
+
# Add system prompt as first user message if exists
|
| 438 |
+
if messages and messages[0]['role'] == 'system':
|
| 439 |
+
system_content = messages[0]['content']
|
| 440 |
+
contents.insert(0, types.Content(
|
| 441 |
+
role="user",
|
| 442 |
+
parts=[types.Part.from_text(text=f"System instructions: {system_content}")]
|
| 443 |
+
))
|
| 444 |
+
|
| 445 |
+
tools = [types.Tool(googleSearch=types.GoogleSearch())]
|
| 446 |
+
generate_content_config = types.GenerateContentConfig(
|
| 447 |
+
thinkingConfig=types.ThinkingConfig(thinkingLevel="HIGH"),
|
| 448 |
+
tools=tools,
|
| 449 |
+
max_output_tokens=16384
|
| 450 |
+
)
|
| 451 |
+
|
| 452 |
+
completion = client.models.generate_content_stream(
|
| 453 |
+
model="gemini-3-pro-preview",
|
| 454 |
+
contents=contents,
|
| 455 |
+
config=generate_content_config,
|
| 456 |
+
)
|
| 457 |
# Handle Mistral API method difference
|
| 458 |
+
elif _current_model["id"] in ("codestral-2508", "mistral-medium-2508"):
|
| 459 |
completion = client.chat.stream(
|
| 460 |
model=get_real_model_id(_current_model["id"]),
|
| 461 |
messages=messages,
|
|
|
|
| 513 |
for chunk in completion:
|
| 514 |
# Handle different response formats for Mistral vs others
|
| 515 |
chunk_content = None
|
| 516 |
+
if _current_model["id"] == "gemini-3-pro-preview":
|
| 517 |
+
# Gemini native SDK format: chunk.text
|
| 518 |
+
if hasattr(chunk, 'text') and chunk.text:
|
| 519 |
+
chunk_content = chunk.text
|
| 520 |
+
elif _current_model["id"] in ("codestral-2508", "mistral-medium-2508"):
|
| 521 |
# Mistral format: chunk.data.choices[0].delta.content
|
| 522 |
if (
|
| 523 |
hasattr(chunk, "data") and chunk.data and
|
anycoder_app/models.py
CHANGED
|
@@ -11,6 +11,8 @@ from huggingface_hub import InferenceClient
|
|
| 11 |
from openai import OpenAI
|
| 12 |
from mistralai import Mistral
|
| 13 |
import dashscope
|
|
|
|
|
|
|
| 14 |
|
| 15 |
from .config import HF_TOKEN, AVAILABLE_MODELS
|
| 16 |
|
|
@@ -20,7 +22,12 @@ Messages = List[Dict[str, str]]
|
|
| 20 |
|
| 21 |
def get_inference_client(model_id, provider="auto"):
|
| 22 |
"""Return an InferenceClient with provider based on model_id and user selection."""
|
| 23 |
-
if model_id == "
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
# Use DashScope OpenAI client
|
| 25 |
return OpenAI(
|
| 26 |
api_key=os.getenv("DASHSCOPE_API_KEY"),
|
|
|
|
| 11 |
from openai import OpenAI
|
| 12 |
from mistralai import Mistral
|
| 13 |
import dashscope
|
| 14 |
+
from google import genai
|
| 15 |
+
from google.genai import types
|
| 16 |
|
| 17 |
from .config import HF_TOKEN, AVAILABLE_MODELS
|
| 18 |
|
|
|
|
| 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
|
| 27 |
+
return genai.Client(
|
| 28 |
+
api_key=os.getenv("GEMINI_API_KEY"),
|
| 29 |
+
)
|
| 30 |
+
elif model_id == "qwen3-30b-a3b-instruct-2507":
|
| 31 |
# Use DashScope OpenAI client
|
| 32 |
return OpenAI(
|
| 33 |
api_key=os.getenv("DASHSCOPE_API_KEY"),
|
requirements.txt
CHANGED
|
@@ -12,4 +12,5 @@ beautifulsoup4
|
|
| 12 |
html2text
|
| 13 |
openai
|
| 14 |
mistralai
|
| 15 |
-
dashscope
|
|
|
|
|
|
| 12 |
html2text
|
| 13 |
openai
|
| 14 |
mistralai
|
| 15 |
+
dashscope
|
| 16 |
+
google-genai
|