Skip to content

Commit

Permalink
fix(agents-api): exec_system + chat bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Vedantsahai18 committed Nov 22, 2024
1 parent d0f074a commit bea2681
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 22 deletions.
3 changes: 0 additions & 3 deletions agents-api/agents_api/activities/execute_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,9 @@ async def execute_system(
if system.operation == "create" and system.subresource == "doc":
arguments["x_developer_id"] = arguments.pop("developer_id")
bg_runner = BackgroundTasks()
res = await handler(
bg_runner = BackgroundTasks()
res = await handler(
data=CreateDocRequest(**arguments.pop("data")),
background_tasks=bg_runner,
background_tasks=bg_runner,
**arguments,
)
await bg_runner()
Expand Down
31 changes: 12 additions & 19 deletions agents-api/agents_api/routers/sessions/chat.py
Original file line number Diff line number Diff line change
@@ -1,31 +1,24 @@
import json
from datetime import datetime
from typing import Annotated, Callable, Optional
from uuid import UUID, uuid4

from anthropic import AsyncAnthropic
from anthropic.types.beta.beta_message import BetaMessage
from fastapi import BackgroundTasks, Depends, Header
from litellm import ChatCompletionMessageToolCall, Function, Message
from litellm.types.utils import Choices, ModelResponse
from starlette.status import HTTP_201_CREATED

from ...activities.task_steps.prompt_step import format_tool
from ...autogen.openapi_model import (
ChatInput,
ChatResponse,
ChunkChatResponse,
CreateEntryRequest,
MessageChatResponse,
)
from ...autogen.Tools import Tool
from ...clients import litellm
from ...common.protocol.developers import Developer
from ...common.protocol.sessions import ChatContext
from ...common.utils.datetime import utcnow
from ...common.utils.template import render_template
from ...dependencies.developer_id import get_developer_data
from ...env import anthropic_api_key
from ...models.chat.gather_messages import gather_messages
from ...models.chat.prepare_chat_context import prepare_chat_context
from ...models.entry.create_entries import create_entries
Expand Down Expand Up @@ -122,9 +115,9 @@ async def chat(
is_claude_model = settings["model"].lower().startswith("claude-3.5")

# Format tools for litellm
formatted_tools = (
tools if is_claude_model else [format_tool(tool) for tool in tools]
)
# formatted_tools = (
# tools if is_claude_model else [format_tool(tool) for tool in tools]
# )

# FIXME: Truncate chat messages in the chat context
# SCRUM-7
Expand All @@ -142,17 +135,13 @@ async def chat(
for m in messages
]

# has_special_tools = any(
# tool["type"] in ["computer_20241022", "bash_20241022", "text_editor_20241022"]
# for tool in formatted_tools
# )

# FIXME: Hack to make the computer use tools compatible with litellm
# Issue was: litellm expects type to be `computer_20241022` and spec to be
# `function` (see: https://docs.litellm.ai/docs/providers/anthropic#computer-tools)
# but we don't allow that (spec should match type).
for i, tool in enumerate(formatted_tools):
if tool.type == "computer_20241022":
formatted_tools = []
for i, tool in enumerate(tools):
if tool.type == "computer_20241022" and tool.computer_20241022:
function = tool.computer_20241022
tool = {
"type": tool.type,
Expand All @@ -165,9 +154,13 @@ async def chat(
},
},
}
formatted_tools[i] = tool
formatted_tools.append(tool)

# If not using Claude model,

if not is_claude_model:
formatted_tools = None

# formatted_tools = None
# Use litellm for other models
model_response = await litellm.acompletion(
messages=messages,
Expand Down

0 comments on commit bea2681

Please sign in to comment.