Skip to content

Commit

Permalink
adapt to from_json from jiter
Browse files Browse the repository at this point in the history
  • Loading branch information
rgbkrk committed Sep 25, 2024
1 parent 042dec5 commit 88ab874
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 109 deletions.
17 changes: 10 additions & 7 deletions chatlab/views/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from IPython.display import display
from IPython.core.getipython import get_ipython

from instructor.dsl.partialjson import JSONParser
from jiter import from_json


class ToolArguments(AutoUpdate):
Expand Down Expand Up @@ -74,11 +74,11 @@ def update(self) -> None:

def render(self):
if self.custom_render is not None:
# We use the same definition as was in the original function
try:
parser = JSONParser()
possible_args = parser.parse(self.arguments)

possible_args = from_json(self.arguments.encode("utf-8"), partial_mode="trailing-strings")
except Exception:
return None
try:
Model = extract_model_from_function(self.name, self.custom_render)
# model = Model.model_validate(possible_args)
model = Model(**possible_args)
Expand Down Expand Up @@ -188,8 +188,11 @@ def render(self):
if self.custom_render is not None:
# We use the same definition as was in the original function
try:
parser = JSONParser()
possible_args = parser.parse(self.arguments)
possible_args = from_json(self.arguments.encode("utf-8"), partial_mode="trailing-strings")
except Exception:
return None

try:

Model = extract_model_from_function(self.name, self.custom_render)
# model = Model.model_validate(possible_args)
Expand Down
Loading

0 comments on commit 88ab874

Please sign in to comment.