use anthropic beta client (#2235)

This commit is contained in:
Shuchang Zheng
2025-04-28 16:24:12 +08:00
committed by GitHub
parent 2f0e6e5eb3
commit a8d237deee
3 changed files with 20 additions and 8 deletions

View File

@@ -1433,7 +1433,6 @@ class ForgeAgent:
raw_response=True, raw_response=True,
betas=["computer-use-2025-01-24"], betas=["computer-use-2025-01-24"],
) )
LOG.info("Anthropic response", llm_response=llm_response)
assistant_content = llm_response["content"] assistant_content = llm_response["content"]
llm_caller.message_history.append({"role": "assistant", "content": assistant_content}) llm_caller.message_history.append({"role": "assistant", "content": assistant_content})

View File

@@ -6,7 +6,7 @@ from typing import Any
import litellm import litellm
import structlog import structlog
from anthropic.types.message import Message as AnthropicMessage from anthropic.types.beta.beta_message import BetaMessage as AnthropicMessage
from jinja2 import Template from jinja2 import Template
from litellm.utils import CustomStreamWrapper, ModelResponse from litellm.utils import CustomStreamWrapper, ModelResponse
@@ -678,7 +678,7 @@ class LLMCaller:
) -> AnthropicMessage: ) -> AnthropicMessage:
max_tokens = active_parameters.get("max_completion_tokens") or active_parameters.get("max_tokens") or 4096 max_tokens = active_parameters.get("max_completion_tokens") or active_parameters.get("max_tokens") or 4096
model_name = self.llm_config.model_name.replace("bedrock/", "").replace("anthropic/", "") model_name = self.llm_config.model_name.replace("bedrock/", "").replace("anthropic/", "")
return await app.ANTHROPIC_CLIENT.messages.create( response = await app.ANTHROPIC_CLIENT.beta.messages.create(
max_tokens=max_tokens, max_tokens=max_tokens,
messages=messages, messages=messages,
model=model_name, model=model_name,
@@ -686,6 +686,8 @@ class LLMCaller:
timeout=timeout, timeout=timeout,
betas=active_parameters.get("betas", None), betas=active_parameters.get("betas", None),
) )
LOG.info("Anthropic response", response=response)
return response
class LLMCallerManager: class LLMCallerManager:

View File

@@ -482,7 +482,6 @@ async def parse_anthropic_actions(
tool_call_id=tool_call_id, tool_call_id=tool_call_id,
) )
) )
idx += 1
elif action == "left_click": elif action == "left_click":
if idx - 1 >= 0: if idx - 1 >= 0:
prev_tool_call = tool_calls[idx - 1] prev_tool_call = tool_calls[idx - 1]
@@ -494,12 +493,12 @@ async def parse_anthropic_actions(
else: else:
coordinate = parsed_args.get("coordinate") coordinate = parsed_args.get("coordinate")
idx += 1
if not coordinate: if not coordinate:
LOG.warning( LOG.warning(
"Left click action has no coordinate and it doesn't have mouse_move before it", "Left click action has no coordinate and it doesn't have mouse_move before it",
tool_call=tool_call, tool_call=tool_call,
) )
idx += 1
continue continue
x, y = coordinate x, y = coordinate
actions.append( actions.append(
@@ -519,12 +518,12 @@ async def parse_anthropic_actions(
) )
elif action == "type": elif action == "type":
text = parsed_args.get("text") text = parsed_args.get("text")
idx += 1
if not text: if not text:
LOG.warning( LOG.warning(
"Type action has no text", "Type action has no text",
tool_call=tool_call, tool_call=tool_call,
) )
idx += 1
continue continue
actions.append( actions.append(
InputTextAction( InputTextAction(
@@ -541,12 +540,12 @@ async def parse_anthropic_actions(
) )
elif action == "key": elif action == "key":
text = parsed_args.get("text") text = parsed_args.get("text")
idx += 1
if not text: if not text:
LOG.warning( LOG.warning(
"Key action has no text", "Key action has no text",
tool_call=tool_call, tool_call=tool_call,
) )
idx += 1
continue continue
actions.append( actions.append(
KeypressAction( KeypressAction(
@@ -561,12 +560,24 @@ async def parse_anthropic_actions(
tool_call_id=tool_call_id, tool_call_id=tool_call_id,
) )
) )
elif action == "screenshot":
actions.append(
NullAction(
organization_id=task.organization_id,
workflow_run_id=task.workflow_run_id,
task_id=task.task_id,
step_id=step.step_id,
step_order=step.order,
action_order=idx,
tool_call_id=tool_call_id,
)
)
else: else:
LOG.error( LOG.error(
"Unsupported action", "Unsupported action",
tool_call=tool_call, tool_call=tool_call,
) )
idx += 1 idx += 1
return actions return actions