vector-bridge 1.0.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
File without changes
@@ -0,0 +1,34 @@
1
+ from typing import Dict, List, Optional, Union
2
+
3
+ from pydantic import BaseModel, ConfigDict, Field
4
+
5
+
6
+ class PresignedUploadUrl(BaseModel):
7
+ url: str
8
+ body: dict
9
+
10
+
11
+ class BaseAIKnowledgeChunk(BaseModel):
12
+ item_id: str
13
+ index: int
14
+ content: str
15
+
16
+
17
+ class BaseAIKnowledge(BaseModel):
18
+ model_config = ConfigDict(from_attributes=True)
19
+ schema_name: str = Field(default="")
20
+ unique_identifier: str = Field(default="")
21
+ content: Optional[str] = None
22
+ timestamp: str
23
+
24
+ _chunk_size: int = 384
25
+ _chunk_overlap: int = 76
26
+
27
+
28
+ class AIKnowledgeList(BaseModel):
29
+ model_config = ConfigDict(from_attributes=True)
30
+
31
+ items: List[Dict]
32
+ limit: Union[int, None] = Field(default=None)
33
+ offset: Union[int, None] = Field(default=None)
34
+ has_more: bool = Field(default=False)
@@ -0,0 +1,140 @@
1
+ from typing import Dict, List, Optional, Union
2
+ from uuid import uuid4
3
+
4
+ from pydantic import BaseModel, ConfigDict, Field
5
+
6
+ from vector_bridge.schema.ai_knowledge import BaseAIKnowledge
7
+ from vector_bridge.schema.helpers.enums import FileSystemType, SortOrder
8
+
9
+ # CREATES ---
10
+
11
+
12
+ class AIKnowledgeFileSystemItemCreate(BaseAIKnowledge):
13
+ model_config = ConfigDict(from_attributes=True)
14
+
15
+ name: str = Field(default=None)
16
+ parent_id: Optional[str] = Field(default=None)
17
+ source_documents_ids: Optional[List[str]] = Field(default_factory=list)
18
+ type: FileSystemType = Field(default=FileSystemType.FILE)
19
+ file_size_bytes: int = Field(default=0)
20
+ starred: bool = Field(default=False)
21
+ tags: List[str] = Field(default_factory=list)
22
+ private: bool = Field(default=False)
23
+ users_with_read_access: List[str] = Field(default_factory=list)
24
+ users_with_write_access: List[str] = Field(default_factory=list)
25
+ groups_with_read_access: List[str] = Field(default_factory=list)
26
+ groups_with_write_access: List[str] = Field(default_factory=list)
27
+ created_by: str
28
+ cloud_stored: bool = Field(default=False)
29
+ vectorized: bool = Field(default=True)
30
+
31
+
32
+ # OUTPUTS ---
33
+
34
+
35
+ class AIKnowledgeFileSystemItemChunk(BaseModel):
36
+ item_id: str = Field(default_factory=lambda: str(uuid4()))
37
+ index: int
38
+ content: str
39
+
40
+
41
+ class AIKnowledgeFileSystemItem(BaseModel):
42
+ model_config = ConfigDict(from_attributes=True)
43
+
44
+ item_id: str
45
+ name: str
46
+ chunks: List[AIKnowledgeFileSystemItemChunk] = Field(default_factory=list)
47
+ parent: Optional["AIKnowledgeFileSystemItem"] = Field(default=None)
48
+ source_documents: List["AIKnowledgeFileSystemItem"] = Field(default_factory=list)
49
+ derived_documents: List["AIKnowledgeFileSystemItem"] = Field(default_factory=list)
50
+ parent_id: Optional[str]
51
+ parent_ids_hierarchy: List[str]
52
+ type: FileSystemType
53
+ file_size_bytes: int
54
+ starred: bool
55
+ tags: List[str]
56
+ private: bool
57
+ users_with_read_access: List[str]
58
+ users_with_write_access: List[str]
59
+ groups_with_read_access: List[str]
60
+ groups_with_write_access: List[str]
61
+ unique_identifier: str
62
+ timestamp: str
63
+ created_by: str
64
+ cloud_stored: bool
65
+ vectorized: bool = Field(default=True)
66
+ archived: bool = Field(default=False)
67
+
68
+
69
+ AIKnowledgeFileSystemItem.model_rebuild()
70
+
71
+
72
+ class AIKnowledgeFileSystemItemsList(BaseModel):
73
+ model_config = ConfigDict(from_attributes=True)
74
+
75
+ items: List[AIKnowledgeFileSystemItem]
76
+ limit: Union[int, None] = Field(default=None)
77
+ offset: Union[int, None] = Field(default=None)
78
+ has_more: bool = Field(default=False)
79
+
80
+
81
+ class AIKnowledgeFileSystemFilters(BaseModel):
82
+ file_name_like: str = Field(default=None)
83
+ file_name_equal: str = Field(default=None)
84
+ item_id: str = Field(default=None)
85
+ parent_id: str = Field(default=None)
86
+ parent_id_is_null: bool = Field(default=None)
87
+ parent_ids_hierarchy_contains_any: List[str] = Field(default=None)
88
+ source_documents_ids_contains_any: List[str] = Field(default=None)
89
+ source_documents_ids_contains_all: List[str] = Field(default=None)
90
+ type: FileSystemType = Field(default=None)
91
+ is_starred: bool = Field(default=None)
92
+ tags_contains_any: List[str] = Field(default=None)
93
+ tags_contains_all: List[str] = Field(default=None)
94
+ is_private: bool = Field(default=None)
95
+ users_with_read_access_contains_any: List[str] = Field(default=None)
96
+ users_with_read_access_contains_all: List[str] = Field(default=None)
97
+ users_with_write_access_contains_any: List[str] = Field(default=None)
98
+ users_with_write_access_contains_all: List[str] = Field(default=None)
99
+ groups_with_read_access_contains_any: List[str] = Field(default=None)
100
+ groups_with_read_access_contains_all: List[str] = Field(default=None)
101
+ groups_with_write_access_contains_any: List[str] = Field(default=None)
102
+ groups_with_write_access_contains_all: List[str] = Field(default=None)
103
+ unique_identifier: str = Field(default="")
104
+ file_size_bytes_min: int = Field(default=None)
105
+ file_size_bytes_max: int = Field(default=None)
106
+ timestamp_after: str = Field(default="")
107
+ timestamp_before: str = Field(default="")
108
+ is_cloud_stored: bool = Field(default=None)
109
+ is_vectorized: bool = Field(default=None)
110
+ is_archived: bool = Field(default=None)
111
+ limit: int = Field(default=100)
112
+ offset: int = Field(default=None)
113
+ sort_by: str = Field(default="timestamp")
114
+ sort_order: SortOrder = Field(default=SortOrder.DESCENDING)
115
+
116
+ def to_non_empty_dict(self):
117
+ _dict = self.model_dump()
118
+ return {k: v for k, v in _dict.items() if v is not None and v != ""}
119
+
120
+ def to_serializible_non_empty_dict(self):
121
+ _dict = self.model_dump()
122
+ if self.sort_order:
123
+ _dict["sort_order"] = self.sort_order.value
124
+ if self.type:
125
+ _dict["type"] = self.type.value
126
+ return {k: v for k, v in _dict.items() if v is not None and v != ""}
127
+
128
+
129
+ class FileSystemItemArchivedCount(BaseModel):
130
+ files: int
131
+ archived_files: int
132
+
133
+
134
+ class FileSystemItemCount(BaseModel):
135
+ files: int
136
+ folders: int
137
+
138
+
139
+ class FileSystemItemAggregatedCount(BaseModel):
140
+ items: Dict[str, FileSystemItemCount]
@@ -0,0 +1,45 @@
1
+ from typing import Any, Dict, List
2
+
3
+ from pydantic import BaseModel, ConfigDict, Field
4
+
5
+ from vector_bridge.schema.ai_knowledge import (BaseAIKnowledge,
6
+ BaseAIKnowledgeChunk)
7
+ from vector_bridge.schema.helpers.enums import SortOrder
8
+
9
+
10
+ class AIKnowledgeCreate(BaseModel):
11
+ content: str
12
+ other: Dict[str, Any]
13
+
14
+
15
+ class AIKnowledgeChunk(BaseAIKnowledgeChunk):
16
+ pass
17
+
18
+
19
+ class AIKnowledge(BaseAIKnowledge):
20
+ model_config = ConfigDict(from_attributes=True)
21
+
22
+ item_id: str
23
+ chunks: List[AIKnowledgeChunk | BaseAIKnowledgeChunk] = Field(default_factory=list)
24
+ other: Dict[str, Any]
25
+
26
+
27
+ class AIKnowledgeContentFilters(BaseModel):
28
+ item_id: str = Field(default=None)
29
+ limit: int = Field(default=100)
30
+ offset: int = Field(default=0)
31
+ sort_by: str = Field(default="timestamp")
32
+ sort_order: SortOrder = Field(default=SortOrder.DESCENDING)
33
+
34
+ class Config:
35
+ extra = "allow"
36
+
37
+ def to_non_empty_dict(self):
38
+ _dict = self.model_dump()
39
+ return {k: v for k, v in _dict.items() if v is not None and v != ""}
40
+
41
+ def to_serializible_non_empty_dict(self):
42
+ _dict = self.model_dump()
43
+ if self.sort_order:
44
+ _dict["sort_order"] = self.sort_order.value
45
+ return {k: v for k, v in _dict.items() if v is not None and v != ""}
@@ -0,0 +1,32 @@
1
+ from datetime import datetime
2
+ from typing import Optional
3
+
4
+ from dateutil.parser import isoparse
5
+ from pydantic import BaseModel, Field
6
+
7
+
8
+ class APIKey(BaseModel):
9
+ hash_key: Optional[str] = Field(default=None)
10
+ organization_id: str
11
+ api_key: str
12
+ key_name: str
13
+ integration_name: str
14
+ user_id: str = Field(default="")
15
+ expire_timestamp: str
16
+ monthly_request_limit: int
17
+ created_by: str
18
+ created_at: str
19
+
20
+ def is_expired(self) -> bool:
21
+ """Check if the API key is expired based on the expire_timestamp."""
22
+ current_time = datetime.utcnow()
23
+ expiration_time = isoparse(self.expire_timestamp)
24
+ return current_time >= expiration_time
25
+
26
+
27
+ class APIKeyCreate(BaseModel):
28
+ key_name: str
29
+ integration_name: str
30
+ user_id: str = Field(default="")
31
+ expire_days: int
32
+ monthly_request_limit: int
@@ -0,0 +1,74 @@
1
+ import json
2
+ from datetime import datetime
3
+ from typing import List, Optional
4
+
5
+ from pydantic import BaseModel, ConfigDict, Field, model_validator
6
+
7
+ from vector_bridge.schema.helpers.enums import MessageStorageMode
8
+ from vector_bridge.schema.instruction import DEFAULT_AGENT
9
+
10
+
11
+ class ChatBase(BaseModel):
12
+ model_config = ConfigDict(from_attributes=True)
13
+
14
+ title: Optional[str] = Field(default="")
15
+ storage: MessageStorageMode
16
+ agent: str = Field(default=DEFAULT_AGENT)
17
+ core_knowledge: dict = Field(default_factory=dict)
18
+
19
+
20
+ class ChatCreate(ChatBase):
21
+ model_config = ConfigDict(from_attributes=True)
22
+
23
+ integration_id: str
24
+
25
+
26
+ class ChatInDB(ChatBase):
27
+ model_config = ConfigDict(from_attributes=True)
28
+
29
+ chat_id: str
30
+ integration_id: str
31
+ chat_created_by: str
32
+ timestamp: datetime
33
+ latest_message_timestamp: datetime
34
+ deleted: bool = False
35
+
36
+ @model_validator(mode="before")
37
+ def check_vector_schema(cls, values):
38
+ values["chat_id"] = str(values["chat_id"])
39
+ values["integration_id"] = str(values["integration_id"])
40
+ if "core_knowledge" in values and isinstance(values["core_knowledge"], str):
41
+ values["core_knowledge"] = json.loads(values["core_knowledge"])
42
+ return values
43
+
44
+
45
+ class Chat(ChatBase):
46
+ model_config = ConfigDict(from_attributes=True)
47
+
48
+ integration_id: str
49
+ timestamp: datetime
50
+ chat_created_by: str
51
+ latest_message_timestamp: datetime
52
+
53
+ @model_validator(mode="before")
54
+ def check_vector_schema(cls, values):
55
+ if isinstance(values, (Chat, ChatInDB)):
56
+ return values
57
+
58
+ values["integration_id"] = str(values["integration_id"])
59
+ if "core_knowledge" in values and isinstance(values["core_knowledge"], str):
60
+ values["core_knowledge"] = json.loads(values["core_knowledge"])
61
+ return values
62
+
63
+
64
+ class ChatsList(BaseModel):
65
+ model_config = ConfigDict(from_attributes=True)
66
+
67
+ chats: List[Chat]
68
+ limit: int
69
+ offset: int = Field(default=0)
70
+ has_more: bool = Field(default=False)
71
+
72
+
73
+ class ChatFilter(BaseModel):
74
+ model_config = ConfigDict(from_attributes=True)
@@ -0,0 +1,13 @@
1
+ class HTTPException(Exception):
2
+ """
3
+ Custom exception for handling HTTP errors.
4
+
5
+ Attributes:
6
+ status_code (int): HTTP status code of the error.
7
+ detail (str): Detailed error message.
8
+ """
9
+
10
+ def __init__(self, status_code: int, detail: str):
11
+ super().__init__(f"HTTP {status_code}: {detail}")
12
+ self.status_code = status_code
13
+ self.detail = detail
@@ -0,0 +1,87 @@
1
+ from enum import Enum
2
+ from typing import Dict, List, Optional
3
+
4
+ from pydantic import BaseModel, Field
5
+
6
+ from vector_bridge.schema.helpers.enums import AIProviders, GPTActions
7
+
8
+
9
+ class FunctionsSorting(str, Enum):
10
+ created_at = "created_at"
11
+ updated_at = "updated_at"
12
+
13
+
14
+ class FunctionPropertyStorageStructure(BaseModel):
15
+ name: str
16
+ description: str
17
+ type: str = Field(default="string")
18
+ items: Dict[str, str] = Field(default_factory=dict)
19
+ enum: List[str] = []
20
+ required: bool = Field(default=False)
21
+
22
+
23
+ class FunctionParametersStorageStructure(BaseModel):
24
+ properties: List[FunctionPropertyStorageStructure]
25
+
26
+ def to_dynamodb_raw(self):
27
+ return {
28
+ "properties": {"L": [{"M": _property.to_dynamodb_raw()} for _property in self.properties]},
29
+ }
30
+
31
+
32
+ class Overrides(BaseModel):
33
+ ai_provider: Optional[AIProviders] = Field(default=None)
34
+ model: str = Field(default="")
35
+ system_prompt: str = Field(default="")
36
+ message_prompt: str = Field(default="")
37
+ knowledge_prompt: str = Field(default="")
38
+ max_tokens: str = Field(default="")
39
+ frequency_penalty: str = Field(default="")
40
+ presence_penalty: str = Field(default="")
41
+ temperature: str = Field(default="")
42
+
43
+
44
+ class Function(BaseModel):
45
+ function_id: str
46
+ function_name: str
47
+ integration_id: str
48
+ description: str
49
+ function_action: GPTActions
50
+ code: str = Field(default="")
51
+ vector_schema: str = Field(default="")
52
+ accessible_by_ai: bool = Field(default=True)
53
+ function_parameters: FunctionParametersStorageStructure
54
+ overrides: Overrides = Field(default=Overrides())
55
+ system_required: bool = Field(default=False)
56
+ created_at: str = Field(default="")
57
+ created_by: str = Field(default="")
58
+ updated_at: str = Field(default="")
59
+ updated_by: str = Field(default="")
60
+
61
+
62
+ class FunctionCreate(BaseModel):
63
+ function_name: str
64
+ description: str
65
+ function_action: GPTActions
66
+ code: str = Field(default="")
67
+ vector_schema: str = Field(default="")
68
+ accessible_by_ai: bool = Field(default=True)
69
+ function_parameters: FunctionParametersStorageStructure
70
+ overrides: Overrides = Field(default=Overrides())
71
+
72
+
73
+ class FunctionUpdate(BaseModel):
74
+ description: str
75
+ function_action: GPTActions
76
+ code: str = Field(default="")
77
+ vector_schema: str = Field(default="")
78
+ accessible_by_ai: bool = Field(default=True)
79
+ function_parameters: FunctionParametersStorageStructure
80
+ overrides: Overrides = Field(default=Overrides())
81
+
82
+
83
+ class PaginatedFunctions(BaseModel):
84
+ functions: List[Function] = Field(default_factory=list)
85
+ limit: int
86
+ last_evaluated_key: Optional[str] = None
87
+ has_more: bool = False
File without changes