From 4258295a079cc2b596190d106b76b53635c51059 Mon Sep 17 00:00:00 2001 From: Krrish Dholakia Date: Sat, 3 Aug 2024 09:11:22 -0700 Subject: [PATCH] feat(utils.py): Add github as a provider Closes https://github.com/BerriAI/litellm/issues/4922#issuecomment-2266564469 --- litellm/__init__.py | 2 ++ litellm/tests/test_completion.py | 30 ++++++++++++++++++++++++++++++ litellm/utils.py | 4 ++++ 3 files changed, 36 insertions(+) diff --git a/litellm/__init__.py b/litellm/__init__.py index 0bbccf82719..f11d117b039 100644 --- a/litellm/__init__.py +++ b/litellm/__init__.py @@ -458,6 +458,7 @@ openai_compatible_providers: List = [ "empower", "friendliai", "azure_ai", + "github", ] @@ -698,6 +699,7 @@ provider_list: List = [ "predibase", "databricks", "empower", + "github", "custom", # custom apis ] diff --git a/litellm/tests/test_completion.py b/litellm/tests/test_completion.py index df5f693f739..c26035ad0ad 100644 --- a/litellm/tests/test_completion.py +++ b/litellm/tests/test_completion.py @@ -344,6 +344,36 @@ def test_completion_empower(): pytest.fail(f"Error occurred: {e}") +def test_completion_github_api(): + litellm.set_verbose = True + messages = [ + { + "role": "user", + "content": "\nWhat is the query for `console.log` => `console.error`\n", + }, + { + "role": "assistant", + "content": "\nThis is the GritQL query for the given before/after examples:\n\n`console.log` => `console.error`\n\n", + }, + { + "role": "user", + "content": "\nWhat is the query for `console.info` => `consdole.heaven`\n", + }, + ] + try: + # test without max tokens + response = completion( + model="github/gpt-4o", + messages=messages, + ) + # Add any assertions, here to check response args + print(response) + except litellm.AuthenticationError: + pass + except Exception as e: + pytest.fail(f"Error occurred: {e}") + + def test_completion_claude_3_empty_response(): litellm.set_verbose = True diff --git a/litellm/utils.py b/litellm/utils.py index 713fe4f2ae5..b6d00536f4d 100644 --- a/litellm/utils.py +++ b/litellm/utils.py @@ -4513,6 +4513,10 @@ def get_llm_provider( elif custom_llm_provider == "azure_ai": api_base = api_base or get_secret("AZURE_AI_API_BASE") # type: ignore dynamic_api_key = api_key or get_secret("AZURE_AI_API_KEY") + elif custom_llm_provider == "github": + api_base = api_base or get_secret("GITHUB_API_BASE") or "https://models.inference.ai.azure.com" # type: ignore + dynamic_api_key = api_key or get_secret("GITHUB_API_KEY") + elif custom_llm_provider == "mistral": # mistral is openai compatible, we just need to set this to custom_openai and have the api_base be https://api.mistral.ai api_base = (