Spaces:
Sleeping
Sleeping
Create state.py
Browse files- src/langgraph_logic/state.py +70 -0
src/langgraph_logic/state.py
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from typing import Dict, Any, Optional, List
|
| 2 |
+
from pydantic import BaseModel, Field
|
| 3 |
+
from typing import Literal
|
| 4 |
+
|
| 5 |
+
class ParsedComment(BaseModel):
|
| 6 |
+
"""
|
| 7 |
+
Represents a single parsed comment from the LLM's review,
|
| 8 |
+
intended for grouping by file/function.
|
| 9 |
+
"""
|
| 10 |
+
message: str
|
| 11 |
+
suggestion: Optional[str] = None
|
| 12 |
+
|
| 13 |
+
def __repr__(self):
|
| 14 |
+
return f"ParsedComment(msg='{self.message[:50]}...', has_suggestion={self.suggestion is not None})"
|
| 15 |
+
|
| 16 |
+
class ParsedReviewSection(BaseModel):
|
| 17 |
+
"""
|
| 18 |
+
Represents a categorized section of the review, e.g., 'Potential Issues'.
|
| 19 |
+
"""
|
| 20 |
+
title: str
|
| 21 |
+
content: str
|
| 22 |
+
|
| 23 |
+
def __repr__(self):
|
| 24 |
+
return f"ParsedReviewSection(title='{self.title}', content='{self.content[:50]}...')"
|
| 25 |
+
|
| 26 |
+
class FileReviewComments(BaseModel):
|
| 27 |
+
"""
|
| 28 |
+
Represents comments specific to a file, potentially grouped by function or general file comments.
|
| 29 |
+
"""
|
| 30 |
+
file_path: str
|
| 31 |
+
sections: Dict[str, List[ParsedComment]] = Field(default_factory=dict)
|
| 32 |
+
|
| 33 |
+
class LLMReviewOutput(BaseModel):
|
| 34 |
+
"""
|
| 35 |
+
Structured data representing the comprehensive review output from the LLM.
|
| 36 |
+
"""
|
| 37 |
+
overall_impression: Optional[str] = None
|
| 38 |
+
file_reviews: List[FileReviewComments] = Field(default_factory=list)
|
| 39 |
+
general_sections: List[ParsedReviewSection] = Field(default_factory=list)
|
| 40 |
+
summary: Optional[str] = None
|
| 41 |
+
approval_status: str = "Comment"
|
| 42 |
+
|
| 43 |
+
class PRReviewState(BaseModel):
|
| 44 |
+
repo_name: str
|
| 45 |
+
pr_id: int
|
| 46 |
+
pr_title: Optional[str]
|
| 47 |
+
code_diff: Optional[str]
|
| 48 |
+
file_contents: Optional[Dict[str, str]]
|
| 49 |
+
llm_markdown_review: Optional[str]
|
| 50 |
+
parsed_llm_review_data: Optional[LLMReviewOutput] = None
|
| 51 |
+
main_comment_body: Optional[str]
|
| 52 |
+
review_status: Literal[
|
| 53 |
+
"initiated",
|
| 54 |
+
"code_fetched",
|
| 55 |
+
"code_reviewed",
|
| 56 |
+
"review_parsed",
|
| 57 |
+
"initial_review_posted",
|
| 58 |
+
"awaiting_human_approval",
|
| 59 |
+
"review_submitted",
|
| 60 |
+
"review_dismissed",
|
| 61 |
+
"error"
|
| 62 |
+
]
|
| 63 |
+
require_human_approval: bool
|
| 64 |
+
human_approval_status: Optional[bool]
|
| 65 |
+
human_feedback_message: Optional[str]
|
| 66 |
+
original_review_id: Optional[int]
|
| 67 |
+
original_review_url: Optional[str]
|
| 68 |
+
final_review_id: Optional[int]
|
| 69 |
+
final_review_url: Optional[str]
|
| 70 |
+
last_error: Optional[str]
|