forked from vitali87/code-graph-rag
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathschemas.py
More file actions
53 lines (40 loc) · 1.42 KB
/
Copy pathschemas.py
File metadata and controls
53 lines (40 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
from typing import Any
from pydantic import BaseModel, ConfigDict, Field, field_validator
class GraphData(BaseModel):
"""Data model for results returned from the knowledge graph tool."""
query_used: str
results: list[dict[str, Any]]
summary: str = Field(description="A brief summary of the operation's outcome.")
@field_validator("results", mode="before")
@classmethod
def _format_results(cls, v: Any) -> list[dict[str, Any]]:
if not isinstance(v, list):
return [] # Return empty list instead of v
clean_results = []
for row in v:
clean_row = {}
for k, val in row.items():
if not isinstance(
val, str | int | float | bool | list | dict | type(None)
):
clean_row[k] = str(val)
else:
clean_row[k] = val # type: ignore
clean_results.append(clean_row)
return clean_results
model_config = ConfigDict(extra="forbid")
class CodeSnippet(BaseModel):
"""Data model for code snippet results."""
qualified_name: str
source_code: str
file_path: str
line_start: int
line_end: int
docstring: str | None = None
found: bool = True
error_message: str | None = None
class ShellCommandResult(BaseModel):
"""Data model for shell command results."""
return_code: int
stdout: str
stderr: str