mirror of
https://github.com/tiennm99/DocsGPT.git
synced 2026-10-04 10:13:06 +00:00
The backend import package is now docsgpt, the name it will carry on PyPI; application was far too generic to install into anyone's site-packages. git mv plus a mechanical rewrite of every import, dotted string and path reference: 734 Python files, the compose files, Dockerfile, workflows, docs, setup scripts, devcontainer, k8s manifests, vscode config, pytest and coverage config, .gitignore. Behaviour is unchanged. Kept for one release: - A top-level application package whose meta-path finder resolves application.x.y to the already-imported docsgpt.x.y object, so old imports and entry points (celery -A application.app.celery, uvicorn application.asgi:asgi_app) keep working with a FutureWarning. - Celery registers every application.* task name as an alias of its docsgpt.* task on start-up, so messages queued by the previous release still run. The redbeat key prefix moves to redbeat:docsgpt:v2: so schedule entries the previous release wrote are left unread instead of firing twice. The backend image builds from the repository root (docker build -f docsgpt/Dockerfile .) so it can ship the alias package; a root .dockerignore allow-lists docsgpt/ and application/ and keeps caches, local data, .env files, the sample index files and the Dockerfile out. Compose and the image workflows point at the new context.
53 lines
2.3 KiB
Python
53 lines
2.3 KiB
Python
import pytest
|
|
from docsgpt.agents.agent_creator import AgentCreator
|
|
from docsgpt.agents.classic_agent import ClassicAgent
|
|
|
|
|
|
@pytest.mark.unit
|
|
class TestAgentCreator:
|
|
|
|
def test_create_classic_agent(self, agent_base_params):
|
|
agent = AgentCreator.create_agent("classic", **agent_base_params)
|
|
assert isinstance(agent, ClassicAgent)
|
|
assert agent.endpoint == agent_base_params["endpoint"]
|
|
assert agent.llm_name == agent_base_params["llm_name"]
|
|
assert agent.model_id == agent_base_params["model_id"]
|
|
|
|
def test_create_react_falls_back_to_classic(self, agent_base_params):
|
|
agent = AgentCreator.create_agent("react", **agent_base_params)
|
|
assert isinstance(agent, ClassicAgent)
|
|
|
|
def test_create_agent_case_insensitive(self, agent_base_params):
|
|
agent_upper = AgentCreator.create_agent("CLASSIC", **agent_base_params)
|
|
agent_mixed = AgentCreator.create_agent("ClAsSiC", **agent_base_params)
|
|
|
|
assert isinstance(agent_upper, ClassicAgent)
|
|
assert isinstance(agent_mixed, ClassicAgent)
|
|
|
|
def test_create_agent_invalid_type(self, agent_base_params):
|
|
with pytest.raises(ValueError, match="No agent class found for type"):
|
|
AgentCreator.create_agent("invalid_agent_type", **agent_base_params)
|
|
|
|
def test_agent_registry_contains_expected_agents(self):
|
|
assert "classic" in AgentCreator.agents
|
|
assert "react" in AgentCreator.agents
|
|
assert AgentCreator.agents["classic"] == ClassicAgent
|
|
|
|
def test_create_agent_with_optional_params(self, agent_base_params):
|
|
agent_base_params["user_api_key"] = "user_key_123"
|
|
agent_base_params["chat_history"] = [{"prompt": "test", "response": "test"}]
|
|
agent_base_params["json_schema"] = {"type": "object"}
|
|
|
|
agent = AgentCreator.create_agent("classic", **agent_base_params)
|
|
|
|
assert agent.user_api_key == "user_key_123"
|
|
assert len(agent.chat_history) == 1
|
|
assert agent.json_schema == {"type": "object"}
|
|
|
|
def test_create_agent_with_attachments(self, agent_base_params):
|
|
attachments = [{"name": "file.txt", "content": "test"}]
|
|
agent_base_params["attachments"] = attachments
|
|
|
|
agent = AgentCreator.create_agent("classic", **agent_base_params)
|
|
assert agent.attachments == attachments
|