Skip to content

Commit 5223fa6

Browse files
committed
move litellm_utils => litellm_lib
1 parent 1311989 commit 5223fa6

File tree

7 files changed

+21
-32
lines changed

7 files changed

+21
-32
lines changed
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
from .toolcall_list import *
2-
from .streaming_utils import *
31
from .run_tools import *
2+
from .toolcall_list import *
3+
from .types import *

packages/jupyter-ai/jupyter_ai/litellm_utils/run_tools.py renamed to packages/jupyter-ai/jupyter_ai/litellm_lib/run_tools.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,8 @@
11
import asyncio
2-
from pydantic import BaseModel
32
from .toolcall_list import ToolCallList
43
from ..tools import Toolkit
54

65

7-
class ToolCallOutput(BaseModel):
8-
tool_call_id: str
9-
role: str = "tool"
10-
name: str
11-
content: str
12-
13-
146
async def run_tools(tool_call_list: ToolCallList, toolkit: Toolkit) -> list[dict]:
157
"""
168
Runs the tools specified in the list of tool calls returned by
File renamed without changes.

packages/jupyter-ai/jupyter_ai/litellm_utils/toolcall_list.py renamed to packages/jupyter-ai/jupyter_ai/litellm_lib/toolcall_list.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,9 @@ class ResolvedToolCall(BaseModel):
2929
`litellm.utils.ChatCompletionDeltaToolCall`.
3030
"""
3131

32-
id: str | None
32+
id: str
3333
"""
34-
The ID of the tool call. This should always be provided by LiteLLM, this
35-
type is left optional as we do not use this attribute.
34+
The ID of the tool call.
3635
"""
3736

3837
type: str
@@ -62,7 +61,7 @@ class ToolCallList(BaseModel):
6261
is used to aggregate the tool call deltas yielded from a LiteLLM response
6362
stream and produce a list of tool calls.
6463
65-
After all tool call deltas are added, the `process()` method may be called
64+
After all tool call deltas are added, the `resolve()` method may be called
6665
to return a list of resolved tool calls.
6766
6867
Example usage:
@@ -75,7 +74,7 @@ class ToolCallList(BaseModel):
7574
tool_call_delta = chunk.choices[0].delta.tool_calls
7675
tool_call_list += tool_call_delta
7776
78-
tool_call_list.resolve()
77+
tool_calls = tool_call_list.resolve()
7978
```
8079
"""
8180

@@ -128,7 +127,11 @@ def __add__(self, other: list[ChatCompletionDeltaToolCall] | None) -> 'ToolCallL
128127

129128
def resolve(self) -> list[ResolvedToolCall]:
130129
"""
131-
Resolve the aggregated tool call delta lists into a list of tool calls.
130+
Returns the aggregated tool calls as `list[ResolvedToolCall]`.
131+
132+
Raises an exception if any function arguments could not be parsed from
133+
JSON into a dictionary. This method should only be called after the
134+
stream completed without errors.
132135
"""
133136
resolved_toolcalls: list[ResolvedToolCall] = []
134137
for i, raw_toolcall in enumerate(self._aggregate):

packages/jupyter-ai/jupyter_ai/litellm_utils/streaming_utils.py renamed to packages/jupyter-ai/jupyter_ai/litellm_lib/types.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from __future__ import annotations
12
from pydantic import BaseModel
23
from .toolcall_list import ToolCallList
34

@@ -11,3 +12,10 @@ class StreamResult(BaseModel):
1112
"""
1213
Tool calls requested by the LLM in its streamed response.
1314
"""
15+
16+
class ToolCallOutput(BaseModel):
17+
tool_call_id: str
18+
role: str = "tool"
19+
name: str
20+
content: str
21+

packages/jupyter-ai/jupyter_ai/personas/base_persona.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,12 @@
1717
from traitlets.config import LoggingConfigurable
1818

1919
from .persona_awareness import PersonaAwareness
20-
from ..litellm_utils import ToolCallList, StreamResult, run_tools, ToolCallOutput
21-
22-
# Import toolkits
20+
from ..litellm_lib import ToolCallList, StreamResult, run_tools
2321
from ..tools.default_toolkit import DEFAULT_TOOLKIT
2422

2523
if TYPE_CHECKING:
2624
from collections.abc import AsyncIterator
2725
from .persona_manager import PersonaManager
28-
from ..tools import Toolkit
2926

3027
class PersonaDefaults(BaseModel):
3128
"""

packages/jupyter-ai/jupyter_ai/personas/jupyternaut/jupyternaut.py

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
from typing import Any, Optional
22
import time
3-
import json
43

54
from jupyterlab_chat.models import Message
65
from litellm import acompletion
76

8-
from ...litellm_utils import StreamResult, ToolCallOutput
7+
from ...litellm_lib import StreamResult, ToolCallOutput
98
from ..base_persona import BasePersona, PersonaDefaults
109
from ..persona_manager import SYSTEM_USERNAME
1110
from .prompt_template import (
@@ -110,15 +109,6 @@ def render_tool_calls(self, stream_result: StreamResult):
110109

111110

112111
def render_tool_call_outputs(self, message_id: str, tool_call_outputs: list[dict]):
113-
# TODO
114-
# self.ychat.update_message(Message(
115-
# id=message_id,
116-
# body=f"\n\n```\n{json.dumps(tool_call_outputs, indent=2)}\n```\n",
117-
# sender=self.id,
118-
# time=time.time(),
119-
# raw_time=False
120-
# ), append=True)
121-
122112
# Updates the content of the last message directly
123113
message = self.ychat.get_message(message_id)
124114
body = message.body
@@ -134,7 +124,6 @@ def render_tool_call_outputs(self, message_id: str, tool_call_outputs: list[dict
134124
f'<jai-tool-call id="{tool_id}" output="{tool_output}"',
135125
)
136126

137-
self.log.error(body)
138127
self.ychat.update_message(Message(
139128
id=message.id,
140129
time=time.time(),

0 commit comments

Comments
 (0)