-
-
Notifications
You must be signed in to change notification settings - Fork 781
feat(novita): add Novita AI provider integration #1118
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Alex-wuhu
wants to merge
3
commits into
MervinPraison:main
Choose a base branch
from
Alex-wuhu:novita-integration
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+98
−0
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| """ | ||
| Novita AI integration example for PraisonAI Agents. | ||
|
|
||
| Novita AI provides an OpenAI-compatible endpoint, allowing you to use | ||
| high-quality open-source models (Kimi, DeepSeek, GLM, etc.) via the | ||
| standard interface. | ||
|
|
||
| Prerequisites: | ||
| Set your Novita AI API key as an environment variable: | ||
| export NOVITA_API_KEY="your-api-key-here" | ||
|
|
||
| Get your API key at: https://novita.ai | ||
| """ | ||
| import os | ||
| from praisonaiagents import Agent | ||
|
|
||
| api_key = os.environ.get("NOVITA_API_KEY") | ||
| if not api_key: | ||
| raise ValueError( | ||
| "The NOVITA_API_KEY environment variable is not set. " | ||
| "Please set it to your Novita AI API key." | ||
| ) | ||
|
|
||
| agent = Agent( | ||
| instructions="You are a helpful assistant", | ||
| llm="openai/moonshotai/kimi-k2.5", | ||
| base_url="https://api.novita.ai/openai", | ||
| api_key=api_key, | ||
| ) | ||
|
|
||
| agent.start("Why is the sky blue?") | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| """ | ||
| Tests for Novita AI provider integration. | ||
|
|
||
| Novita AI provides an OpenAI-compatible endpoint (https://api.novita.ai/openai), | ||
| allowing PraisonAI agents to use Kimi, DeepSeek, GLM, and other models. | ||
|
|
||
| These tests verify that the Agent class correctly accepts Novita configuration | ||
| without making real API calls. | ||
| """ | ||
|
|
||
| import pytest | ||
| from unittest.mock import patch | ||
| import os | ||
|
|
||
|
|
||
| class TestNovitaProviderConfig: | ||
| """Test that Agent accepts Novita AI provider configuration.""" | ||
|
|
||
| def test_agent_accepts_novita_base_url(self): | ||
| """Agent should accept Novita's OpenAI-compatible base_url.""" | ||
| from praisonaiagents import Agent | ||
|
|
||
| agent = Agent( | ||
| name="NovitaTest", | ||
| instructions="You are a helpful assistant", | ||
| llm="openai/moonshotai/kimi-k2.5", | ||
| base_url="https://api.novita.ai/openai", | ||
| api_key="test-novita-key", | ||
| ) | ||
| assert agent is not None | ||
| assert agent.base_url == "https://api.novita.ai/openai" | ||
|
|
||
| def test_agent_novita_api_key_from_env(self): | ||
| """Agent should read NOVITA_API_KEY from environment.""" | ||
| from praisonaiagents import Agent | ||
|
|
||
| with patch.dict(os.environ, {"NOVITA_API_KEY": "env-test-key"}): | ||
| agent = Agent( | ||
| name="NovitaEnvTest", | ||
| instructions="You are a helpful assistant", | ||
| llm="openai/moonshotai/kimi-k2.5", | ||
| base_url="https://api.novita.ai/openai", | ||
| api_key=os.environ.get("NOVITA_API_KEY"), | ||
| ) | ||
| assert agent is not None | ||
|
|
||
| @pytest.mark.parametrize( | ||
| "model_name", | ||
| [ | ||
| "openai/moonshotai/kimi-k2.5", | ||
| "openai/deepseek/deepseek-v3.2", | ||
| "openai/zai-org/glm-5", | ||
| ], | ||
| ) | ||
| def test_agent_novita_models(self, model_name): | ||
| """Agent should accept various Novita models and store them correctly.""" | ||
| from praisonaiagents import Agent | ||
|
|
||
| agent = Agent( | ||
| name=f"NovitaModelTest-{model_name.split('/')[-1]}", | ||
| instructions="You are a helpful assistant", | ||
| llm=model_name, | ||
| base_url="https://api.novita.ai/openai", | ||
| api_key="test-key", | ||
| ) | ||
| assert agent is not None | ||
| assert agent.llm == model_name |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The script currently passes
Noneto theAgentconstructor if theNOVITA_API_KEYenvironment variable is not set. This can lead to a less-than-obvious authentication error whenagent.start()is called. It would be more user-friendly to explicitly check for the presence of the API key and raise aValueErrorif it's missing. This provides a clear and immediate error message to the user.