rettxmutation 0.2.0__tar.gz → 0.2.2__tar.gz
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.
- {rettxmutation-0.2.0/src/rettxmutation.egg-info → rettxmutation-0.2.2}/PKG-INFO +2 -8
- {rettxmutation-0.2.0 → rettxmutation-0.2.2}/pyproject.toml +2 -17
- {rettxmutation-0.2.0 → rettxmutation-0.2.2}/src/rettxmutation/__init__.py +1 -5
- {rettxmutation-0.2.0 → rettxmutation-0.2.2}/src/rettxmutation/repositories/__init__.py +0 -8
- {rettxmutation-0.2.0 → rettxmutation-0.2.2}/src/rettxmutation/repositories/interfaces.py +1 -41
- {rettxmutation-0.2.0 → rettxmutation-0.2.2}/src/rettxmutation/services/__init__.py +0 -4
- {rettxmutation-0.2.0/src/rettxmutation/openai_agent → rettxmutation-0.2.2/src/rettxmutation/services}/embedding_client.py +54 -32
- {rettxmutation-0.2.0 → rettxmutation-0.2.2}/src/rettxmutation/services/embedding_service.py +1 -1
- {rettxmutation-0.2.0 → rettxmutation-0.2.2}/src/rettxmutation/services/services_factory.py +9 -172
- {rettxmutation-0.2.0 → rettxmutation-0.2.2/src/rettxmutation.egg-info}/PKG-INFO +2 -8
- rettxmutation-0.2.2/src/rettxmutation.egg-info/SOURCES.txt +40 -0
- rettxmutation-0.2.2/src/rettxmutation.egg-info/requires.txt +10 -0
- rettxmutation-0.2.0/src/rettxmutation/models/context.py +0 -12
- rettxmutation-0.2.0/src/rettxmutation/models/document.py +0 -57
- rettxmutation-0.2.0/src/rettxmutation/openai_agent/__init__.py +0 -73
- rettxmutation-0.2.0/src/rettxmutation/openai_agent/base_agent.py +0 -184
- rettxmutation-0.2.0/src/rettxmutation/openai_agent/exceptions.py +0 -37
- rettxmutation-0.2.0/src/rettxmutation/openai_agent/hardcoded_prompts.py +0 -90
- rettxmutation-0.2.0/src/rettxmutation/openai_agent/hardcoded_yaml_configs.py +0 -154
- rettxmutation-0.2.0/src/rettxmutation/openai_agent/mutation_extraction_agent.py +0 -151
- rettxmutation-0.2.0/src/rettxmutation/openai_agent/prompts/__init__.py +0 -1
- rettxmutation-0.2.0/src/rettxmutation/openai_agent/prompts/extraction/__init__.py +0 -1
- rettxmutation-0.2.0/src/rettxmutation/openai_agent/prompts/extraction/extract_mutations.skprompt.txt +0 -30
- rettxmutation-0.2.0/src/rettxmutation/openai_agent/prompts/extraction/extract_mutations.yaml +0 -10
- rettxmutation-0.2.0/src/rettxmutation/openai_agent/prompts/shared/__init__.py +0 -1
- rettxmutation-0.2.0/src/rettxmutation/openai_agent/prompts/shared/latest_transcripts.json +0 -34
- rettxmutation-0.2.0/src/rettxmutation/openai_agent/prompts/summarization/__init__.py +0 -1
- rettxmutation-0.2.0/src/rettxmutation/openai_agent/prompts/summarization/correct_summary_mistakes.skprompt.txt +0 -16
- rettxmutation-0.2.0/src/rettxmutation/openai_agent/prompts/summarization/correct_summary_mistakes.yaml +0 -11
- rettxmutation-0.2.0/src/rettxmutation/openai_agent/prompts/summarization/summarize_report.skprompt.txt +0 -15
- rettxmutation-0.2.0/src/rettxmutation/openai_agent/prompts/summarization/summarize_report.yaml +0 -9
- rettxmutation-0.2.0/src/rettxmutation/openai_agent/prompts/validation/__init__.py +0 -1
- rettxmutation-0.2.0/src/rettxmutation/openai_agent/prompts/validation/validate_document.skprompt.txt +0 -4
- rettxmutation-0.2.0/src/rettxmutation/openai_agent/prompts/validation/validate_document.yaml +0 -10
- rettxmutation-0.2.0/src/rettxmutation/openai_agent/prompts/validation/validate_mutations.skprompt.txt +0 -0
- rettxmutation-0.2.0/src/rettxmutation/openai_agent/prompts/validation/validate_mutations.yaml +0 -9
- rettxmutation-0.2.0/src/rettxmutation/openai_agent/summarization_agent.py +0 -148
- rettxmutation-0.2.0/src/rettxmutation/openai_agent/utils.py +0 -115
- rettxmutation-0.2.0/src/rettxmutation/openai_agent/validation_agent.py +0 -131
- rettxmutation-0.2.0/src/rettxmutation/repositories/document_analysis_repository.py +0 -102
- rettxmutation-0.2.0/src/rettxmutation/repositories/openai_repository.py +0 -43
- rettxmutation-0.2.0/src/rettxmutation/services/exceptions.py +0 -30
- rettxmutation-0.2.0/src/rettxmutation/services/mutation_validator.py +0 -222
- rettxmutation-0.2.0/src/rettxmutation/services/ocr_service.py +0 -288
- rettxmutation-0.2.0/src/rettxmutation.egg-info/SOURCES.txt +0 -76
- rettxmutation-0.2.0/src/rettxmutation.egg-info/requires.txt +0 -16
- rettxmutation-0.2.0/tests/test_models_document.py +0 -89
- rettxmutation-0.2.0/tests/test_ocr.py +0 -324
- rettxmutation-0.2.0/tests/test_openai_agents.py +0 -129
- rettxmutation-0.2.0/tests/test_validate_mutations.py +0 -439
- {rettxmutation-0.2.0 → rettxmutation-0.2.2}/LICENSE +0 -0
- {rettxmutation-0.2.0 → rettxmutation-0.2.2}/README.md +0 -0
- {rettxmutation-0.2.0 → rettxmutation-0.2.2}/setup.cfg +0 -0
- {rettxmutation-0.2.0 → rettxmutation-0.2.2}/src/rettxmutation/config.py +0 -0
- {rettxmutation-0.2.0 → rettxmutation-0.2.2}/src/rettxmutation/models/__init__.py +0 -0
- {rettxmutation-0.2.0 → rettxmutation-0.2.2}/src/rettxmutation/models/gene_assembly.py +0 -0
- {rettxmutation-0.2.0 → rettxmutation-0.2.2}/src/rettxmutation/models/gene_models.py +0 -0
- {rettxmutation-0.2.0 → rettxmutation-0.2.2}/src/rettxmutation/models/gene_registry.py +0 -0
- {rettxmutation-0.2.0 → rettxmutation-0.2.2}/src/rettxmutation/models/keyword_collection.py +0 -0
- {rettxmutation-0.2.0 → rettxmutation-0.2.2}/src/rettxmutation/models/mutation_model.py +0 -0
- {rettxmutation-0.2.0 → rettxmutation-0.2.2}/src/rettxmutation/models/search_models.py +0 -0
- {rettxmutation-0.2.0 → rettxmutation-0.2.2}/src/rettxmutation/repositories/ai_search_repository.py +0 -0
- {rettxmutation-0.2.0 → rettxmutation-0.2.2}/src/rettxmutation/repositories/text_analytics_repository.py +0 -0
- {rettxmutation-0.2.0 → rettxmutation-0.2.2}/src/rettxmutation/repositories/variant_validator_repository.py +0 -0
- {rettxmutation-0.2.0 → rettxmutation-0.2.2}/src/rettxmutation/services/ai_search.py +0 -0
- {rettxmutation-0.2.0 → rettxmutation-0.2.2}/src/rettxmutation/services/keyword_detector_service.py +0 -0
- {rettxmutation-0.2.0 → rettxmutation-0.2.2}/src/rettxmutation/services/mutation_tokenizator.py +0 -0
- {rettxmutation-0.2.0 → rettxmutation-0.2.2}/src/rettxmutation/services/variant_validator_mapping_service.py +0 -0
- {rettxmutation-0.2.0 → rettxmutation-0.2.2}/src/rettxmutation/services/variant_validator_service.py +0 -0
- {rettxmutation-0.2.0 → rettxmutation-0.2.2}/src/rettxmutation/utils/__init__.py +0 -0
- {rettxmutation-0.2.0 → rettxmutation-0.2.2}/src/rettxmutation/utils/hgvs_descriptor.py +0 -0
- {rettxmutation-0.2.0 → rettxmutation-0.2.2}/src/rettxmutation/utils/mutation_converter.py +0 -0
- {rettxmutation-0.2.0 → rettxmutation-0.2.2}/src/rettxmutation/utils/text_util.py +0 -0
- {rettxmutation-0.2.0 → rettxmutation-0.2.2}/src/rettxmutation.egg-info/dependency_links.txt +0 -0
- {rettxmutation-0.2.0 → rettxmutation-0.2.2}/src/rettxmutation.egg-info/top_level.txt +0 -0
- {rettxmutation-0.2.0 → rettxmutation-0.2.2}/tests/test_gene_model.py +0 -0
- {rettxmutation-0.2.0 → rettxmutation-0.2.2}/tests/test_keyword_collection.py +0 -0
- {rettxmutation-0.2.0 → rettxmutation-0.2.2}/tests/test_keyword_detector.py +0 -0
- {rettxmutation-0.2.0 → rettxmutation-0.2.2}/tests/test_semantic_search.py +0 -0
- {rettxmutation-0.2.0 → rettxmutation-0.2.2}/tests/test_variant_validator.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: rettxmutation
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.2
|
|
4
4
|
Summary: Extract Rett Syndrome mutations from genetic diagnosis report
|
|
5
5
|
Author-email: Pedro Rocha <procha@rettsyndrome.eu>
|
|
6
6
|
License: MIT License
|
|
@@ -13,21 +13,15 @@ Requires-Python: >=3.8
|
|
|
13
13
|
Description-Content-Type: text/markdown
|
|
14
14
|
License-File: LICENSE
|
|
15
15
|
Requires-Dist: python-dotenv
|
|
16
|
-
Requires-Dist: azure-ai-formrecognizer
|
|
17
16
|
Requires-Dist: azure-core
|
|
18
17
|
Requires-Dist: azure-ai-textanalytics
|
|
19
|
-
Requires-Dist: azure.ai.documentintelligence
|
|
20
|
-
Requires-Dist: ftfy
|
|
21
18
|
Requires-Dist: mutalyzer_hgvs_parser
|
|
22
19
|
Requires-Dist: pydantic
|
|
23
|
-
Requires-Dist: pydantic_settings
|
|
24
20
|
Requires-Dist: openai
|
|
25
|
-
Requires-Dist: opencv-python-headless
|
|
26
21
|
Requires-Dist: backoff
|
|
27
22
|
Requires-Dist: jmespath
|
|
28
23
|
Requires-Dist: azure-search-documents
|
|
29
|
-
Requires-Dist:
|
|
30
|
-
Requires-Dist: importlib.resources
|
|
24
|
+
Requires-Dist: numpy
|
|
31
25
|
Dynamic: license-file
|
|
32
26
|
|
|
33
27
|
# RettX Mutation Analysis Library
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "rettxmutation"
|
|
3
|
-
version = "0.2.
|
|
3
|
+
version = "0.2.2"
|
|
4
4
|
authors = [
|
|
5
5
|
{ name="Pedro Rocha", email="procha@rettsyndrome.eu" },
|
|
6
6
|
]
|
|
@@ -15,21 +15,15 @@ classifiers = [
|
|
|
15
15
|
]
|
|
16
16
|
dependencies = [
|
|
17
17
|
"python-dotenv",
|
|
18
|
-
"azure-ai-formrecognizer",
|
|
19
18
|
"azure-core",
|
|
20
19
|
"azure-ai-textanalytics",
|
|
21
|
-
"azure.ai.documentintelligence",
|
|
22
|
-
"ftfy",
|
|
23
20
|
"mutalyzer_hgvs_parser",
|
|
24
21
|
"pydantic",
|
|
25
|
-
"pydantic_settings",
|
|
26
22
|
"openai",
|
|
27
|
-
"opencv-python-headless",
|
|
28
23
|
"backoff",
|
|
29
24
|
"jmespath",
|
|
30
25
|
"azure-search-documents",
|
|
31
|
-
"
|
|
32
|
-
"importlib.resources"
|
|
26
|
+
"numpy"
|
|
33
27
|
]
|
|
34
28
|
|
|
35
29
|
[project.urls]
|
|
@@ -42,16 +36,7 @@ package-dir = {"" = "src"}
|
|
|
42
36
|
packages = [
|
|
43
37
|
"rettxmutation",
|
|
44
38
|
"rettxmutation.models",
|
|
45
|
-
"rettxmutation.openai_agent",
|
|
46
39
|
"rettxmutation.repositories",
|
|
47
40
|
"rettxmutation.services",
|
|
48
41
|
"rettxmutation.utils"
|
|
49
|
-
]
|
|
50
|
-
|
|
51
|
-
[tool.setuptools.package-data]
|
|
52
|
-
"rettxmutation.openai_agent" = [
|
|
53
|
-
"prompts/**/*.skprompt.txt",
|
|
54
|
-
"prompts/**/*.yaml",
|
|
55
|
-
"prompts/**/*.json",
|
|
56
|
-
"prompts/**/__init__.py"
|
|
57
42
|
]
|
|
@@ -27,13 +27,11 @@ from .services import (
|
|
|
27
27
|
create_services,
|
|
28
28
|
EmbeddingService,
|
|
29
29
|
VariantValidatorService,
|
|
30
|
-
MutationValidator,
|
|
31
30
|
MutationTokenizator,
|
|
32
31
|
AISearchService,
|
|
33
|
-
OcrService
|
|
34
32
|
)
|
|
35
33
|
|
|
36
|
-
__version__ = "0.2.
|
|
34
|
+
__version__ = "0.2.2"
|
|
37
35
|
|
|
38
36
|
__all__ = [
|
|
39
37
|
# Core configuration
|
|
@@ -46,10 +44,8 @@ __all__ = [
|
|
|
46
44
|
# Individual services
|
|
47
45
|
"EmbeddingService",
|
|
48
46
|
"VariantValidatorService",
|
|
49
|
-
"MutationValidator",
|
|
50
47
|
"MutationTokenizator",
|
|
51
48
|
"AISearchService",
|
|
52
|
-
"OcrService",
|
|
53
49
|
|
|
54
50
|
# Version
|
|
55
51
|
"__version__"
|
|
@@ -4,15 +4,11 @@
|
|
|
4
4
|
from .interfaces import (
|
|
5
5
|
AISearchRepositoryInterface,
|
|
6
6
|
TextAnalyticsRepositoryInterface,
|
|
7
|
-
DocumentAnalysisRepositoryInterface,
|
|
8
|
-
OpenAIRepositoryInterface,
|
|
9
7
|
VariantValidatorRepositoryInterface,
|
|
10
8
|
)
|
|
11
9
|
|
|
12
10
|
# Repository Implementations
|
|
13
|
-
from .document_analysis_repository import DocumentAnalysisRepository
|
|
14
11
|
from .text_analytics_repository import TextAnalyticsRepository
|
|
15
|
-
from .openai_repository import OpenAIRepository
|
|
16
12
|
from .ai_search_repository import AISearchRepository
|
|
17
13
|
from .variant_validator_repository import (
|
|
18
14
|
VariantValidatorRepository,
|
|
@@ -24,13 +20,9 @@ __all__ = [
|
|
|
24
20
|
# Interfaces
|
|
25
21
|
"AISearchRepositoryInterface",
|
|
26
22
|
"TextAnalyticsRepositoryInterface",
|
|
27
|
-
"DocumentAnalysisRepositoryInterface",
|
|
28
|
-
"OpenAIRepositoryInterface",
|
|
29
23
|
"VariantValidatorRepositoryInterface",
|
|
30
24
|
# Implementations
|
|
31
|
-
"DocumentAnalysisRepository",
|
|
32
25
|
"TextAnalyticsRepository",
|
|
33
|
-
"OpenAIRepository",
|
|
34
26
|
"AISearchRepository",
|
|
35
27
|
"VariantValidatorRepository",
|
|
36
28
|
"VariantValidatorError",
|
|
@@ -6,8 +6,7 @@ enabling better testability and flexibility in implementation.
|
|
|
6
6
|
"""
|
|
7
7
|
|
|
8
8
|
from abc import ABC, abstractmethod
|
|
9
|
-
from typing import Any, Dict, List,
|
|
10
|
-
from azure.ai.documentintelligence.models import AnalyzeResult, DocumentAnalysisFeature
|
|
9
|
+
from typing import Any, Dict, List, Optional
|
|
11
10
|
|
|
12
11
|
|
|
13
12
|
class AISearchRepositoryInterface(ABC):
|
|
@@ -38,45 +37,6 @@ class TextAnalyticsRepositoryInterface(ABC):
|
|
|
38
37
|
pass
|
|
39
38
|
|
|
40
39
|
|
|
41
|
-
class DocumentAnalysisRepositoryInterface(ABC):
|
|
42
|
-
"""Interface for Document Analysis repository operations."""
|
|
43
|
-
|
|
44
|
-
@abstractmethod
|
|
45
|
-
def analyze_document(
|
|
46
|
-
self,
|
|
47
|
-
file_stream: BinaryIO,
|
|
48
|
-
features: Optional[List[DocumentAnalysisFeature]] = None,
|
|
49
|
-
) -> AnalyzeResult:
|
|
50
|
-
"""
|
|
51
|
-
Analyze a document using Azure Document Analysis.
|
|
52
|
-
|
|
53
|
-
Args:
|
|
54
|
-
file_stream: Binary stream of the document
|
|
55
|
-
features: Optional list of analysis features to enable
|
|
56
|
-
|
|
57
|
-
Returns:
|
|
58
|
-
AnalyzeResult: The analysis result from Azure Document Analysis
|
|
59
|
-
|
|
60
|
-
Raises:
|
|
61
|
-
Exception: If document analysis fails
|
|
62
|
-
"""
|
|
63
|
-
pass
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
class OpenAIRepositoryInterface(ABC):
|
|
67
|
-
"""Interface for OpenAI repository operations."""
|
|
68
|
-
|
|
69
|
-
@abstractmethod
|
|
70
|
-
def create_embedding(self, deployment: str, text: str) -> Iterable[float]:
|
|
71
|
-
"""Create embedding for a single text."""
|
|
72
|
-
pass
|
|
73
|
-
|
|
74
|
-
@abstractmethod
|
|
75
|
-
def create_embeddings(self, deployment: str, texts: List[str]) -> List[List[float]]:
|
|
76
|
-
"""Create embeddings for multiple texts."""
|
|
77
|
-
pass
|
|
78
|
-
|
|
79
|
-
|
|
80
40
|
class VariantValidatorRepositoryInterface(ABC):
|
|
81
41
|
"""Interface for VariantValidator repository operations."""
|
|
82
42
|
|
|
@@ -1,19 +1,15 @@
|
|
|
1
|
-
from .mutation_validator import MutationValidator
|
|
2
1
|
from .variant_validator_service import VariantValidatorService
|
|
3
2
|
from .embedding_service import EmbeddingService
|
|
4
3
|
from .mutation_tokenizator import MutationTokenizator
|
|
5
4
|
from .ai_search import AISearchService
|
|
6
|
-
from .ocr_service import OcrService
|
|
7
5
|
from .keyword_detector_service import KeywordDetectorService
|
|
8
6
|
from .services_factory import RettxServices, create_services
|
|
9
7
|
|
|
10
8
|
__all__ = [
|
|
11
|
-
"MutationValidator",
|
|
12
9
|
"VariantValidatorService",
|
|
13
10
|
"EmbeddingService",
|
|
14
11
|
"MutationTokenizator",
|
|
15
12
|
"AISearchService",
|
|
16
|
-
"OcrService",
|
|
17
13
|
"KeywordDetectorService",
|
|
18
14
|
"RettxServices",
|
|
19
15
|
"create_services"
|
|
@@ -1,58 +1,79 @@
|
|
|
1
1
|
"""
|
|
2
|
-
Embedding Client
|
|
2
|
+
Standalone Embedding Client for Azure OpenAI.
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
Generates text embeddings using Azure OpenAI's embedding API
|
|
5
|
+
with retry logic for rate limiting.
|
|
5
6
|
"""
|
|
6
7
|
|
|
7
8
|
import logging
|
|
8
9
|
import backoff
|
|
9
10
|
from typing import List
|
|
10
|
-
from openai import RateLimitError
|
|
11
|
-
|
|
12
|
-
from .base_agent import BaseAgent
|
|
11
|
+
from openai import AzureOpenAI, RateLimitError
|
|
13
12
|
|
|
14
13
|
logger = logging.getLogger(__name__)
|
|
15
14
|
|
|
16
15
|
|
|
17
|
-
class EmbeddingClient
|
|
16
|
+
class EmbeddingClient:
|
|
18
17
|
"""Client for generating text embeddings using Azure OpenAI."""
|
|
19
|
-
|
|
20
|
-
def __init__(
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
18
|
+
|
|
19
|
+
def __init__(
|
|
20
|
+
self,
|
|
21
|
+
api_key: str,
|
|
22
|
+
api_version: str,
|
|
23
|
+
azure_endpoint: str,
|
|
24
|
+
model_name: str,
|
|
25
|
+
embedding_deployment: str,
|
|
26
|
+
):
|
|
27
|
+
"""
|
|
28
|
+
Initialize the embedding client with Azure OpenAI configuration.
|
|
29
|
+
|
|
30
|
+
Args:
|
|
31
|
+
api_key: Azure OpenAI API key
|
|
32
|
+
api_version: Azure OpenAI API version
|
|
33
|
+
azure_endpoint: Azure OpenAI endpoint URL
|
|
34
|
+
model_name: Chat model deployment name (accepted for API
|
|
35
|
+
compatibility but not used internally)
|
|
36
|
+
embedding_deployment: Embedding model deployment name
|
|
37
|
+
"""
|
|
38
|
+
self._embedding_deployment = embedding_deployment
|
|
39
|
+
self.openai_client = AzureOpenAI(
|
|
40
|
+
api_key=api_key,
|
|
41
|
+
api_version=api_version,
|
|
42
|
+
azure_endpoint=azure_endpoint,
|
|
43
|
+
)
|
|
44
|
+
logger.debug(
|
|
45
|
+
f"Embedding client initialized with deployment: {self._embedding_deployment}"
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
@backoff.on_exception(backoff.expo, RateLimitError, max_tries=5)
|
|
30
49
|
def create_embedding(self, text: str) -> List[float]:
|
|
31
50
|
"""
|
|
32
51
|
Generate embeddings for a single text using Azure OpenAI's embedding API.
|
|
33
|
-
|
|
52
|
+
|
|
34
53
|
Args:
|
|
35
54
|
text: The text to embed
|
|
36
|
-
|
|
55
|
+
|
|
37
56
|
Returns:
|
|
38
57
|
List[float]: A list of floats representing the embedding vector
|
|
39
58
|
"""
|
|
40
59
|
try:
|
|
41
60
|
logger.debug(f"Creating embedding for text of length: {len(text)}")
|
|
42
|
-
|
|
61
|
+
|
|
43
62
|
response = self.openai_client.embeddings.create(
|
|
44
63
|
model=self._embedding_deployment,
|
|
45
64
|
input=text,
|
|
46
|
-
encoding_format="float"
|
|
65
|
+
encoding_format="float",
|
|
47
66
|
)
|
|
48
67
|
|
|
49
68
|
# Extract the embedding vector from the response
|
|
50
69
|
embedding_vector = response.data[0].embedding
|
|
51
|
-
|
|
52
|
-
logger.debug(
|
|
53
|
-
|
|
70
|
+
|
|
71
|
+
logger.debug(
|
|
72
|
+
f"Created embedding vector of dimension: {len(embedding_vector)}"
|
|
73
|
+
)
|
|
74
|
+
|
|
54
75
|
return embedding_vector
|
|
55
|
-
|
|
76
|
+
|
|
56
77
|
except Exception as e:
|
|
57
78
|
logger.error(f"Error creating embedding: {str(e)}")
|
|
58
79
|
raise
|
|
@@ -60,28 +81,29 @@ class EmbeddingClient(BaseAgent):
|
|
|
60
81
|
def create_embeddings_batch(self, texts: List[str]) -> List[List[float]]:
|
|
61
82
|
"""
|
|
62
83
|
Generate embeddings for multiple texts in a single request.
|
|
63
|
-
|
|
84
|
+
|
|
64
85
|
Args:
|
|
65
86
|
texts: List of texts to embed
|
|
66
|
-
|
|
87
|
+
|
|
88
|
+
Returns:
|
|
67
89
|
List[List[float]]: List of embedding vectors
|
|
68
90
|
"""
|
|
69
91
|
try:
|
|
70
92
|
logger.debug(f"Creating embeddings for {len(texts)} texts")
|
|
71
|
-
|
|
93
|
+
|
|
72
94
|
response = self.openai_client.embeddings.create(
|
|
73
95
|
model=self._embedding_deployment,
|
|
74
96
|
input=texts,
|
|
75
|
-
encoding_format="float"
|
|
97
|
+
encoding_format="float",
|
|
76
98
|
)
|
|
77
99
|
|
|
78
100
|
# Extract embedding vectors from the response
|
|
79
101
|
embedding_vectors = [item.embedding for item in response.data]
|
|
80
|
-
|
|
102
|
+
|
|
81
103
|
logger.debug(f"Created {len(embedding_vectors)} embedding vectors")
|
|
82
|
-
|
|
104
|
+
|
|
83
105
|
return embedding_vectors
|
|
84
|
-
|
|
106
|
+
|
|
85
107
|
except Exception as e:
|
|
86
108
|
logger.error(f"Error creating batch embeddings: {str(e)}")
|
|
87
109
|
raise
|
|
@@ -3,7 +3,7 @@ import numpy as np
|
|
|
3
3
|
from typing import List, Dict, Any
|
|
4
4
|
from rettxmutation.models.mutation_model import Mutation
|
|
5
5
|
from rettxmutation.models.gene_models import GeneMutation
|
|
6
|
-
from rettxmutation.
|
|
6
|
+
from rettxmutation.services.embedding_client import EmbeddingClient
|
|
7
7
|
from rettxmutation.config import RettxConfig, validate_config_fields
|
|
8
8
|
|
|
9
9
|
logger = logging.getLogger(__name__)
|
|
@@ -12,14 +12,11 @@ import logging
|
|
|
12
12
|
from typing import Optional
|
|
13
13
|
from rettxmutation.config import RettxConfig
|
|
14
14
|
from rettxmutation.services.embedding_service import EmbeddingService
|
|
15
|
-
from rettxmutation.services.mutation_validator import MutationValidator
|
|
16
15
|
from rettxmutation.services.mutation_tokenizator import MutationTokenizator
|
|
17
16
|
from rettxmutation.services.ai_search import AISearchService
|
|
18
|
-
from rettxmutation.services.ocr_service import OcrService
|
|
19
17
|
from rettxmutation.services.keyword_detector_service import KeywordDetectorService
|
|
20
18
|
from rettxmutation.services.variant_validator_service import VariantValidatorService
|
|
21
|
-
from rettxmutation.repositories import
|
|
22
|
-
from rettxmutation.openai_agent import ValidationAgent, MutationExtractionAgent, SummarizationAgent
|
|
19
|
+
from rettxmutation.repositories import TextAnalyticsRepository
|
|
23
20
|
|
|
24
21
|
logger = logging.getLogger(__name__)
|
|
25
22
|
|
|
@@ -52,15 +49,9 @@ class RettxServices:
|
|
|
52
49
|
# Lazy-initialized services
|
|
53
50
|
self._embedding_service: Optional[EmbeddingService] = None
|
|
54
51
|
self._variant_validator_service: Optional[VariantValidatorService] = None
|
|
55
|
-
self._mutation_validator: Optional[MutationValidator] = None
|
|
56
52
|
self._mutation_tokenizator: Optional[MutationTokenizator] = None
|
|
57
|
-
self._ocr_service: Optional[OcrService] = None
|
|
58
53
|
self._keyword_detector_service: Optional[KeywordDetectorService] = None
|
|
59
|
-
self.
|
|
60
|
-
# Lazy-initialized agents
|
|
61
|
-
self._validation_agent: Optional[ValidationAgent] = None
|
|
62
|
-
self._extraction_agent: Optional[MutationExtractionAgent] = None
|
|
63
|
-
self._summarization_agent: Optional[SummarizationAgent] = None
|
|
54
|
+
self._ai_search_service: Optional[AISearchService] = None
|
|
64
55
|
|
|
65
56
|
logger.debug("RettxServices factory initialized with unified configuration")
|
|
66
57
|
|
|
@@ -134,32 +125,6 @@ class RettxServices:
|
|
|
134
125
|
self._variant_validator_service = VariantValidatorService(repository)
|
|
135
126
|
return self._variant_validator_service
|
|
136
127
|
|
|
137
|
-
@property
|
|
138
|
-
def mutation_validator(self) -> MutationValidator:
|
|
139
|
-
"""
|
|
140
|
-
Get or create the mutation validator service.
|
|
141
|
-
|
|
142
|
-
Returns:
|
|
143
|
-
MutationValidator: Service for validating raw mutations
|
|
144
|
-
"""
|
|
145
|
-
if self._mutation_validator is None:
|
|
146
|
-
logger.debug("Initializing MutationValidator")
|
|
147
|
-
self._mutation_validator = MutationValidator(
|
|
148
|
-
config=self._config,
|
|
149
|
-
variant_validator_service=self.variant_validator_service
|
|
150
|
-
)
|
|
151
|
-
return self._mutation_validator
|
|
152
|
-
|
|
153
|
-
@mutation_validator.setter
|
|
154
|
-
def mutation_validator(self, validator: MutationValidator):
|
|
155
|
-
"""Set the mutation validator (for testing purposes)."""
|
|
156
|
-
self._mutation_validator = validator
|
|
157
|
-
|
|
158
|
-
@mutation_validator.deleter
|
|
159
|
-
def mutation_validator(self):
|
|
160
|
-
"""Delete the mutation validator (for testing purposes)."""
|
|
161
|
-
self._mutation_validator = None
|
|
162
|
-
|
|
163
128
|
@property
|
|
164
129
|
def mutation_tokenizator(self) -> MutationTokenizator:
|
|
165
130
|
"""
|
|
@@ -173,149 +138,24 @@ class RettxServices:
|
|
|
173
138
|
self._mutation_tokenizator = MutationTokenizator()
|
|
174
139
|
return self._mutation_tokenizator
|
|
175
140
|
|
|
176
|
-
@property
|
|
177
|
-
def ocr_service(self) -> OcrService:
|
|
178
|
-
"""
|
|
179
|
-
Get or create the OCR service.
|
|
180
|
-
|
|
181
|
-
Returns:
|
|
182
|
-
OcrService: Configured service for document analysis and text processing
|
|
183
|
-
|
|
184
|
-
Raises:
|
|
185
|
-
ValueError: If required configuration fields are missing
|
|
186
|
-
"""
|
|
187
|
-
if self._ocr_service is None:
|
|
188
|
-
logger.debug("Initializing OcrService with DocumentAnalysisRepository")
|
|
189
|
-
# Create the repository first
|
|
190
|
-
document_analysis_repo = DocumentAnalysisRepository(self._config)
|
|
191
|
-
# Create the service with the repository
|
|
192
|
-
self._ocr_service = OcrService(document_analysis_repo)
|
|
193
|
-
|
|
194
|
-
return self._ocr_service
|
|
195
|
-
|
|
196
141
|
@property
|
|
197
142
|
def ai_search_service(self) -> AISearchService:
|
|
198
143
|
"""Get or create the AI search service."""
|
|
199
|
-
if self.
|
|
144
|
+
if self._ai_search_service is None:
|
|
200
145
|
logger.debug("Initializing AISearchService")
|
|
201
|
-
self.
|
|
202
|
-
return self.
|
|
146
|
+
self._ai_search_service = AISearchService(self._config)
|
|
147
|
+
return self._ai_search_service
|
|
203
148
|
|
|
204
149
|
@ai_search_service.setter
|
|
205
|
-
def
|
|
150
|
+
def ai_search_service(self, service: AISearchService):
|
|
206
151
|
"""Set the AI search service (for testing purposes)."""
|
|
207
|
-
self.
|
|
152
|
+
self._ai_search_service = service
|
|
208
153
|
|
|
209
154
|
@ai_search_service.deleter
|
|
210
155
|
def ai_search_service(self):
|
|
211
156
|
"""Delete the AI search service (for testing purposes)."""
|
|
212
|
-
self.
|
|
213
|
-
@ocr_service.setter
|
|
214
|
-
def ocr_service(self, service: OcrService):
|
|
215
|
-
"""Set the OCR service (for testing purposes)."""
|
|
216
|
-
self._ocr_service = service
|
|
217
|
-
|
|
218
|
-
@ocr_service.deleter
|
|
219
|
-
def ocr_service(self):
|
|
220
|
-
"""Delete the OCR service (for testing purposes)."""
|
|
221
|
-
self._ocr_service = None
|
|
222
|
-
|
|
223
|
-
@property
|
|
224
|
-
def validation_agent(self) -> ValidationAgent:
|
|
225
|
-
"""
|
|
226
|
-
Get or create the validation agent.
|
|
227
|
-
|
|
228
|
-
Returns:
|
|
229
|
-
ValidationAgent: Agent for document validation using Azure OpenAI
|
|
230
|
-
|
|
231
|
-
Raises:
|
|
232
|
-
ValueError: If required configuration fields are missing
|
|
233
|
-
"""
|
|
234
|
-
if self._validation_agent is None:
|
|
235
|
-
logger.debug("Initializing ValidationAgent")
|
|
236
|
-
self._validation_agent = ValidationAgent(
|
|
237
|
-
api_key=self._config.RETTX_OPENAI_KEY,
|
|
238
|
-
api_version=self._config.RETTX_OPENAI_MODEL_VERSION,
|
|
239
|
-
azure_endpoint=self._config.RETTX_OPENAI_ENDPOINT,
|
|
240
|
-
model_name=self._config.RETTX_OPENAI_MODEL_NAME
|
|
241
|
-
)
|
|
242
|
-
|
|
243
|
-
return self._validation_agent
|
|
244
|
-
|
|
245
|
-
@validation_agent.setter
|
|
246
|
-
def validation_agent(self, agent: ValidationAgent):
|
|
247
|
-
"""Set the validation agent (for testing purposes)."""
|
|
248
|
-
self._validation_agent = agent
|
|
249
|
-
|
|
250
|
-
@validation_agent.deleter
|
|
251
|
-
def validation_agent(self):
|
|
252
|
-
"""Delete the validation agent (for testing purposes)."""
|
|
253
|
-
self._validation_agent = None
|
|
254
|
-
|
|
255
|
-
@property
|
|
256
|
-
def extraction_agent(self) -> MutationExtractionAgent:
|
|
257
|
-
"""
|
|
258
|
-
Get or create the mutation extraction agent.
|
|
259
|
-
|
|
260
|
-
Returns:
|
|
261
|
-
MutationExtractionAgent: Agent for extracting mutations using Azure OpenAI
|
|
262
|
-
|
|
263
|
-
Raises:
|
|
264
|
-
ValueError: If required configuration fields are missing
|
|
265
|
-
"""
|
|
266
|
-
if self._extraction_agent is None:
|
|
267
|
-
logger.debug("Initializing MutationExtractionAgent")
|
|
268
|
-
self._extraction_agent = MutationExtractionAgent(
|
|
269
|
-
api_key=self._config.RETTX_OPENAI_KEY,
|
|
270
|
-
api_version=self._config.RETTX_OPENAI_MODEL_VERSION,
|
|
271
|
-
azure_endpoint=self._config.RETTX_OPENAI_ENDPOINT,
|
|
272
|
-
model_name=self._config.RETTX_OPENAI_MODEL_NAME
|
|
273
|
-
)
|
|
274
|
-
|
|
275
|
-
return self._extraction_agent
|
|
276
|
-
|
|
277
|
-
@extraction_agent.setter
|
|
278
|
-
def extraction_agent(self, agent: MutationExtractionAgent):
|
|
279
|
-
"""Set the extraction agent (for testing purposes)."""
|
|
280
|
-
self._extraction_agent = agent
|
|
157
|
+
self._ai_search_service = None
|
|
281
158
|
|
|
282
|
-
@extraction_agent.deleter
|
|
283
|
-
def extraction_agent(self):
|
|
284
|
-
"""Delete the extraction agent (for testing purposes)."""
|
|
285
|
-
self._extraction_agent = None
|
|
286
|
-
|
|
287
|
-
@property
|
|
288
|
-
def summarization_agent(self) -> SummarizationAgent:
|
|
289
|
-
"""
|
|
290
|
-
Get or create the summarization agent.
|
|
291
|
-
|
|
292
|
-
Returns:
|
|
293
|
-
SummarizationAgent: Agent for summarizing reports using Azure OpenAI
|
|
294
|
-
|
|
295
|
-
Raises:
|
|
296
|
-
ValueError: If required configuration fields are missing
|
|
297
|
-
"""
|
|
298
|
-
if self._summarization_agent is None:
|
|
299
|
-
logger.debug("Initializing SummarizationAgent")
|
|
300
|
-
self._summarization_agent = SummarizationAgent(
|
|
301
|
-
api_key=self._config.RETTX_OPENAI_KEY,
|
|
302
|
-
api_version=self._config.RETTX_OPENAI_MODEL_VERSION,
|
|
303
|
-
azure_endpoint=self._config.RETTX_OPENAI_ENDPOINT,
|
|
304
|
-
model_name=self._config.RETTX_OPENAI_MODEL_NAME
|
|
305
|
-
)
|
|
306
|
-
|
|
307
|
-
return self._summarization_agent
|
|
308
|
-
|
|
309
|
-
@summarization_agent.setter
|
|
310
|
-
def summarization_agent(self, agent: SummarizationAgent):
|
|
311
|
-
"""Set the summarization agent (for testing purposes)."""
|
|
312
|
-
self._summarization_agent = agent
|
|
313
|
-
|
|
314
|
-
@summarization_agent.deleter
|
|
315
|
-
def summarization_agent(self):
|
|
316
|
-
"""Delete the summarization agent (for testing purposes)."""
|
|
317
|
-
self._summarization_agent = None
|
|
318
|
-
|
|
319
159
|
@property
|
|
320
160
|
def keyword_detector_service(self) -> KeywordDetectorService:
|
|
321
161
|
"""
|
|
@@ -337,7 +177,7 @@ class RettxServices:
|
|
|
337
177
|
logger.debug(f"Text analytics repository not available: {e}")
|
|
338
178
|
|
|
339
179
|
try:
|
|
340
|
-
ai_search_svc = self.
|
|
180
|
+
ai_search_svc = self.ai_search_service
|
|
341
181
|
except (ValueError, AttributeError) as e:
|
|
342
182
|
logger.debug(f"AI search service not available: {e}")
|
|
343
183
|
|
|
@@ -369,9 +209,6 @@ class RettxServices:
|
|
|
369
209
|
if self._variant_validator_service:
|
|
370
210
|
self._variant_validator_service.close()
|
|
371
211
|
|
|
372
|
-
if self._mutation_validator:
|
|
373
|
-
self._mutation_validator.close()
|
|
374
|
-
|
|
375
212
|
# Other services don't currently have cleanup methods, but this provides
|
|
376
213
|
# a central place to add cleanup logic as services evolve
|
|
377
214
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: rettxmutation
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.2
|
|
4
4
|
Summary: Extract Rett Syndrome mutations from genetic diagnosis report
|
|
5
5
|
Author-email: Pedro Rocha <procha@rettsyndrome.eu>
|
|
6
6
|
License: MIT License
|
|
@@ -13,21 +13,15 @@ Requires-Python: >=3.8
|
|
|
13
13
|
Description-Content-Type: text/markdown
|
|
14
14
|
License-File: LICENSE
|
|
15
15
|
Requires-Dist: python-dotenv
|
|
16
|
-
Requires-Dist: azure-ai-formrecognizer
|
|
17
16
|
Requires-Dist: azure-core
|
|
18
17
|
Requires-Dist: azure-ai-textanalytics
|
|
19
|
-
Requires-Dist: azure.ai.documentintelligence
|
|
20
|
-
Requires-Dist: ftfy
|
|
21
18
|
Requires-Dist: mutalyzer_hgvs_parser
|
|
22
19
|
Requires-Dist: pydantic
|
|
23
|
-
Requires-Dist: pydantic_settings
|
|
24
20
|
Requires-Dist: openai
|
|
25
|
-
Requires-Dist: opencv-python-headless
|
|
26
21
|
Requires-Dist: backoff
|
|
27
22
|
Requires-Dist: jmespath
|
|
28
23
|
Requires-Dist: azure-search-documents
|
|
29
|
-
Requires-Dist:
|
|
30
|
-
Requires-Dist: importlib.resources
|
|
24
|
+
Requires-Dist: numpy
|
|
31
25
|
Dynamic: license-file
|
|
32
26
|
|
|
33
27
|
# RettX Mutation Analysis Library
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
pyproject.toml
|
|
4
|
+
src/rettxmutation/__init__.py
|
|
5
|
+
src/rettxmutation/config.py
|
|
6
|
+
src/rettxmutation.egg-info/PKG-INFO
|
|
7
|
+
src/rettxmutation.egg-info/SOURCES.txt
|
|
8
|
+
src/rettxmutation.egg-info/dependency_links.txt
|
|
9
|
+
src/rettxmutation.egg-info/requires.txt
|
|
10
|
+
src/rettxmutation.egg-info/top_level.txt
|
|
11
|
+
src/rettxmutation/models/__init__.py
|
|
12
|
+
src/rettxmutation/models/gene_assembly.py
|
|
13
|
+
src/rettxmutation/models/gene_models.py
|
|
14
|
+
src/rettxmutation/models/gene_registry.py
|
|
15
|
+
src/rettxmutation/models/keyword_collection.py
|
|
16
|
+
src/rettxmutation/models/mutation_model.py
|
|
17
|
+
src/rettxmutation/models/search_models.py
|
|
18
|
+
src/rettxmutation/repositories/__init__.py
|
|
19
|
+
src/rettxmutation/repositories/ai_search_repository.py
|
|
20
|
+
src/rettxmutation/repositories/interfaces.py
|
|
21
|
+
src/rettxmutation/repositories/text_analytics_repository.py
|
|
22
|
+
src/rettxmutation/repositories/variant_validator_repository.py
|
|
23
|
+
src/rettxmutation/services/__init__.py
|
|
24
|
+
src/rettxmutation/services/ai_search.py
|
|
25
|
+
src/rettxmutation/services/embedding_client.py
|
|
26
|
+
src/rettxmutation/services/embedding_service.py
|
|
27
|
+
src/rettxmutation/services/keyword_detector_service.py
|
|
28
|
+
src/rettxmutation/services/mutation_tokenizator.py
|
|
29
|
+
src/rettxmutation/services/services_factory.py
|
|
30
|
+
src/rettxmutation/services/variant_validator_mapping_service.py
|
|
31
|
+
src/rettxmutation/services/variant_validator_service.py
|
|
32
|
+
src/rettxmutation/utils/__init__.py
|
|
33
|
+
src/rettxmutation/utils/hgvs_descriptor.py
|
|
34
|
+
src/rettxmutation/utils/mutation_converter.py
|
|
35
|
+
src/rettxmutation/utils/text_util.py
|
|
36
|
+
tests/test_gene_model.py
|
|
37
|
+
tests/test_keyword_collection.py
|
|
38
|
+
tests/test_keyword_detector.py
|
|
39
|
+
tests/test_semantic_search.py
|
|
40
|
+
tests/test_variant_validator.py
|