Spaces:
Runtime error
Runtime error
| from enum import Enum as PyEnum | |
| from src.utils import ProposalAIAnalysisClient | |
| from src.models import QueryType, CreateOrUpdateType, Category | |
| class ProposalAIAnalysisService: | |
| def __init__(self): | |
| self.proposal_ai_analysis_client = ProposalAIAnalysisClient | |
| async def __aenter__(self): | |
| return self | |
| async def __aexit__(self, exc_type, exc_value, traceback): | |
| pass | |
| async def get_all_data( | |
| self, | |
| query_type: QueryType = QueryType.ALL, | |
| id: str = None, | |
| proposal_id: str = None, | |
| category: Category = None, | |
| ): | |
| async with self.proposal_ai_analysis_client() as client: | |
| if query_type == QueryType.ALL: | |
| return await client.get_complete_analysis(proposal_id=proposal_id) | |
| else: | |
| return await client.get_all_data( | |
| query_type=query_type, | |
| id=id, | |
| proposal_id=proposal_id, | |
| category=category, | |
| ) | |
| async def create_data( | |
| self, | |
| query_type: QueryType = QueryType.ALL, | |
| create_or_update_type: CreateOrUpdateType = CreateOrUpdateType.ALL, | |
| data: dict = None, | |
| ): | |
| async with self.proposal_ai_analysis_client() as client: | |
| if query_type == QueryType.ALL: | |
| return await client.create_complete_analysis(data=data) | |
| else: | |
| return await client.create_data( | |
| query_type=query_type, | |
| create_or_update_type=create_or_update_type, | |
| data=data, | |
| ) | |
| async def update_data( | |
| self, | |
| query_type: QueryType = QueryType.ALL, | |
| create_or_update_type: CreateOrUpdateType = CreateOrUpdateType.ALL, | |
| data: dict = None, | |
| ): | |
| async with self.proposal_ai_analysis_client() as client: | |
| if query_type == QueryType.ALL: | |
| return await client.update_complete_analysis(data=data) | |
| else: | |
| return await client.update_data( | |
| query_type=query_type, | |
| create_or_update_type=create_or_update_type, | |
| data=data, | |
| ) | |
| async def delete_data( | |
| self, | |
| query_type: QueryType = QueryType.ALL, | |
| id: str = None, | |
| proposal_id: str = None, | |
| category: Category = None, | |
| ): | |
| async with self.proposal_ai_analysis_client() as client: | |
| if query_type == QueryType.ALL: | |
| return await client.delete_complete_analysis(proposal_id=proposal_id) | |
| else: | |
| return await client.delete_data( | |
| query_type=query_type, | |
| id=id, | |
| proposal_id=proposal_id, | |
| category=category, | |
| ) | |