Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/vtk_prompt/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,16 @@ def query(
}
)
else:
# Normal path: build context and prompt
# Normal path: translate to DSL if needed, then build context and prompt
if mcp_client:
is_dsl = mcp_client._call_tool("is_dsl_prompt", {"text": message})
if is_dsl not in ("true", "True", True):
translated = mcp_client.translate_prompt(message)
if translated:
if self.verbose:
logger.debug("DSL translation:\n%s", translated)
message = translated

context_snippets = None
if mcp_client:
mcp_context = mcp_client.get_enriched_context(message, top_k=top_k)
Expand Down
30 changes: 30 additions & 0 deletions src/vtk_prompt/vtk_mcp_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,36 @@ def validate_code(self, code: str) -> str | None:
except Exception:
return None

def translate_prompt(
self,
query: str,
model: str | None = None,
base_url: str | None = None,
api_key: str | None = None,
) -> str | None:
"""Translate a natural language query into the VTK pipeline DSL.

Args:
query: Natural language prompt.
model: LiteLLM model override (e.g. ``ollama/llama3``).
base_url: Base URL for OpenAI-compatible endpoints (e.g. Ollama).
api_key: API key for the endpoint.

Returns the DSL string, or None if the tool call fails.
"""
args: dict = {"query": query}
if model:
args["model"] = model
if base_url:
args["base_url"] = base_url
if api_key:
args["api_key"] = api_key
result = self._call_tool("translate_prompt_to_dsl", args)
if not result or result.startswith("Error:"):
logger.warning("DSL translation failed: %s", result)
return None
return result

def get_enriched_context(self, query: str, top_k: int = 5) -> str:
"""Build context for the LLM combining code examples, docs, and VTK class hints."""
parts = []
Expand Down
Loading