66import faicons
77from chatlas import ChatAuto , ContentToolResult
88from chatlas .types import ToolAnnotations
9- from pydantic import BaseModel , Field
109from shiny import reactive
1110from shiny .express import input , ui
1211from shinychat .express import Chat
@@ -39,20 +38,6 @@ def list_files_impl():
3938 )
4039
4140
42- class ListFileParams (BaseModel ):
43- """
44- List files in the user's current directory. Always check again when asked.
45- """
46-
47- path : str = Field (..., description = "The path to list files from" )
48-
49-
50- class ListFileParamsWithIntent (ListFileParams ):
51- intent : str = Field (
52- ..., description = "The user's intent for this tool" , alias = "_intent"
53- )
54-
55-
5641annotations : ToolAnnotations = {}
5742if TOOL_OPTS ["with_title" ]:
5843 annotations ["title" ] = "List Files"
@@ -61,56 +46,60 @@ class ListFileParamsWithIntent(ListFileParams):
6146if TOOL_OPTS ["async" ]:
6247 if TOOL_OPTS ["with_intent" ]:
6348
64- async def list_files_func1 (path : str , _intent : str ):
49+ async def list_files (path : str , _intent : str ): # pyright: ignore[reportRedeclaration]
50+ """
51+ List files in the user's current directory. Always check again when asked.
52+
53+ Parameters
54+ ----------
55+ path
56+ The path to list files from.
57+ _intent
58+ Reason for the request to explain the tool call to the user.
59+ """
6560 await asyncio .sleep (random .uniform (1 , 10 ))
6661 return list_files_impl ()
6762
68- chat_client .register_tool (
69- list_files_func1 ,
70- name = "list_files" ,
71- model = ListFileParamsWithIntent ,
72- annotations = annotations ,
73- )
74-
7563 else :
7664
77- async def list_files_func2 (path : str ):
65+ async def list_files (path : str ): # pyright: ignore[reportRedeclaration]
66+ """
67+ List files in the user's current directory. Always check again when asked.
68+ """
7869 await asyncio .sleep (random .uniform (1 , 10 ))
7970 return list_files_impl ()
8071
81- chat_client .register_tool (
82- list_files_func2 ,
83- name = "list_files" ,
84- model = ListFileParams ,
85- annotations = annotations ,
86- )
87-
8872else :
8973 if TOOL_OPTS ["with_intent" ]:
9074
91- def list_files_func3 (path : str , _intent : str ):
75+ def list_files (path : str , _intent : str ): # pyright: ignore[reportRedeclaration]
76+ """
77+ List files in the user's current directory. Always check again when asked.
78+
79+ Parameters
80+ ----------
81+ path
82+ The path to list files from.
83+ _intent
84+ Reason for the request to explain the tool call to the user.
85+ """
9286 time .sleep (random .uniform (1 , 3 ))
9387 return list_files_impl ()
9488
95- chat_client .register_tool (
96- list_files_func3 ,
97- name = "list_files" ,
98- model = ListFileParamsWithIntent ,
99- annotations = annotations ,
100- )
101-
10289 else :
10390
104- def list_files_func4 (path : str ):
91+ def list_files (path : str ): # pyright: ignore[reportRedeclaration]
92+ """
93+ List files in the user's current directory. Always check again when asked.
94+ """
10595 time .sleep (random .uniform (1 , 3 ))
10696 return list_files_impl ()
10797
108- chat_client .register_tool (
109- list_files_func4 ,
110- name = "list_files" ,
111- model = ListFileParams ,
112- annotations = annotations ,
113- )
98+
99+ chat_client .register_tool (
100+ list_files ,
101+ annotations = annotations ,
102+ )
114103
115104ui .page_opts (fillable = True )
116105
0 commit comments