mozzic commited on
Commit
6a8cd1b
·
verified ·
1 Parent(s): 7d94266

Upload src\models.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. src//models.py +87 -0
src//models.py ADDED
@@ -0,0 +1,87 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Data models for Context Thread Agent
3
+ """
4
+
5
+ from typing import List, Dict, Optional, Any
6
+ from dataclasses import dataclass
7
+ from enum import Enum
8
+
9
+
10
+ class CellType(Enum):
11
+ CODE = "code"
12
+ MARKDOWN = "markdown"
13
+ RAW = "raw"
14
+
15
+
16
+ @dataclass
17
+ class Cell:
18
+ """Represents a Jupyter notebook cell."""
19
+ cell_id: str
20
+ cell_type: CellType
21
+ source: str
22
+ outputs: List[Dict[str, Any]] = None
23
+
24
+ def __post_init__(self):
25
+ if self.outputs is None:
26
+ self.outputs = []
27
+
28
+
29
+ @dataclass
30
+ class ContextUnit:
31
+ """A cell with its context and dependencies."""
32
+ cell: Cell
33
+ intent: str
34
+ dependencies: List[str]
35
+ context_window: List[str] = None
36
+
37
+ def __post_init__(self):
38
+ if self.context_window is None:
39
+ self.context_window = []
40
+
41
+
42
+ @dataclass
43
+ class ContextThread:
44
+ """A thread of related context units."""
45
+ notebook_name: str
46
+ thread_id: str
47
+ units: List[ContextUnit]
48
+ metadata: Dict[str, Any] = None
49
+
50
+ def __post_init__(self):
51
+ if self.metadata is None:
52
+ self.metadata = {}
53
+
54
+
55
+ @dataclass
56
+ class QueryRequest:
57
+ """A user query request."""
58
+ query: str
59
+ notebook_path: Optional[str] = None
60
+ top_k: int = 5
61
+
62
+
63
+ @dataclass
64
+ class Citation:
65
+ """A citation to a specific cell."""
66
+ cell_id: str
67
+ cell_type: CellType
68
+ content_snippet: str
69
+ intent: Optional[str] = None
70
+
71
+
72
+ @dataclass
73
+ class AgentResponse:
74
+ """Response from the agent."""
75
+ answer: str
76
+ citations: List[Citation]
77
+ confidence: float
78
+ has_hallucination_risk: bool
79
+ retrieved_units: List[ContextUnit]
80
+
81
+
82
+ @dataclass
83
+ class RetrievalResult:
84
+ """Result from retrieval system."""
85
+ units: List[ContextUnit]
86
+ scores: List[float]
87
+ query: str