Skip to content

Commit

Permalink
Merge pull request #63 from jlowin/litellm
Browse files Browse the repository at this point in the history
Add tools and streamhandlers
  • Loading branch information
jlowin authored May 21, 2024
2 parents 32dca0b + 4ece779 commit a7e9dd2
Show file tree
Hide file tree
Showing 15 changed files with 669 additions and 204 deletions.
5 changes: 5 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,8 @@ skip-magic-trailing-comma = false

[tool.pytest.ini_options]
timeout = 120
asyncio_mode = "auto"
filterwarnings = [
"ignore::DeprecationWarning:litellm.*",
"ignore::PendingDeprecationWarning:litellm.*",
]
4 changes: 4 additions & 0 deletions src/controlflow/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
from .settings import settings
import controlflow.llm

default_history = controlflow.llm.history.InMemoryHistory()

from .core.flow import Flow
from .core.task import Task
from .core.agent import Agent
from .core.controller.controller import Controller

from .instructions import instructions
from .decorators import flow, task
4 changes: 2 additions & 2 deletions src/controlflow/core/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class LiteAgent(ControlFlowModel, ExposeSyncMethodsMixin):
description="The model used by the agent. If not provided, the default model will be used.",
)

async def say_async(self, messages: Union[str, dict]) -> Response:
async def run_async(self, messages: Union[str, dict]) -> Response:
if not isinstance(messages, list):
raise ValueError("Messages must be provided as a list.")

Expand All @@ -102,7 +102,7 @@ async def say_async(self, messages: Union[str, dict]) -> Response:
messages=messages, model=self.model, tools=self.tools
)

async def say(self, messages: Union[str, dict]) -> Response:
async def run(self, messages: Union[str, dict]) -> Response:
if not isinstance(messages, list):
raise ValueError("Messages must be provided as a list.")

Expand Down
15 changes: 5 additions & 10 deletions src/controlflow/core/controller/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
from controlflow.core.graph import Graph
from controlflow.core.task import Task
from controlflow.instructions import get_instructions
from controlflow.llm.history import BaseHistory
from controlflow.tui.app import TUIApp as TUI
from controlflow.utilities.context import ctx
from controlflow.utilities.prefect import (
Expand All @@ -34,7 +35,7 @@
wrap_prefect_tool,
)
from controlflow.utilities.tasks import all_complete, any_incomplete
from controlflow.utilities.types import FunctionTool, Thread
from controlflow.utilities.types import FunctionTool

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -67,6 +68,7 @@ class Controller(BaseModel, ExposeSyncMethodsMixin):
description="Tasks that the controller will complete.",
)
agents: Union[list[Agent], None] = None
history: BaseHistory = Field()
context: dict = {}
model_config: dict = dict(extra="forbid")
enable_tui: bool = Field(default_factory=lambda: controlflow.settings.enable_tui)
Expand Down Expand Up @@ -101,20 +103,13 @@ def help_im_stuck():

return help_im_stuck

async def _run_agent(
self, agent: Agent, tasks: list[Task] = None, thread: Thread = None
) -> Run:
async def _run_agent(self, agent: Agent, tasks: list[Task] = None) -> Run:
"""
Run a single agent.
"""

@prefect_task(task_run_name=f'Run Agent: "{agent.name}"')
async def _run_agent(
controller: Controller,
agent: Agent,
tasks: list[Task],
thread: Thread = None,
):
async def _run_agent(controller: Controller, agent: Agent, tasks: list[Task]):
from controlflow.core.controller.instruction_template import MainTemplate

tasks = tasks or controller.tasks
Expand Down
3 changes: 3 additions & 0 deletions src/controlflow/llm/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import controlflow.llm.history
import controlflow.llm.tools
import controlflow.llm.completions
Loading

0 comments on commit a7e9dd2

Please sign in to comment.