Skip to content

Commit c99e631

Browse files
authored
refactor: make pipeline more consistent (#174)
1 parent b03b260 commit c99e631

11 files changed

Lines changed: 90 additions & 101 deletions

File tree

src/deepset_mcp/api/README.md

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,13 @@ from deepset_mcp.api.client import AsyncDeepsetClient
4040
async with AsyncDeepsetClient() as client:
4141
# Access pipeline resource for a specific workspace
4242
pipelines = client.pipelines(workspace="your-workspace")
43-
43+
4444
# List all pipelines
4545
pipeline_list = await pipelines.list(page_number=1, limit=10)
46-
46+
4747
# Get a specific pipeline with its YAML configuration
4848
pipeline = await pipelines.get("my-pipeline", include_yaml=True)
49-
49+
5050
# Create a new pipeline
5151
yaml_config = """
5252
components:
@@ -55,9 +55,9 @@ async with AsyncDeepsetClient() as client:
5555
params:
5656
model: "sentence-transformers/all-MiniLM-L6-v2"
5757
"""
58-
58+
5959
response = await pipelines.create(
60-
name="my-new-pipeline",
60+
pipeline_name="my-new-pipeline",
6161
yaml_config=yaml_config
6262
)
6363
```
@@ -135,9 +135,9 @@ async with AsyncDeepsetClient() as client:
135135
Monitor pipeline performance and troubleshoot issues:
136136

137137
```python
138-
from deepset_mcp.api.pipeline.log_level import LogLevel
139-
from deepset_mcp.api.client import AsyncDeepsetClient
140138

139+
from deepset_mcp.api.pipeline.models import LogLevel
140+
from deepset_mcp.api.client import AsyncDeepsetClient
141141

142142
async with AsyncDeepsetClient() as client:
143143
pipelines = client.pipelines(workspace="your-workspace")
@@ -147,7 +147,7 @@ async with AsyncDeepsetClient() as client:
147147
limit=50,
148148
level=LogLevel.ERROR # Filter by log level
149149
)
150-
150+
151151
for log_entry in logs.data:
152152
print(f"[{log_entry.level}] {log_entry.message}")
153153
```
@@ -212,23 +212,23 @@ from deepset_mcp.api.client import AsyncDeepsetClient
212212

213213
async with AsyncDeepsetClient() as client:
214214
templates = client.pipeline_templates(workspace="your-workspace")
215-
215+
216216
# List available templates
217217
template_list = await templates.list_templates(
218218
limit=20,
219219
field="created_at",
220220
order="DESC",
221221
filter="category eq 'RAG'" # OData filter
222222
)
223-
223+
224224
# Get a specific template with its YAML configuration
225225
template = await templates.get_template("template-name")
226-
226+
227227
# Use the template YAML to create a new pipeline
228228
if template.yaml_config:
229229
pipelines = client.pipelines(workspace="your-workspace")
230230
await pipelines.create(
231-
name="pipeline-from-template",
231+
pipeline_name="pipeline-from-template",
232232
yaml_config=template.yaml_config
233233
)
234234
```
@@ -451,11 +451,11 @@ from deepset_mcp.api.client import AsyncDeepsetClient
451451
async with AsyncDeepsetClient() as client:
452452
# Development workspace
453453
dev_pipelines = client.pipelines("development")
454-
dev_pipeline = await dev_pipelines.create(name="test-pipeline", yaml_config=config)
455-
454+
dev_pipeline = await dev_pipelines.create(pipeline_name="test-pipeline", yaml_config=config)
455+
456456
# Production workspace
457457
prod_pipelines = client.pipelines("production")
458-
prod_pipeline = await prod_pipelines.create(name="prod-pipeline", yaml_config=config)
458+
prod_pipeline = await prod_pipelines.create(pipeline_name="prod-pipeline", yaml_config=config)
459459
```
460460

461461
### Validation Before Deployment
@@ -465,18 +465,17 @@ Always validate pipeline configurations before deployment:
465465
```python
466466
from deepset_mcp.api.client import AsyncDeepsetClient
467467

