Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions src/praisonai-agents/novita-basic.py
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,
)
Comment on lines +24 to +29
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The script currently passes None to the Agent constructor if the NOVITA_API_KEY environment variable is not set. This can lead to a less-than-obvious authentication error when agent.start() is called. It would be more user-friendly to explicitly check for the presence of the API key and raise a ValueError if it's missing. This provides a clear and immediate error message to the user.

Suggested change
agent = Agent(
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"),
)
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?")
67 changes: 67 additions & 0 deletions src/praisonai-agents/tests/unit/test_novita_provider.py
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