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
improvement: add more github models, pass default headers (#7306)
Myles Scolnick284ad6a090c5
diff --git a/marimo/_server/ai/config.py b/marimo/_server/ai/config.pyindex 08cfb5715c..ed90778aec 100644--- a/marimo/_server/ai/config.py+++ b/marimo/_server/ai/config.py@@ -86,7 +86,7 @@ class AnyProviderConfig:@classmethoddef for_github(cls, config: AiConfig) -> AnyProviderConfig:fallback_key = cls.os_key("GITHUB_TOKEN")- return cls._for_openai_like(+ result = cls._for_openai_like(config,"github","GitHub",@@ -96,6 +96,21 @@ class AnyProviderConfig:require_key=True,)+ # Add default extra headers for GitHub, but allow user to override+ default_headers = {+ "editor-version": "vscode/1.95.0",+ "Copilot-Integration-Id": "vscode-chat",+ }++ # Merge: user headers override defaults+ if result.extra_headers:+ merged_headers = {**default_headers, **result.extra_headers}+ else:+ merged_headers = default_headers++ result.extra_headers = merged_headers+ return result+@classmethoddef for_openrouter(cls, config: AiConfig) -> AnyProviderConfig:fallback_key = cls.os_key("OPENROUTER_API_KEY")diff --git a/marimo/_smoke_tests/ai/github_model_check.py b/marimo/_smoke_tests/ai/github_model_check.pyindex eab43656bf..fe17d0de69 100644--- a/marimo/_smoke_tests/ai/github_model_check.py+++ b/marimo/_smoke_tests/ai/github_model_check.py@@ -9,16 +9,17 @@import marimo-__generated_with = "0.15.5"+__generated_with = "0.18.0"app = marimo.App(width="medium")[email protected](hide_code=True)def _():import marimo as moimport openaiimport os- return mo, openai+ import httpx+ return httpx, mo, openai@app.cell@@ -32,10 +33,24 @@ def _(mo):@app.cell-def _(api_key, openai):+def _(mo):+ with_headers = mo.ui.checkbox(label="With Headers")+ with_headers+ return (with_headers,)+++def _(api_key, httpx, openai, with_headers):client = openai.Client(base_url="https://api.githubcopilot.com/",api_key=api_key.value,+ http_client=httpx.Client(verify=False),+ default_headers={+ "editor-version": "vscode/1.95.0",+ "Copilot-Integration-Id": "vscode-chat",+ }+ if with_headers.value+ else {},)models = client.models.list().model_dump()return client, models@@ -58,6 +73,7 @@ def _(mo):@app.celldef _(client, ids, run_button):+ results = {}if run_button.value:for model in ids:try:@@ -66,10 +82,25 @@ def _(client, ids, run_button):messages=[{"role": "user", "content": "hi"}],max_tokens=100,)- print("✅ Model " + model + " passed: ")- print(response.choices[0].message.content)+ msg = (+ "✅ Model "+ + model+ + " passed: "+ + response.choices[0].message.content+ )+ print(msg)+ results[model] = msgexcept:- print("❌ Model " + model + " failed")+ msg = "❌ Model " + model + " failed"+ print(msg)+ results[model] = msg+ return (results,)+++def _(mo, results):+ mo.stop(not results)+ mo.ui.table(results, selection=None)returndiff --git a/packages/llm-info/data/models.yml b/packages/llm-info/data/models.ymlindex 9d1ef8b770..9902947e29 100644--- a/packages/llm-info/data/models.yml+++ b/packages/llm-info/data/models.yml@@ -149,14 +149,14 @@- name: GPT-5model: gpt-5description: The best model for coding and agentic tasks across domains- providers: [openai, azure]+ providers: [openai, azure, github]roles: [chat, edit]thinking: false- name: GPT-5 Minimodel: gpt-5-minidescription: A faster, cost-efficient version of GPT-5 for well-defined tasks- providers: [openai, azure]+ providers: [openai, azure, github]roles: [chat, edit]thinking: falsediff --git a/tests/_server/ai/test_ai_config.py b/tests/_server/ai/test_ai_config.pyindex af2431b941..d330acb603 100644--- a/tests/_server/ai/test_ai_config.py+++ b/tests/_server/ai/test_ai_config.py@@ -168,6 +168,55 @@ class TestAnyProviderConfig:assert provider_config.api_key == "test-github-key"assert provider_config.base_url == "https://api.githubcopilot.com/"+ def test_for_github_default_extra_headers(self):+ """Test GitHub configuration includes default extra headers."""+ config: AiConfig = {+ "github": {+ "api_key": "test-github-key",+ }+ }++ provider_config = AnyProviderConfig.for_github(config)++ assert provider_config.extra_headers is not None+ assert (+ provider_config.extra_headers["editor-version"] == "vscode/1.95.0"+ )+ assert (+ provider_config.extra_headers["Copilot-Integration-Id"]+ == "vscode-chat"+ )++ def test_for_github_user_headers_override_defaults(self):+ """Test GitHub configuration allows user headers to override defaults."""+ config: AiConfig = {+ "github": {+ "api_key": "test-github-key",+ "extra_headers": {+ "editor-version": "custom-editor/2.0.0",+ "X-Custom-Header": "custom-value",+ },+ }+ }++ provider_config = AnyProviderConfig.for_github(config)++ assert provider_config.extra_headers is not None+ # User header should override default+ assert (+ provider_config.extra_headers["editor-version"]+ == "custom-editor/2.0.0"+ )+ # Default header not overridden should remain+ assert (+ provider_config.extra_headers["Copilot-Integration-Id"]+ == "vscode-chat"+ )+ # Custom user header should be preserved+ assert (+ provider_config.extra_headers["X-Custom-Header"] == "custom-value"+ )+def test_for_openrouter(self):"""Test OpenRouter configuration."""config: AiConfig = {@@ -1105,9 +1154,18 @@ class TestSSLConfiguration:assert provider_config.client_pem == "/custom/path/to/client.pem", (f"{provider_name}: client_pem should match")- assert provider_config.extra_headers == {"X-Custom": "header"}, (- f"{provider_name}: extra_headers should match"- )+ # GitHub includes default headers that are merged with user headers+ if provider_name == "github":+ assert provider_config.extra_headers is not None+ assert "X-Custom" in provider_config.extra_headers+ assert provider_config.extra_headers["X-Custom"] == "header"+ # GitHub should also include default headers+ assert "editor-version" in provider_config.extra_headers+ assert "Copilot-Integration-Id" in provider_config.extra_headers+ else:+ assert provider_config.extra_headers == {"X-Custom": "header"}, (+ f"{provider_name}: extra_headers should match"+ )@pytest.mark.parametrize(("provider_name", "provider_method", "api_key_config"),