deapi-mcp 0.7.0__py3-none-any.whl

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.
@@ -0,0 +1,102 @@
1
+ """Text embedding tools for deAPI MCP server."""
2
+
3
+ from typing import Annotated, Any, List, Optional, Union
4
+
5
+ from pydantic import Field
6
+
7
+ from ..deapi_client import DeapiAPIError, get_client
8
+ from ..polling_manager import PollingManager
9
+ from ._responses import build_job_response, build_price_response
10
+
11
+
12
+ async def text_to_embedding(
13
+ input: Annotated[
14
+ Union[str, List[str]], Field(description="Text string or list of text strings to embed")
15
+ ],
16
+ model: Annotated[
17
+ str, Field(description="Embedding model name (e.g., 'Bge_M3_FP16')")
18
+ ] = "Bge_M3_FP16",
19
+ return_result_in_response: Annotated[bool, Field(description="Return embedding inline")] = True,
20
+ webhook_url: Annotated[
21
+ Optional[str],
22
+ Field(
23
+ description="HTTPS URL for deAPI to call when this job finishes. Notifies your own systems; the tool still returns the result here"
24
+ ),
25
+ ] = None,
26
+ webhook_secret: Annotated[
27
+ Optional[str],
28
+ Field(
29
+ description="32-255 char key deAPI signs the callback with (HMAC-SHA256). Needs webhook_url. A secret given in chat stays in the transcript"
30
+ ),
31
+ ] = None,
32
+ ) -> dict[str, Any]:
33
+ """Generate text embeddings using AI models.
34
+
35
+ Converts text into vector embeddings for semantic search, similarity comparison,
36
+ and other NLP tasks. Accepts a single string or a list of strings.
37
+
38
+ Returns:
39
+ dict: Contains 'success', 'job_id' and the embeddings: 'result' when returned
40
+ inline, otherwise 'result_url' pointing at the file that holds them
41
+ """
42
+ try:
43
+ client = get_client()
44
+ async with client:
45
+ request_data = {
46
+ "input": input,
47
+ "model": model,
48
+ "return_result_in_response": return_result_in_response,
49
+ }
50
+
51
+ job_response = await client.submit_job(
52
+ endpoint="embeddings",
53
+ json_data=request_data,
54
+ webhook_url=webhook_url,
55
+ webhook_secret=webhook_secret,
56
+ )
57
+ job_id = job_response.data.request_id
58
+
59
+ polling_manager = PollingManager(client, job_type="embedding")
60
+ result = await polling_manager.poll_until_complete(job_id)
61
+
62
+ # With return_result_in_response=False the vectors go to a file and
63
+ # only result_url carries them, the same as a transcript.
64
+ return build_job_response(result, job_id)
65
+
66
+ except DeapiAPIError as e:
67
+ return {"success": False, "error": f"API error: {str(e)}"}
68
+ except Exception as e:
69
+ return {"success": False, "error": f"Unexpected error: {str(e)}"}
70
+
71
+
72
+ async def text_to_embedding_price(
73
+ input: Annotated[
74
+ Union[str, List[str]],
75
+ Field(description="Text string or list of text strings for price calculation"),
76
+ ],
77
+ model: Annotated[str, Field(description="Embedding model name")] = "Bge_M3_FP16",
78
+ ) -> dict[str, Any]:
79
+ """Calculate price for text embedding generation.
80
+
81
+ Returns:
82
+ dict: Contains 'success' and 'price' information
83
+ """
84
+ try:
85
+ client = get_client()
86
+ async with client:
87
+ request_data = {
88
+ "input": input,
89
+ "model": model,
90
+ }
91
+
92
+ price_response = await client.calculate_price(
93
+ endpoint="embeddings/price",
94
+ json_data=request_data,
95
+ )
96
+
97
+ return build_price_response(price_response)
98
+
99
+ except DeapiAPIError as e:
100
+ return {"success": False, "error": f"API error: {str(e)}"}
101
+ except Exception as e:
102
+ return {"success": False, "error": f"Unexpected error: {str(e)}"}