Spaces:
Running on Zero
Running on Zero
Download backend/llama.cpp/tools/ui/src/lib/services/tools.service.ts from kazutab/mindmap-studio: direct link, hf CLI and curl.
- Browser
- Download file 1.19 kB
-
https://huggingface.co/spaces/kazutab/mindmap-studio/resolve/main/backend/llama.cpp/tools/ui/src/lib/services/tools.service.ts
- Command line
-
hf download hf://spaces/kazutab/mindmap-studio/backend/llama.cpp/tools/ui/src/lib/services/tools.service.ts
-
curl -L -o tools.service.ts https://huggingface.co/spaces/kazutab/mindmap-studio/resolve/main/backend/llama.cpp/tools/ui/src/lib/services/tools.service.ts
1.19 kB
| import { apiFetch } from '$lib/utils'; | |
| import { API_TOOLS } from '$lib/constants'; | |
| import { ToolResponseField } from '$lib/enums'; | |
| import type { ToolExecutionResult, ServerBuiltinToolInfo } from '$lib/types'; | |
| export class ToolsService { | |
| /** | |
| * Fetch the list of built-in tools from the server. | |
| * | |
| * @returns Array of tool definitions in OpenAI-compatible format | |
| */ | |
| static async list(): Promise<ServerBuiltinToolInfo[]> { | |
| return apiFetch<ServerBuiltinToolInfo[]>(API_TOOLS.LIST); | |
| } | |
| /** | |
| * Execute a built-in tool on the server. | |
| */ | |
| static async executeTool( | |
| toolName: string, | |
| params: Record<string, unknown>, | |
| signal?: AbortSignal | |
| ): Promise<ToolExecutionResult> { | |
| const result = await apiFetch<Record<string, unknown>>(API_TOOLS.EXECUTE, { | |
| method: 'POST', | |
| body: JSON.stringify({ tool: toolName, params }), | |
| signal | |
| }); | |
| if (ToolResponseField.ERROR in result) { | |
| return { content: String(result[ToolResponseField.ERROR]), isError: true }; | |
| } | |
| if (ToolResponseField.PLAIN_TEXT in result) { | |
| return { content: String(result[ToolResponseField.PLAIN_TEXT]), isError: false }; | |
| } | |
| return { content: JSON.stringify(result), isError: false }; | |
| } | |
| } | |