468-
469468
async with AsyncDeepsetClient() as client:
470469
pipelines = client.pipelines(workspace="your-workspace")
471470

472471
# Validate configuration
473472
validation_result = await pipelines.validate(yaml_config)
474-
473+
475474
if validation_result.valid:
476475
# Create and deploy pipeline
477-
await pipelines.create(name="my-pipeline", yaml_config=yaml_config)
476+
await pipelines.create(pipeline_name="my-pipeline", yaml_config=yaml_config)
478477
deployment_result = await pipelines.deploy("my-pipeline")
479-
478+
480479
if deployment_result.valid:
481480
print("Pipeline deployed successfully")
482481
else:

src/deepset_mcp/api/pipeline/log_level.py

Lines changed: 0 additions & 13 deletions
This file was deleted.

src/deepset_mcp/api/pipeline/models.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,3 +237,11 @@ class PipelineOperationWithErrors(BaseModel):
237237
message: str
238238
validation_result: PipelineValidationResult
239239
pipeline: DeepsetPipeline
240+
241+
242+
class LogLevel(StrEnum):
243+
"""Log level filter options for pipeline logs."""
244+
245+
INFO = "info"
246+
WARNING = "warning"
247+
ERROR = "error"

src/deepset_mcp/api/pipeline/protocols.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
from collections.abc import AsyncIterator
66
from typing import Any, Protocol
77

