1+ from dataclasses import dataclass
12from typing import Iterable
3+
4+ from openai .types .chat import ChatCompletionContentPartTextParam , ChatCompletionToolParam
5+
26from chat_context_toolkit .virtual_filesystem ._types import ToolDefinition
37from chat_context_toolkit .virtual_filesystem ._virtual_filesystem import VirtualFileSystem
4- from openai .types .chat import ChatCompletionContentPartTextParam , ChatCompletionToolParam
8+
9+
10+ @dataclass
11+ class ViewToolOptions :
12+ tool_name : str = "view"
13+ """Name of the tool provided to the LLM."""
14+ tool_description : str = "Read the contents of a file at the specified path"
15+ """Description of the tool provided to the LLM."""
16+ path_argument_description : str = "The path to the file to read (e.g., '/docs/file.txt')"
17+ """Description of the 'path' argument."""
518
619
720class ViewTool (ToolDefinition ):
821 """Tool for viewing the contents of a file in the virtual file system."""
922
10- def __init__ (self , virtual_filesystem : VirtualFileSystem , tool_name : str = "view" ) :
23+ def __init__ (self , virtual_filesystem : VirtualFileSystem , options : ViewToolOptions = ViewToolOptions ()) -> None :
1124 self .virtual_filesystem = virtual_filesystem
12- self .tool_name = tool_name
25+ self .options = options
1326
1427 @property
1528 def tool_param (self ) -> ChatCompletionToolParam :
1629 return ChatCompletionToolParam (
1730 type = "function" ,
1831 function = {
19- "name" : self .tool_name ,
20- "description" : "Read the contents of a file at the specified path" ,
32+ "name" : self .options . tool_name ,
33+ "description" : self . options . tool_description ,
2134 "parameters" : {
2235 "type" : "object" ,
2336 "properties" : {
2437 "path" : {
2538 "type" : "string" ,
26- "description" : "The path to the file to read (e.g., '/docs/file.txt')" ,
39+ "description" : self . options . path_argument_description ,
2740 }
2841 },
2942 "required" : ["path" ],
@@ -35,12 +48,12 @@ async def execute(self, args: dict) -> str | Iterable[ChatCompletionContentPartT
3548 """Execute the built-in view tool to read file contents."""
3649 path = args .get ("path" )
3750 if not path :
38- return "Error: 'path' argument is required for the view tool"
51+ return f "Error: 'path' argument is required for the { self . options . tool_name } tool"
3952
4053 try :
4154 file_content = await self .virtual_filesystem .read_file (path )
4255 except FileNotFoundError :
4356 return f"Error: File at path { path } not found. Please pay attention to the available files and try again."
4457
45- result = f" <file path={ path } >\n { file_content } \n </file>"
58+ result = f' <file path=" { path } " >\n { file_content } \n </file>'
4659 return result
0 commit comments