Skip to content

Commit c272e41

Browse files
authored
Merge branch 'master' into ROB-858-holmes-telemetry
2 parents b82f06f + bed9d1f commit c272e41

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

holmes/core/llm.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import sentry_sdk
77

88
from litellm.litellm_core_utils.streaming_handler import CustomStreamWrapper
9-
from holmes.core.tools import Tool
109
from pydantic import BaseModel
1110
import litellm
1211
import os
@@ -45,13 +44,13 @@ def count_tokens_for_message(self, messages: list[dict]) -> int:
4544
def completion(
4645
self,
4746
messages: List[Dict[str, Any]],
48-
tools: Optional[List[Tool]] = [],
47+
tools: Optional[List[Dict[str, Any]]] = [],
4948
tool_choice: Optional[Union[str, dict]] = None,
5049
response_format: Optional[Union[dict, Type[BaseModel]]] = None,
5150
temperature: Optional[float] = None,
5251
drop_params: Optional[bool] = None,
5352
stream: Optional[bool] = None,
54-
) -> ModelResponse:
53+
) -> Union[ModelResponse, CustomStreamWrapper]:
5554
pass
5655

5756

@@ -167,24 +166,28 @@ def count_tokens_for_message(self, messages: list[dict]) -> int:
167166
def completion(
168167
self,
169168
messages: List[Dict[str, Any]],
170-
tools: Optional[List[Tool]] = [],
169+
tools: Optional[List[Dict[str, Any]]] = None,
171170
tool_choice: Optional[Union[str, dict]] = None,
172171
response_format: Optional[Union[dict, Type[BaseModel]]] = None,
173172
temperature: Optional[float] = None,
174173
drop_params: Optional[bool] = None,
175174
stream: Optional[bool] = None,
176-
) -> ModelResponse:
175+
) -> Union[ModelResponse, CustomStreamWrapper]:
176+
tools_args = {}
177+
if tools and tool_choice:
178+
tools_args["tools"] = tools
179+
tools_args["tool_choice"] = tool_choice
180+
177181
result = litellm.completion(
178182
model=self.model,
179183
api_key=self.api_key,
180184
messages=messages,
181-
tools=tools,
182-
tool_choice=tool_choice,
183185
base_url=self.base_url,
184186
temperature=temperature,
185187
response_format=response_format,
186188
drop_params=drop_params,
187189
stream=stream,
190+
**tools_args,
188191
)
189192

190193
if isinstance(result, ModelResponse):

holmes/core/tool_calling_llm.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
from holmes.plugins.prompts import load_and_render_prompt
2020
from holmes.core.llm import LLM
2121
from openai import BadRequestError
22-
from openai._types import NOT_GIVEN
2322
from openai.types.chat.chat_completion_message_tool_call import (
2423
ChatCompletionMessageToolCall,
2524
)
@@ -136,8 +135,8 @@ def call(
136135
perf_timing.measure(f"start iteration {i}")
137136
logging.debug(f"running iteration {i}")
138137
# on the last step we don't allow tools - we want to force a reply, not a request to run another tool
139-
tools = NOT_GIVEN if i == max_steps - 1 else tools
140-
tool_choice = None if tools == NOT_GIVEN else "auto"
138+
tools = None if i == max_steps else tools
139+
tool_choice = "auto" if tools else None
141140

142141
total_tokens = self.llm.count_tokens_for_message(messages)
143142
max_context_size = self.llm.get_context_window_size()

0 commit comments

Comments
 (0)