|
15 | 15 | from IPython.display import display
|
16 | 16 | from IPython.core.getipython import get_ipython
|
17 | 17 |
|
18 |
| -from instructor.dsl.partialjson import JSONParser |
19 |
| - |
| 18 | +from jiter import from_json |
20 | 19 |
|
21 | 20 |
|
22 | 21 | class ToolArguments(AutoUpdate):
|
@@ -75,11 +74,11 @@ def update(self) -> None:
|
75 | 74 |
|
76 | 75 | def render(self):
|
77 | 76 | if self.custom_render is not None:
|
78 |
| - # We use the same definition as was in the original function |
79 | 77 | try:
|
80 |
| - parser = JSONParser() |
81 |
| - possible_args = parser.parse(self.arguments) |
82 |
| - |
| 78 | + possible_args = from_json(self.arguments.encode("utf-8"), partial_mode="trailing-strings") |
| 79 | + except Exception: |
| 80 | + return None |
| 81 | + try: |
83 | 82 | Model = extract_model_from_function(self.name, self.custom_render)
|
84 | 83 | # model = Model.model_validate(possible_args)
|
85 | 84 | model = Model(**possible_args)
|
@@ -110,13 +109,17 @@ def append_arguments(self, arguments: str):
|
110 | 109 | def apply_result(self, result: str):
|
111 | 110 | """Replaces the existing display with a new one that shows the result of the tool being called."""
|
112 | 111 | tc = ToolCalled(
|
113 |
| - id=self.id, name=self.name, arguments=self.arguments, result=result, display_id=self.display_id, |
114 |
| - custom_render=self.custom_render |
| 112 | + id=self.id, |
| 113 | + name=self.name, |
| 114 | + arguments=self.arguments, |
| 115 | + result=result, |
| 116 | + display_id=self.display_id, |
| 117 | + custom_render=self.custom_render, |
115 | 118 | )
|
116 | 119 | tc.update()
|
117 | 120 | return tc
|
118 | 121 |
|
119 |
| - async def call(self, function_registry: FunctionRegistry) -> 'ToolCalled': |
| 122 | + async def call(self, function_registry: FunctionRegistry) -> "ToolCalled": |
120 | 123 | """Call the function and return a stack of messages for LLM and human consumption."""
|
121 | 124 | function_name = self.name
|
122 | 125 | function_args = self.arguments
|
@@ -185,9 +188,11 @@ def render(self):
|
185 | 188 | if self.custom_render is not None:
|
186 | 189 | # We use the same definition as was in the original function
|
187 | 190 | try:
|
188 |
| - parser = JSONParser() |
189 |
| - possible_args = parser.parse(self.arguments) |
| 191 | + possible_args = from_json(self.arguments.encode("utf-8"), partial_mode="trailing-strings") |
| 192 | + except Exception: |
| 193 | + return None |
190 | 194 |
|
| 195 | + try: |
191 | 196 | Model = extract_model_from_function(self.name, self.custom_render)
|
192 | 197 | # model = Model.model_validate(possible_args)
|
193 | 198 | model = Model(**possible_args)
|
|
0 commit comments