Spaces:
Sleeping
Sleeping
File size: 2,841 Bytes
01d5a5d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
from dataclasses import dataclass
from enum import Enum
from typing import Any, Optional
@dataclass
class FileInfo:
"""File-related information"""
data_type: str
filename: str
content: str
file_content: Optional[Any]
class DocumentType(str, Enum):
DOCUMENT = "DOCUMENT"
TEXT = "TEXT"
@classmethod
def from_mime_type(cls, mime_type: str) -> "DocumentType":
"""Converts a MIME type to DocumentType.
Args:
mime_type: String representing the MIME type.
Returns:
The appropriate DocumentType based on the given MIME type.
"""
if mime_type == "text":
return cls.TEXT
elif mime_type == "pdf":
return cls.DOCUMENT
elif mime_type == "md":
return cls.DOCUMENT
else:
return cls.DOCUMENT
@dataclass
class BioInfo:
"""User biographical information"""
global_bio: str
status_bio: str
about_me: str
@dataclass
class InsighterInput:
"""Raw input parameters for the Insighter"""
file_info: FileInfo
bio_info: BioInfo
@classmethod
def from_dict(cls, inputs: dict) -> "InsighterInput":
"""Creates an InsighterInput instance from a dictionary.
Args:
inputs: Dictionary containing the input parameters.
Returns:
An InsighterInput object populated with values from the dictionary.
"""
return cls(
file_info=FileInfo(
data_type=inputs.get("dataType", "DOCUMENT"),
filename=inputs.get("filename", ""),
content=inputs.get("content", "").strip(),
file_content=inputs.get("fileContent", ""),
),
bio_info=BioInfo(
global_bio=inputs.get("globalBio", ""),
status_bio=inputs.get("statusBio", ""),
about_me=inputs.get("aboutMe", ""),
),
)
@dataclass
class SummarizerInput:
"""Raw input parameters for the Summarizer"""
file_info: FileInfo
insight: str
@classmethod
def from_dict(cls, inputs: dict) -> "SummarizerInput":
"""Creates a SummarizerInput instance from a dictionary.
Args:
inputs: Dictionary containing the input parameters.
Returns:
A SummarizerInput object populated with values from the dictionary.
"""
return cls(
file_info=FileInfo(
data_type=inputs.get("dataType", "DOCUMENT"),
filename=inputs.get("filename", ""),
content=inputs.get("content", "").strip(),
file_content=inputs.get("fileContent", ""),
),
insight=inputs.get("insight", ""),
)
|