8-
from deepset_mcp.api.pipeline.log_level import LogLevel
98
from deepset_mcp.api.pipeline.models import (
109
DeepsetPipeline,
1110
DeepsetSearchResponse,
1211
DeepsetStreamEvent,
12+
LogLevel,
1313
PipelineList,
1414
PipelineLogList,
1515
PipelineValidationResult,

src/deepset_mcp/api/pipeline/resource.py

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,14 @@
66
import logging
77
from collections.abc import AsyncIterator
88
from typing import TYPE_CHECKING, Any
9+
from urllib.parse import quote
910

1011
from deepset_mcp.api.exceptions import UnexpectedAPIError
11-
from deepset_mcp.api.pipeline.log_level import LogLevel
1212
from deepset_mcp.api.pipeline.models import (
1313
DeepsetPipeline,
1414
DeepsetSearchResponse,
1515
DeepsetStreamEvent,
16+
LogLevel,
1617
PipelineList,
1718
PipelineLogList,
1819
PipelineValidationResult,
@@ -29,7 +30,7 @@
2930

3031

3132
class PipelineResource(PipelineResourceProtocol):
32-
"""Manages interactions with the deepset pipeline API."""
33+
"""Interact with pipelines on the deepset AI platform."""
3334

3435
def __init__(
3536
self,
@@ -54,7 +55,7 @@ async def validate(self, yaml_config: str) -> PipelineValidationResult:
5455
data = {"query_yaml": yaml_config}
5556

5657
resp = await self._client.request(
57-
endpoint=f"v1/workspaces/{self._workspace}/pipeline_validations",
58+
endpoint=f"v1/workspaces/{quote(self._workspace, safe='')}/pipeline_validations",
5859
method="POST",
5960
data=data,
6061
)
@@ -92,7 +93,7 @@ async def list(
9293
}
9394

9495
resp = await self._client.request(
95-
endpoint=f"v1/workspaces/{self._workspace}/pipelines",
96+
endpoint=f"v1/workspaces/{quote(self._workspace, safe='')}/pipelines",
9697
method="GET",
9798
params=params,
9899
)
@@ -118,14 +119,18 @@ async def get(self, pipeline_name: str, include_yaml: bool = True) -> DeepsetPip
118119
:param include_yaml: Whether to include YAML configuration in the response.
119120
:returns: DeepsetPipeline instance.
120121
"""
121-
resp = await self._client.request(endpoint=f"v1/workspaces/{self._workspace}/pipelines/{pipeline_name}")
122+
resp = await self._client.request(
123+
endpoint=f"v1/workspaces/{quote(self._workspace, safe='')}/pipelines/{quote(pipeline_name, safe='')}"
124+
)
122125
raise_for_status(resp)
123126

124127
pipeline = DeepsetPipeline.model_validate(resp.json)
125128

126129
if include_yaml:
127130
yaml_response = await self._client.request(
128-
endpoint=f"v1/workspaces/{self._workspace}/pipelines/{pipeline_name}/yaml"
131+
endpoint=(
132+
f"v1/workspaces/{quote(self._workspace, safe='')}/pipelines/{quote(pipeline_name, safe='')}/yaml"
133+
)
129134
)
130135

131136
raise_for_status(yaml_response)
@@ -135,16 +140,16 @@ async def get(self, pipeline_name: str, include_yaml: bool = True) -> DeepsetPip
135140

136141
return pipeline
137142

138-
async def create(self, name: str, yaml_config: str) -> NoContentResponse:
143+
async def create(self, pipeline_name: str, yaml_config: str) -> NoContentResponse:
139144
"""Create a new pipeline with a name and YAML config.
140145
141-
:param name: Name of the new pipeline.
146+
:param pipeline_name: Name of the new pipeline.
142147
:param yaml_config: YAML configuration for the pipeline.
143148
:returns: NoContentResponse indicating successful creation.
144149
"""
145-
data = {"name": name, "query_yaml": yaml_config}
150+
data = {"name": pipeline_name, "query_yaml": yaml_config}
146151
resp = await self._client.request(
147-
endpoint=f"v1/workspaces/{self._workspace}/pipelines",
152+
endpoint=f"v1/workspaces/{quote(self._workspace, safe='')}/pipelines",
148153
method="POST",
149154
data=data,
150155
)
@@ -170,7 +175,7 @@ async def update(
170175
# Handle name update first if any
171176
if updated_pipeline_name is not None:
172177
name_resp = await self._client.request(
173-
endpoint=f"v1/workspaces/{self._workspace}/pipelines/{pipeline_name}",
178+
endpoint=f"v1/workspaces/{quote(self._workspace, safe='')}/pipelines/{quote(pipeline_name, safe='')}",
174179
method="PATCH",
175180
data={"name": updated_pipeline_name},
176181
)
@@ -184,7 +189,9 @@ async def update(
184189

185190
if yaml_config is not None:
186191
yaml_resp = await self._client.request(
187-
endpoint=f"v1/workspaces/{self._workspace}/pipelines/{pipeline_name}/yaml",
192+
endpoint=(
193+
f"v1/workspaces/{quote(self._workspace, safe='')}/pipelines/{quote(pipeline_name, safe='')}/yaml"
194+
),
188195
method="PUT",
189196
data={"query_yaml": yaml_config},
190197
)
@@ -223,7 +230,7 @@ async def get_logs(
223230
params["filter"] = f"level eq '{level}' and origin eq 'querypipeline'"
224231

225232
resp = await self._client.request(
226-
endpoint=f"v1/workspaces/{self._workspace}/pipelines/{pipeline_name}/logs",
233+
endpoint=f"v1/workspaces/{quote(self._workspace, safe='')}/pipelines/{quote(pipeline_name, safe='')}/logs",
227234
method="GET",
228235
params=params,
229236
)
@@ -244,7 +251,9 @@ async def deploy(self, pipeline_name: str) -> PipelineValidationResult:
244251
:raises UnexpectedAPIError: If the API returns an unexpected status code.
245252
"""
246253
resp = await self._client.request(
247-
endpoint=f"v1/workspaces/{self._workspace}/pipelines/{pipeline_name}/deploy",
254+
endpoint=(
255+
f"v1/workspaces/{quote(self._workspace, safe='')}/pipelines/{quote(pipeline_name, safe='')}/deploy"
256+
),
248257
method="POST",
249258
)
250259

@@ -274,7 +283,7 @@ async def delete(self, pipeline_name: str) -> NoContentResponse:
274283
:raises UnexpectedAPIError: If the API returns an unexpected status code.
275284
"""
276285
resp = await self._client.request(
277-
endpoint=f"v1/workspaces/{self._workspace}/pipelines/{pipeline_name}",
286+
endpoint=f"v1/workspaces/{quote(self._workspace, safe='')}/pipelines/{quote(pipeline_name, safe='')}",
278287
method="DELETE",
279288
)
280289

@@ -315,7 +324,9 @@ async def search(
315324
data["filters"] = filters
316325

317326
resp = await self._client.request(
318-
endpoint=f"v1/workspaces/{self._workspace}/pipelines/{pipeline_name}/search",
327+
endpoint=(
328+
f"v1/workspaces/{quote(self._workspace, safe='')}/pipelines/{quote(pipeline_name, safe='')}/search"
329+
),
319330
method="POST",
320331
data=data,
321332
response_type=dict[str, Any],
@@ -365,7 +376,10 @@ async def search_stream(
365376
data["filters"] = filters
366377

367378
async with self._client.stream_request(
368-
endpoint=f"v1/workspaces/{self._workspace}/pipelines/{pipeline_name}/search-stream",
379+
endpoint=(
380+
f"v1/workspaces/{quote(self._workspace, safe='')}/pipelines/"
381+
f"{quote(pipeline_name, safe='')}/search-stream"
382+
),
369383
method="POST",
370384
data=data,
371385
) as resp:

src/deepset_mcp/tools/pipeline.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
import yaml
88

99
from deepset_mcp.api.exceptions import BadRequestError, ResourceNotFoundError, UnexpectedAPIError
10-
from deepset_mcp.api.pipeline.log_level import LogLevel
1110
from deepset_mcp.api.pipeline.models import (
1211
DeepsetPipeline,
1312
DeepsetSearchResponse,
13+
LogLevel,
1414
PipelineList,
1515
PipelineLogList,
1616
PipelineOperationWithErrors,

test/integration/test_integration_pipeline_logs.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ async def test_get_logs_for_deployed_pipeline(
125125
pipeline_name = "test-logs-pipeline"
126126

127127
# Step 1: Create a pipeline
128-
await pipeline_resource.create(name=pipeline_name, yaml_config=simple_yaml_config)
128+
await pipeline_resource.create(pipeline_name=pipeline_name, yaml_config=simple_yaml_config)
129129

130130
# Step 2: Deploy the pipeline
131131
deploy_result = await pipeline_resource.deploy(pipeline_name=pipeline_name)
@@ -172,7 +172,7 @@ async def test_get_logs_for_non_deployed_pipeline(
172172
pipeline_name = "test-logs-non-deployed-pipeline"
173173

174174
# Create pipeline but do not deploy it
175-
await pipeline_resource.create(name=pipeline_name, yaml_config=simple_yaml_config)
175+
await pipeline_resource.create(pipeline_name=pipeline_name, yaml_config=simple_yaml_config)
176176

177177
# Try to get logs for the non-deployed pipeline
178178
logs = await pipeline_resource.get_logs(pipeline_name=pipeline_name)
@@ -197,7 +197,7 @@ async def test_deployment_timeout_handling(
197197
pipeline_name = "test-timeout-pipeline"
198198

199199
# Create and deploy pipeline
200-
await pipeline_resource.create(name=pipeline_name, yaml_config=simple_yaml_config)
200+
await pipeline_resource.create(pipeline_name=pipeline_name, yaml_config=simple_yaml_config)
201201
deploy_result = await pipeline_resource.deploy(pipeline_name=pipeline_name)
202202
assert deploy_result.valid is True
203203

0 commit comments

Comments
 (0)