11import pytest
22
3+ from fastapi_app .dependencies import common_parameters
34from fastapi_app .openai_clients import create_openai_chat_client , create_openai_embed_client
45from tests .data import test_data
56
@@ -22,3 +23,45 @@ 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_BASE_URL or 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_BASE_URL" , "https://custom.github.ai/inference" )
61+ monkeypatch .setenv ("GITHUB_MODEL" , "openai/gpt-4" )
62+ monkeypatch .setenv ("GITHUB_EMBED_MODEL" , "openai/text-embedding-ada-002" )
63+
64+ # Test that dependencies use custom values
65+ context = await common_parameters ()
66+ assert context .openai_chat_model == "openai/gpt-4"
67+ assert context .openai_embed_model == "openai/text-embedding-ada-002"
0 commit comments