A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.
Python artificial-intelligencedagdata-sciencedata-visualizationdataflowdeveloper-toolsmachine-learningnotebookspipelinepythonreactivesqlweb-app
fix: allow AI code generation with deepseek-flash (#11461)
Shahmir Varqhaddeedf7bf446
diff --git a/marimo/_server/ai/providers.py b/marimo/_server/ai/providers.pyindex e6ddcb85ed..ca220f54f2 100644--- a/marimo/_server/ai/providers.py+++ b/marimo/_server/ai/providers.py@@ -1064,6 +1064,17 @@ class CustomProvider(OpenAIClientMixin, PydanticProvider["Provider"]):from pydantic_ai.models import infer_modelfrom pydantic_ai.models.openai import OpenAIChatModel+ if (+ self._provider_name == "deepseek"+ and self.model == "deepseek-flash"+ ):+ # Remove once pydantic/pydantic-ai#8353 fixes this model's profile.+ return OpenAIChatModel(+ model_name=self.model,+ provider=self.provider,+ profile=self.provider.model_profile("deepseek-v4-flash"),+ )+try:return infer_model(f"{self._provider_name}:{self.model}",diff --git a/tests/_server/ai/test_providers.py b/tests/_server/ai/test_providers.pyindex a9f79bfa6d..92bbff979a 100644--- a/tests/_server/ai/test_providers.py+++ b/tests/_server/ai/test_providers.py@@ -2,6 +2,7 @@import asyncioimport hashlib+import jsonimport osfrom collections.abc import AsyncIteratorfrom pathlib import Path@@ -1106,6 +1107,101 @@ def test_custom_provider_inherits_profile_from_base_url() -> None:assert profile.openai_chat_send_back_thinking_parts == "field"[email protected]("openai", "pydantic_ai")+ ("provider_name", "model_name", "base_url", "tool_choice"),+ [+ ("deepseek", "deepseek-flash", "https://api.deepseek.com", "auto"),+ (+ "deepseek_official",+ "deepseek-flash",+ "https://api.deepseek.com/v1/",+ "auto",+ ),+ ("deepseek", "deepseek-v4-flash", "https://api.deepseek.com", "auto"),+ ("deepseek", "deepseek-chat", "https://api.deepseek.com", "required"),+ (+ "custom",+ "deepseek-flash",+ "https://my.internal.llm/v1",+ "required",+ ),+ ],+)+async def test_custom_provider_structured_completion_tool_choice(+ provider_name: str,+ model_name: str,+ base_url: str,+ tool_choice: str,+) -> None:+ import httpx+ from openai import AsyncOpenAI++ requests: list[dict[str, str]] = []++ def respond(request: httpx.Request) -> httpx.Response:+ body = json.loads(request.content)+ requests.append(+ {"model": body["model"], "tool_choice": body["tool_choice"]}+ )+ return httpx.Response(+ 200,+ json={+ "id": "response",+ "object": "chat.completion",+ "created": 0,+ "model": model_name,+ "choices": [+ {+ "index": 0,+ "finish_reason": "tool_calls",+ "message": {+ "role": "assistant",+ "tool_calls": [+ {+ "id": "completion",+ "type": "function",+ "function": {+ "name": body["tools"][0]["function"][+ "name"+ ],+ "arguments": '{"code": "print(1)"}',+ },+ }+ ],+ },+ }+ ],+ },+ )++ async with (+ httpx.AsyncClient(+ transport=httpx.MockTransport(respond)+ ) as http_client,+ AsyncOpenAI(+ api_key="test-key", base_url=base_url, http_client=http_client+ ) as client,+ ):+ with patch.object(+ CustomProvider, "get_openai_client", return_value=client+ ):+ provider = CustomProvider(+ AiModelId.from_model(f"{provider_name}/{model_name}"),+ AnyProviderConfig(api_key="test-key", base_url=base_url),+ )+ agent = provider._create_structured_completion_agent(+ name="completion",+ max_tokens=None,+ system_prompt="Generate Python code.",+ output_type=CellCompletion,+ )+ result = await agent.run("Print 1")++ assert result.output == CellCompletion(code="print(1)")+ assert requests == [{"model": model_name, "tool_choice": tool_choice}]++@pytest.mark.requires("pydantic_ai")def test_custom_provider_unknown_base_url_stays_generic() -> None:"""An unknown name with an unrecognized base URL falls back to the generic