mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-09 22:31:41 +00:00
refactor: extract duplicated stdout/stderr → logs logic to shared helper
This commit is contained in:
parent
cf8d1ac521
commit
4770b657e1
3 changed files with 22 additions and 28 deletions
|
|
@ -50,7 +50,7 @@ from litellm.types.llms.openai import (
|
|||
)
|
||||
from litellm.types.responses.main import (
|
||||
OutputCodeInterpreterCall,
|
||||
OutputCodeInterpreterCallLog,
|
||||
build_code_interpreter_log_outputs,
|
||||
)
|
||||
from litellm.types.utils import (
|
||||
Delta,
|
||||
|
|
@ -708,20 +708,9 @@ class ModelResponseIterator:
|
|||
continue
|
||||
call_id = tr.get("tool_use_id", "")
|
||||
content = tr.get("content", {})
|
||||
if isinstance(content, dict):
|
||||
parts = []
|
||||
if content.get("stdout"):
|
||||
parts.append(content["stdout"])
|
||||
if content.get("stderr"):
|
||||
parts.append(f"STDERR: {content['stderr']}")
|
||||
logs = "".join(parts)
|
||||
else:
|
||||
logs = ""
|
||||
log_outputs = build_code_interpreter_log_outputs(content)
|
||||
tool_input = self._server_tool_inputs.get(call_id, {})
|
||||
code = tool_input.get("command", "") if isinstance(tool_input, dict) else ""
|
||||
log_outputs = (
|
||||
[OutputCodeInterpreterCallLog(type="logs", logs=logs)] if logs else None
|
||||
)
|
||||
results.append(
|
||||
OutputCodeInterpreterCall(
|
||||
type="code_interpreter_call",
|
||||
|
|
|
|||
|
|
@ -61,7 +61,7 @@ from litellm.types.utils import (
|
|||
)
|
||||
from litellm.types.responses.main import (
|
||||
OutputCodeInterpreterCall,
|
||||
OutputCodeInterpreterCallLog,
|
||||
build_code_interpreter_log_outputs,
|
||||
)
|
||||
from litellm.utils import (
|
||||
ModelResponse,
|
||||
|
|
@ -1771,20 +1771,7 @@ class AnthropicConfig(AnthropicModelInfo, BaseConfig):
|
|||
continue
|
||||
call_id = tr.get("tool_use_id", "")
|
||||
content = tr.get("content", {})
|
||||
if isinstance(content, dict):
|
||||
parts = []
|
||||
if content.get("stdout"):
|
||||
parts.append(content["stdout"])
|
||||
if content.get("stderr"):
|
||||
parts.append(f"STDERR: {content['stderr']}")
|
||||
logs = "".join(parts)
|
||||
else:
|
||||
logs = ""
|
||||
log_outputs = (
|
||||
[OutputCodeInterpreterCallLog(type="logs", logs=logs)]
|
||||
if logs
|
||||
else None
|
||||
)
|
||||
log_outputs = build_code_interpreter_log_outputs(content)
|
||||
code_interpreter_results.append(
|
||||
OutputCodeInterpreterCall(
|
||||
type="code_interpreter_call",
|
||||
|
|
|
|||
|
|
@ -67,6 +67,24 @@ class OutputCodeInterpreterCall(BaseLiteLLMOpenAIResponseObject):
|
|||
outputs: Optional[List[OutputCodeInterpreterCallLog]]
|
||||
|
||||
|
||||
def build_code_interpreter_log_outputs(
|
||||
content: Any,
|
||||
) -> Optional[List[OutputCodeInterpreterCallLog]]:
|
||||
"""Convert Anthropic bash_code_execution stdout/stderr to log outputs.
|
||||
|
||||
Shared by streaming (handler.py) and non-streaming (transformation.py) paths.
|
||||
"""
|
||||
if not isinstance(content, dict):
|
||||
return None
|
||||
parts = []
|
||||
if content.get("stdout"):
|
||||
parts.append(content["stdout"])
|
||||
if content.get("stderr"):
|
||||
parts.append(f"STDERR: {content['stderr']}")
|
||||
logs = "".join(parts)
|
||||
return [OutputCodeInterpreterCallLog(type="logs", logs=logs)] if logs else None
|
||||
|
||||
|
||||
class GenericResponseOutputItem(BaseLiteLLMOpenAIResponseObject):
|
||||
"""
|
||||
Generic response API output item
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue