Skip to content

Commit 6fae638

Browse files
Copilotpamelafox
andauthored
Replace Azure Inference URL with GitHub Models API URL (#236)
* Initial plan * Replace Azure Inference URL with GitHub Models API URL and update model names Co-authored-by: pamelafox <[email protected]> * Remove GITHUB_BASE_URL env var and hard-code GitHub Models URL Co-authored-by: pamelafox <[email protected]> * Format test file with ruff to fix CI formatting check Co-authored-by: pamelafox <[email protected]> --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: pamelafox <[email protected]>
1 parent 64672ca commit 6fae638

File tree

4 files changed

+52
-13
lines changed

4 files changed

+52
-13
lines changed

.env.sample

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@ OLLAMA_EMBED_MODEL=nomic-embed-text
3737
OLLAMA_EMBEDDING_COLUMN=embedding_nomic
3838
# Needed for GitHub Models:
3939
GITHUB_TOKEN=YOUR-GITHUB-TOKEN
40-
GITHUB_BASE_URL=https://models.inference.ai.azure.com
41-
GITHUB_MODEL=gpt-4o
42-
GITHUB_EMBED_MODEL=text-embedding-3-large
40+
GITHUB_MODEL=openai/gpt-4o
41+
GITHUB_EMBED_MODEL=openai/text-embedding-3-large
4342
GITHUB_EMBED_DIMENSIONS=1024
4443
GITHUB_EMBEDDING_COLUMN=embedding_3l

src/backend/fastapi_app/dependencies.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ async def common_parameters():
5353
embedding_column = os.getenv("OLLAMA_EMBEDDING_COLUMN") or "embedding_nomic"
5454
elif OPENAI_EMBED_HOST == "github":
5555
openai_embed_deployment = None
56-
openai_embed_model = os.getenv("GITHUB_EMBED_MODEL") or "text-embedding-3-large"
56+
openai_embed_model = os.getenv("GITHUB_EMBED_MODEL") or "openai/text-embedding-3-large"
5757
openai_embed_dimensions = int(os.getenv("GITHUB_EMBED_DIMENSIONS", 1024))
5858
embedding_column = os.getenv("GITHUB_EMBEDDING_COLUMN") or "embedding_3l"
5959
else:
@@ -70,7 +70,7 @@ async def common_parameters():
7070
openai_embed_model = os.getenv("OLLAMA_EMBED_MODEL") or "nomic-embed-text"
7171
elif OPENAI_CHAT_HOST == "github":
7272
openai_chat_deployment = None
73-
openai_chat_model = os.getenv("GITHUB_MODEL") or "gpt-4o"
73+
openai_chat_model = os.getenv("GITHUB_MODEL") or "openai/gpt-4o"
7474
else:
7575
openai_chat_deployment = None
7676
openai_chat_model = os.getenv("OPENAICOM_CHAT_MODEL") or "gpt-3.5-turbo"

src/backend/fastapi_app/openai_clients.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,10 @@ async def create_openai_chat_client(
5454
)
5555
elif OPENAI_CHAT_HOST == "github":
5656
logger.info("Setting up OpenAI client for chat completions using GitHub Models")
57-
github_base_url = os.getenv("GITHUB_BASE_URL", "https://models.inference.ai.azure.com")
58-
github_model = os.getenv("GITHUB_MODEL", "gpt-4o")
59-
logger.info(f"Using GitHub Models with base URL: {github_base_url}, model: {github_model}")
57+
github_model = os.getenv("GITHUB_MODEL", "openai/gpt-4o")
58+
logger.info(f"Using GitHub Models with model: {github_model}")
6059
openai_chat_client = openai.AsyncOpenAI(
61-
base_url=github_base_url,
60+
base_url="https://models.github.ai/inference",
6261
api_key=os.getenv("GITHUB_TOKEN"),
6362
)
6463
else:
@@ -114,11 +113,10 @@ async def create_openai_embed_client(
114113
)
115114
elif OPENAI_EMBED_HOST == "github":
116115
logger.info("Setting up OpenAI client for embeddings using GitHub Models")
117-
github_base_url = os.getenv("GITHUB_BASE_URL", "https://models.inference.ai.azure.com")
118-
github_embed_model = os.getenv("GITHUB_EMBED_MODEL", "text-embedding-3-small")
119-
logger.info(f"Using GitHub Models with base URL: {github_base_url}, embedding model: {github_embed_model}")
116+
github_embed_model = os.getenv("GITHUB_EMBED_MODEL", "openai/text-embedding-3-small")
117+
logger.info(f"Using GitHub Models with embedding model: {github_embed_model}")
120118
openai_embed_client = openai.AsyncOpenAI(
121-
base_url=github_base_url,
119+
base_url="https://models.github.ai/inference",
122120
api_key=os.getenv("GITHUB_TOKEN"),
123121
)
124122
else:

tests/test_openai_clients.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import pytest
22

3+
from fastapi_app.dependencies import common_parameters
34
from fastapi_app.openai_clients import create_openai_chat_client, create_openai_embed_client
45
from tests.data import test_data
56

@@ -22,3 +23,44 @@ async def test_create_openai_chat_client(mock_azure_credential, mock_openai_chat
2223
model="gpt-4o-mini", messages=[{"content": "test", "role": "user"}]
2324
)
2425
assert response.choices[0].message.content == "The capital of France is Paris. [Benefit_Options-2.pdf]."
26+
27+
28+
@pytest.mark.asyncio
29+
async def test_github_models_configuration(monkeypatch):
30+
"""Test that GitHub Models uses the correct URLs and model names."""
31+
# Set up environment for GitHub Models
32+
monkeypatch.setenv("OPENAI_CHAT_HOST", "github")
33+
monkeypatch.setenv("OPENAI_EMBED_HOST", "github")
34+
monkeypatch.setenv("GITHUB_TOKEN", "fake-token")
35+
# Don't set GITHUB_MODEL to test defaults
36+
37+
# Test chat client configuration
38+
chat_client = await create_openai_chat_client(None)
39+
assert str(chat_client.base_url).rstrip("/") == "https://models.github.ai/inference"
40+
assert chat_client.api_key == "fake-token"
41+
42+
# Test embed client configuration
43+
embed_client = await create_openai_embed_client(None)
44+
assert str(embed_client.base_url).rstrip("/") == "https://models.github.ai/inference"
45+
assert embed_client.api_key == "fake-token"
46+
47+
# Test that dependencies use correct defaults
48+
context = await common_parameters()
49+
assert context.openai_chat_model == "openai/gpt-4o"
50+
assert context.openai_embed_model == "openai/text-embedding-3-large"
51+
52+
53+
@pytest.mark.asyncio
54+
async def test_github_models_with_custom_values(monkeypatch):
55+
"""Test that GitHub Models respects custom environment values."""
56+
# Set up environment for GitHub Models with custom values
57+
monkeypatch.setenv("OPENAI_CHAT_HOST", "github")
58+
monkeypatch.setenv("OPENAI_EMBED_HOST", "github")
59+
monkeypatch.setenv("GITHUB_TOKEN", "fake-token")
60+
monkeypatch.setenv("GITHUB_MODEL", "openai/gpt-4")
61+
monkeypatch.setenv("GITHUB_EMBED_MODEL", "openai/text-embedding-ada-002")
62+
63+
# Test that dependencies use custom values
64+
context = await common_parameters()
65+
assert context.openai_chat_model == "openai/gpt-4"
66+
assert context.openai_embed_model == "openai/text-embedding-ada-002"

0 commit comments

Comments
 (0)