Skip to content
Merged
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
5 changes: 1 addition & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,8 @@ format:
uvx ruff check --fix ./aperag
uvx ruff format --preview ./aperag

lint:
uvx ruff check --preview ./aperag

static-check:
uvx mypy .
uvx mypy ./aperag

test:
pytest tests/ -v
Expand Down
5 changes: 1 addition & 4 deletions aperag/api/components/schemas/flow.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,7 @@ components:
items:
$ref: '#/components/schemas/Edge'
style:
type: object
description: Workflow style
additionalProperties:
$ref: '#/components/schemas/WorkflowStyle'
$ref: '#/components/schemas/WorkflowStyle'

WorkflowStyle:
type: object
Expand Down
3 changes: 0 additions & 3 deletions aperag/chat/history/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,6 @@ def clear(self):
f.write("[]")
"""

messages: List[BaseMessage]
"""A list of Messages stored in-memory."""

async def add_user_message(self, message: str) -> None:
"""Convenience method for adding a human message string to the store.

Expand Down
5 changes: 1 addition & 4 deletions aperag/docparser/doc_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@
DocRayParser,
]

PARSER_MAP = {
cls.name: cls
for cls in ALL_PARSERS
}
PARSER_MAP = {cls.name: cls for cls in ALL_PARSERS}


def get_default_config() -> list["ParserConfig"]:
Expand Down
20 changes: 9 additions & 11 deletions aperag/docparser/docray_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,17 +191,15 @@ def convert_para(
) -> list[Part]:
para_type = para_block["type"]
bbox = para_block.get("bbox", (0, 0, 0, 0))
metadata.update(
{
"pdf_source_map": [
{
"page_idx": page_idx,
"bbox": tuple(bbox),
}
],
"para_type": str(para_type),
}
)
metadata.update({
"pdf_source_map": [
{
"page_idx": page_idx,
"bbox": tuple(bbox),
}
],
"para_type": str(para_type),
})

if para_type in [BlockType.Text, BlockType.List, BlockType.Index]:
return [
Expand Down
2 changes: 1 addition & 1 deletion aperag/flow/runners/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@
"RerankNodeRunner",
"StartNodeRunner",
"VectorSearchNodeRunner",
]
]
12 changes: 3 additions & 9 deletions aperag/query/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,12 @@ class Source(str, Enum):
APP = "app"


class Document(BaseModel):
source: Source = Source.FILE
doc_id: str = None
text: str = None


class DocumentWithScore(BaseModel):
source: Source = Source.FILE
doc_id: str = None
text: str = None
doc_id: Optional[str] = None
text: Optional[str] = None
score: float
metadata: dict = None
metadata: Optional[dict] = None

def get_source_file(self) -> str:
return self.metadata["source"]
Expand Down
6 changes: 2 additions & 4 deletions aperag/schema/view_models.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# generated by datamodel-codegen:
# filename: openapi.merged.yaml
# timestamp: 2025-05-27T07:34:21+00:00
# timestamp: 2025-05-27T09:17:08+00:00

from __future__ import annotations

Expand Down Expand Up @@ -224,9 +224,7 @@ class WorkflowDefinition(BaseModel):
edges: list[Edge] = Field(
..., description='List of edges connecting nodes in the workflow'
)
style: Optional[dict[str, WorkflowStyle]] = Field(
None, description='Workflow style'
)
style: Optional[WorkflowStyle] = None


class DebugFlowRequest(BaseModel):
Expand Down
9 changes: 5 additions & 4 deletions aperag/service/flow_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ async def debug_flow_stream(user: str, bot_id: str, debug: view_models.DebugFlow
return StreamingHttpResponse(json.dumps({"error": str(e)}), content_type="application/json")


async def get_flow(user, bot_id):
async def get_flow(user: str, bot_id: str) -> view_models.WorkflowDefinition:
"""Get flow config for a bot"""
bot = await query_bot(user, bot_id)
if not bot:
Expand All @@ -110,16 +110,17 @@ async def get_flow(user, bot_id):
return fail(HTTPStatus.INTERNAL_SERVER_ERROR, message=str(e))


async def update_flow(user, bot_id, data):
async def update_flow(user: str, bot_id: str, data: view_models.WorkflowDefinition):
"""Update flow config for a bot"""
bot = await query_bot(user, bot_id)
if not bot:
return fail(HTTPStatus.NOT_FOUND, message="Bot not found")
try:
config = json.loads(bot.config or "{}")
config["flow"] = data.dict(exclude_unset=True)
flow = data.model_dump(exclude_unset=True, by_alias=True)
config["flow"] = flow
bot.config = json.dumps(config, ensure_ascii=False)
await bot.asave()
return success(data)
return success(flow)
except Exception as e:
return fail(HTTPStatus.INTERNAL_SERVER_ERROR, message=str(e))
1 change: 1 addition & 0 deletions aperag/vectorstore/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ def __init__(self, ctx: Dict[str, Any], **kwargs: Any) -> None:
self.embedding: BaseEmbedding = None
self.store: VectorStore = None

@abstractmethod
def search(self, query: QueryWithEmbedding, **kwargs) -> QueryResult:
pass

Expand Down
12 changes: 8 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ dependencies = [
"arrow<2.0.0,>=1.2.3",
"func-timeout<5.0.0,>=4.3.5",
"terminal<1.0.0,>=0.4.0",
"types-chardet<6.0.0.0,>=5.0.4.6",
"psycopg2-binary<3.0.0,>=2.9.6",
"watchfiles<1.0.0,>=0.19.0",
"flower<3.0.0,>=2.0.0",
Expand All @@ -35,7 +34,6 @@ dependencies = [
"socksio<2.0.0,>=1.0.0",
"django-prometheus<3.0.0,>=2.3.1",
"whitenoise<7.0.0,>=6.5.0",
"types-requests<3.0.0.0,>=2.31.0.2",
"elasticsearch<9.0.0,>=8.9.0",
"gevent<24.0.0,>=23.9.1",
"requests<3.0.0,>=2.31.0",
Expand Down Expand Up @@ -99,6 +97,8 @@ dev = [
"types-toml<1.0.0.0,>=0.10.8.1",
"types-redis<5.0.0.0,>=4.3.21.6",
"types-chardet<6.0.0.0,>=5.0.4.6",
"types-requests>=2.31.0.2,<3.0.0.0",
"types-chardet<6.0.0.0,>=5.0.4.6",
"vulture<3.0,>=2.14",
"deptry<1.0.0,>=0.23.0",
"mypy<2.0.0,>=1.4.1",
Expand Down Expand Up @@ -159,8 +159,11 @@ exclude = [
line-length = 120

[tool.mypy]
ignore_missing_imports = "True"
disallow_untyped_defs = "False"
ignore_missing_imports = true
disallow_untyped_defs = false
# https://discuss.python.org/t/mypy-dir-is-excluded-but-then-errors-are-thrown-for-files-within-the-dir/75952
# https://mypy.readthedocs.io/en/stable/running_mypy.html#following-imports
follow_imports = "silent"
exclude = [
"playground",
"services/text2SQL",
Expand All @@ -170,6 +173,7 @@ exclude = [
"aperag/migrations",
"vectorstore/test_connector.py",
"readers/test_local_path_embedding.py",
"aperag/schema/view_models.py",
]

[tool.setuptools]
Expand Down
Loading
Loading