Skip to content

Commit fed9699

Browse files
committed
copilot fixes
1 parent ef48f21 commit fed9699

11 files changed

Lines changed: 72 additions & 47 deletions

File tree

docs/source/advanced_usage/profiler.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ If you only need to measure execution time (wall clock), use `time_function` or
119119
```python
120120
from mmore.profiler import time_function, time_context
121121

122-
@time_function
122+
@time_function()
123123
def quick_check():
124124
pass
125125

pyrightconfig.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"include": ["src/mmore", "tests"],
3+
"exclude": ["build", "dist", "**/__pycache__", "*.egg-info"],
4+
"executionEnvironments": [
5+
{
6+
"root": "src/mmore",
7+
"extraPaths": ["src"]
8+
},
9+
{
10+
"root": "tests",
11+
"extraPaths": ["src"]
12+
}
13+
],
14+
"pythonVersion": "3.10",
15+
"typeCheckingMode": "standard"
16+
}

src/mmore/process/post_processor/__init__.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,15 @@ def load_postprocessor(config: BasePostProcessorConfig) -> BasePostProcessor:
3333
from .translator import TranslatorConfig, TranslatorPostProcessor
3434

3535
config_translator = load_config(config.args, TranslatorConfig)
36-
return TranslatorPostProcessor.from_config(config_translator)
36+
return cast(
37+
BasePostProcessor, TranslatorPostProcessor.from_config(config_translator)
38+
)
3739

3840
elif config.type == "metafuse":
3941
from .metafuse import MetaDataInfusor, MetaDataInfusorConfig
4042

4143
config_metafuse = load_config(config.args, MetaDataInfusorConfig)
42-
return MetaDataInfusor.from_config(config_metafuse)
44+
return cast(BasePostProcessor, MetaDataInfusor.from_config(config_metafuse))
4345

4446
else:
4547
raise ValueError(f"Unrecognized postprocessor type: {config.type}")

src/mmore/process/processors/media_processor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ def _extract_video_frames(file_path: str) -> List[Image.Image]:
161161
for i in range(num_thumbnails):
162162
t = min(i * sample_rate, duration - 0.1)
163163
frame = clip.get_frame(t)
164-
image = Image.fromarray(cast(np.ndarray, frame).convert("RGB"))
164+
image = Image.fromarray(cast(np.ndarray, frame)).convert("RGB")
165165
images.append(image)
166166
logger.info(f"Extracted {len(images)} images from {file_path}.")
167167
except Exception as e:

src/mmore/profiler.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,12 @@
1010
from contextlib import contextmanager
1111
from dataclasses import dataclass
1212
from pathlib import Path
13-
from typing import Callable, Optional
13+
from typing import Callable, Optional, TypeVar
1414

1515
logger = logging.getLogger(__name__)
1616

17+
R = TypeVar("R")
18+
1719

1820
@dataclass
1921
class ProfilingConfig:
@@ -204,20 +206,19 @@ def time_context(name: str, log: bool = True):
204206
logger.info(f"⏱️ {name} took {elapsed:.4f} seconds")
205207

206208

207-
def time_function(func: Optional[Callable] = None, log: bool = True):
209+
def time_function(log: bool = True) -> Callable[[Callable[..., R]], Callable[..., R]]:
208210
"""Decorator to time a function execution.
209211
210212
Args:
211-
func: Function to decorate (if used as decorator without parentheses)
212213
log: Whether to log the timing result
213214
214215
Returns:
215216
Decorated function
216217
"""
217218

218-
def decorator(f: Callable) -> Callable:
219+
def decorator(f: Callable[..., R]) -> Callable[..., R]:
219220
@functools.wraps(f)
220-
def wrapper(*args, **kwargs):
221+
def wrapper(*args: object, **kwargs: object) -> R:
221222
start_time = time.time()
222223
try:
223224
result = f(*args, **kwargs)
@@ -229,10 +230,7 @@ def wrapper(*args, **kwargs):
229230

230231
return wrapper
231232

232-
if func is None:
233-
return decorator
234-
else:
235-
return decorator(func)
233+
return decorator
236234

237235

238236
class Profiler:

src/mmore/run_ragcli.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,9 @@
1414
)
1515

1616
from mmore.profiler import enable_profiling_from_env, profile_function
17-
18-
from .rag.pipeline import RAGPipeline
19-
from .run_rag import RAGInferenceConfig
20-
from .utils import load_config
17+
from mmore.rag.pipeline import RAGPipeline
18+
from mmore.run_rag import RAGInferenceConfig
19+
from mmore.utils import load_config
2120

2221

2322
class RagCLI:

src/mmore/run_websearch.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,12 @@
1616
from pydantic import BaseModel, Field
1717

1818
from mmore.profiler import enable_profiling_from_env, profile_function
19-
20-
from .rag.pipeline import RAGPipeline
21-
from .run_rag import APIConfig, LocalConfig, RAGInferenceConfig
22-
from .utils import load_config
23-
from .websearchRAG.config import WebsearchConfig
24-
from .websearchRAG.logging_config import logger
25-
from .websearchRAG.pipeline import WebsearchPipeline
19+
from mmore.rag.pipeline import RAGPipeline
20+
from mmore.run_rag import APIConfig, LocalConfig, RAGInferenceConfig
21+
from mmore.utils import load_config
22+
from mmore.websearchRAG.config import WebsearchConfig
23+
from mmore.websearchRAG.logging_config import logger
24+
from mmore.websearchRAG.pipeline import WebsearchPipeline
2625

2726
load_dotenv()
2827

src/mmore/tui/config_builder.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -802,7 +802,7 @@ def pick_or_build_config(
802802
)
803803
)
804804
path = picked
805-
if choice == "edit":
805+
if choice == "edit" and path is not None:
806806
_edit_config(path)
807807

808808
if choice == "manual":

tests/conftest.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import pytest
55
from langchain_milvus.utils.sparse import BaseSparseEmbedding
66

7-
from mmore.type import MultimodalSample
7+
from mmore.type import DocumentMetadata, MultimodalSample
88

99

1010
class FakeSparseEmbedding(BaseSparseEmbedding):
@@ -23,21 +23,21 @@ def embed_documents(self, texts: List[str]) -> List[Dict[int, float]]:
2323
document_id="doc-1",
2424
text="Paris is the capital of France.",
2525
modalities=[],
26-
metadata={},
26+
metadata=DocumentMetadata(),
2727
),
2828
MultimodalSample(
2929
id="doc-2",
3030
document_id="doc-2",
3131
text="The Eiffel Tower stands 330 metres tall.",
3232
modalities=[],
33-
metadata={"author": "Alice"},
33+
metadata=DocumentMetadata(extra={"author": "Alice"}),
3434
),
3535
MultimodalSample(
3636
id="doc-3",
3737
document_id="doc-3",
3838
text="Milvus is an open-source vector database.",
3939
modalities=[],
40-
metadata={},
40+
metadata=DocumentMetadata(),
4141
),
4242
]
4343

tests/test_indexer.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from mmore.index.indexer import Indexer
1212
from mmore.rag.model import DenseModelConfig, SparseModelConfig
1313
from mmore.run_index import index
14-
from mmore.type import MultimodalSample
14+
from mmore.type import DocumentMetadata, MultimodalSample
1515

1616

1717
@pytest.fixture
@@ -98,7 +98,7 @@ def test_indexer_idempotent_collection(mock_sparse, tmp_path):
9898
document_id="doc-4",
9999
text="A fourth document.",
100100
modalities=[],
101-
metadata={},
101+
metadata=DocumentMetadata(),
102102
)
103103
]
104104

@@ -153,7 +153,7 @@ def test_indexer_error_on_missing_collection(mock_sparse, tmp_path):
153153
)
154154

155155
doc = MultimodalSample(
156-
id="x", document_id="x", text="test", modalities=[], metadata={}
156+
id="x", document_id="x", text="test", modalities=[], metadata=DocumentMetadata()
157157
)
158158
with pytest.raises(Exception):
159159
# Bypasses index_documents (which creates the collection) and inserts directly

0 commit comments

Comments
 (0)