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
6 changes: 5 additions & 1 deletion business_objects/embedding.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,9 +321,13 @@ def __build_payload_selector(
data_type != enums.DataTypes.TEXT.value
and data_type != enums.DataTypes.LLM_RESPONSE.value
and data_type != enums.DataTypes.PERMISSION.value
and data_type != enums.DataTypes.TEXT_LIST.value
):
payload_selector += f"'{attr}', (r.\"data\"->>'{attr}')::{data_type}"
elif data_type == enums.DataTypes.PERMISSION.value:
elif (
data_type == enums.DataTypes.PERMISSION.value
or data_type == enums.DataTypes.TEXT_LIST.value
):
payload_selector += f"'{attr}', r.\"data\"->'{attr}'"
else:
payload_selector += f"'{attr}', r.\"data\"->>'{attr}'"
Expand Down
15 changes: 14 additions & 1 deletion business_objects/record.py
Original file line number Diff line number Diff line change
Expand Up @@ -943,7 +943,7 @@ def get_first_no_text_column(project_id: str, record_id: str) -> str:
(
SELECT a.name
FROM attribute a
WHERE data_type NOT IN('{enums.DataTypes.TEXT.value}' , '{enums.DataTypes.CATEGORY.value}', '{enums.DataTypes.LLM_RESPONSE.value}')
WHERE data_type NOT IN('{enums.DataTypes.TEXT.value}', '{enums.DataTypes.CATEGORY.value}', '{enums.DataTypes.LLM_RESPONSE.value}', '{enums.DataTypes.TEXT_LIST.value}')
AND a.state IN ('{enums.AttributeState.AUTOMATICALLY_CREATED.value}','{enums.AttributeState.UPLOADED.value}','{enums.AttributeState.USABLE.value}')
AND a.project_id = '{project_id}'
ORDER BY a.relative_position
Expand All @@ -968,3 +968,16 @@ def get_record_ids_by_running_ids(project_id: str, running_ids: List[int]) -> Li
.all()
)
]


def get_records_by_running_ids(project_id: str, running_ids: List[int]) -> List[str]:
return (
session.query(Record)
.filter(
Record.project_id == project_id,
Record.data[attribute.get_running_id_name(project_id)]
.as_integer()
.in_(running_ids),
)
.all()
)
49 changes: 49 additions & 0 deletions cognition_objects/integration_sharepoint_property_sync.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
from typing import List, Optional, Dict, Any
from sqlalchemy.orm.attributes import flag_modified
from ..models import IntegrationSharepointPropertySync
from ..enums import SharepointPropertySyncState
from ..business_objects import general
from ..session import session


def get_by_integration_id(
integration_id: str,
) -> IntegrationSharepointPropertySync:
return (
session.query(IntegrationSharepointPropertySync)
.filter(IntegrationSharepointPropertySync.integration_id == integration_id)
.first()
)


def create(
integration_id: str,
config: Optional[Dict[str, Any]] = None,
logs: Optional[List[Dict[str, Any]]] = None,
with_commit: bool = True,
) -> IntegrationSharepointPropertySync:
integration_sync = IntegrationSharepointPropertySync(
integration_id=integration_id,
config=config or {},
logs=logs or [],
)
session.add(integration_sync)
general.flush_or_commit(with_commit)
return integration_sync


def update(
integration_id: str,
config: Optional[Dict[str, Any]] = None,
logs: Optional[List[Dict[str, Any]]] = None,
with_commit: bool = True,
) -> IntegrationSharepointPropertySync:
integration_sync = get_by_integration_id(integration_id)
if config is not None:
integration_sync.config = config
flag_modified(integration_sync, "config")
if logs is not None:
integration_sync.logs = logs
flag_modified(integration_sync, "logs")
general.flush_or_commit(with_commit)
return integration_sync
9 changes: 9 additions & 0 deletions enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class DataTypes(Enum):
LLM_RESPONSE = "LLM_RESPONSE"
EMBEDDING_LIST = "EMBEDDING_LIST" # only for embeddings & default hidden
PERMISSION = "PERMISSION" # used for access control
TEXT_LIST = "TEXT_LIST"
UNKNOWN = "UNKNOWN"


Expand Down Expand Up @@ -168,6 +169,7 @@ class Tablenames(Enum):
INTEGRATION_PDF = "pdf"
INTEGRATION_SHAREPOINT = "sharepoint"
STEP_TEMPLATES = "step_templates" # templates for strategy steps
INTEGRATION_SHAREPOINT_PROPERTY_SYNC = "sharepoint_property_sync"
CONVERSATION_TAG = "conversation_tag" # config of tags used in conversations
CONVERSATION_TAG_ASSOCIATION = (
"conversation_tag_association" # association between conversation and tags
Expand Down Expand Up @@ -946,3 +948,10 @@ def from_string(value: str):
raise KeyError(
f"Could not parse CognitionIntegrationType from string '{changed_value}'"
)


class SharepointPropertySyncState(Enum):
CREATED = "CREATED"
RUNNING = "RUNNING"
COMPLETED = "COMPLETED"
FAILED = "FAILED"
2 changes: 2 additions & 0 deletions integration_objects/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ def get_existing_integration_records(
integration_id: str,
by: str = "source",
) -> Dict[str, object]:
# TODO(extension): make return type Dict[str, List[object]]
# once an object_id can reference multiple different integration records
return {
getattr(record, by, record.source): record
for record in get_all_by_integration_id(IntegrationModel, integration_id)
Expand Down
21 changes: 21 additions & 0 deletions models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2390,6 +2390,27 @@ class IntegrationSharepoint(Base):
file_properties = Column(JSON)


class IntegrationSharepointPropertySync(Base):
__tablename__ = Tablenames.INTEGRATION_SHAREPOINT_PROPERTY_SYNC.value
__table_args__ = (UniqueConstraint("integration_id"), {"schema": "integration"})
id = Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
created_by = Column(
UUID(as_uuid=True),
ForeignKey(f"{Tablenames.USER.value}.id", ondelete="SET NULL"),
index=True,
)
created_at = Column(DateTime, default=sql.func.now())
updated_at = Column(DateTime, onupdate=sql.func.now())
integration_id = Column(
UUID(as_uuid=True),
ForeignKey(f"cognition.{Tablenames.INTEGRATION.value}.id", ondelete="CASCADE"),
index=True,
)
config = Column(JSON) # JSON object containing the rules for property sync
logs = Column(ARRAY(String))
state = Column(String)


class CognitionConversationTag(Base):
__tablename__ = Tablenames.CONVERSATION_TAG.value
__table_args__ = {"schema": "cognition"}
Expand Down