Skip to content

Commit

Permalink
Proper Kuzu initialization + some refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
whimo committed May 15, 2024
1 parent 3de8160 commit 5100c7a
Show file tree
Hide file tree
Showing 46 changed files with 138 additions and 136 deletions.
5 changes: 2 additions & 3 deletions examples/blog_post/blog_post.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@

from dotenv import load_dotenv

from llama_index.graph_stores.kuzu import KuzuGraphStore
from langchain.schema import AIMessage, HumanMessage, SystemMessage, BaseMessage
from langchain_core.prompts.chat import ChatPromptTemplate
from motleycrew.agent.langchain.react import ReactMotleyAgent
from motleycrew.agents.langchain.react import ReactMotleyAgent

from motleycrew.tool.llm_tool import LLMTool
from motleycrew.tools.llm_tool import LLMTool
from motleycrew import MotleyCrew, TaskRecipe

from .blog_post_input import text
Expand Down
6 changes: 2 additions & 4 deletions examples/delegation_crewai.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from langchain_community.tools import DuckDuckGoSearchRun

from motleycrew import MotleyCrew
from motleycrew.agent.crewai import CrewAIMotleyAgent
from motleycrew.agents.crewai import CrewAIMotleyAgent
from motleycrew.common.utils import configure_logging


Expand Down Expand Up @@ -61,9 +61,7 @@ def main():
[analysis_report_task, literature_summary_task] >> blog_post_task

# Get your crew to work!
result = crew.run(
verbose=2, # You can set it to 1 or 2 to different logging levels
)
result = crew.run()

# Get the outputs of the task
print(blog_post_task.output)
Expand Down
8 changes: 3 additions & 5 deletions examples/image_generation_crewai.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from dotenv import load_dotenv

from motleycrew import MotleyCrew, TaskRecipe
from motleycrew.agent.crewai import CrewAIMotleyAgent
from motleycrew.tool.image_generation import DallEImageGeneratorTool
from motleycrew.agents.crewai import CrewAIMotleyAgent
from motleycrew.tools.image_generation import DallEImageGeneratorTool
from motleycrew.common.utils import configure_logging


Expand Down Expand Up @@ -47,9 +47,7 @@ def main():
)

# Get your crew to work!
crew.run(
verbose=2, # You can set it to 1 or 2 to different logging levels
)
crew.run()

print(write_task.output)
return write_task.output
Expand Down
8 changes: 3 additions & 5 deletions examples/math_crewai.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from dotenv import load_dotenv

from motleycrew import MotleyCrew, TaskRecipe
from motleycrew.agent.crewai import CrewAIMotleyAgent
from motleycrew.tool.python_repl import create_repl_tool
from motleycrew.agents.crewai import CrewAIMotleyAgent
from motleycrew.tools.python_repl import create_repl_tool
from motleycrew.common.utils import configure_logging


Expand Down Expand Up @@ -45,9 +45,7 @@ def main():
)

# Get your crew to work!
crew.run(
verbose=2, # You can set it to 1 or 2 to different logging levels
)
crew.run()

print(task.output)
return task.output
Expand Down
2 changes: 1 addition & 1 deletion examples/research_agent/retriever_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
load_index_from_storage,
)

from motleycrew.tool import MotleyTool
from motleycrew.tools import MotleyTool
from motleycrew.applications.research_agent.question import Question


Expand Down
6 changes: 2 additions & 4 deletions examples/single_crewai.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from langchain_community.tools import DuckDuckGoSearchRun

from motleycrew import MotleyCrew
from motleycrew.agent.crewai import CrewAIMotleyAgent
from motleycrew.agents.crewai import CrewAIMotleyAgent
from motleycrew.common.utils import configure_logging


Expand Down Expand Up @@ -34,9 +34,7 @@ def main():
)

# Get your crew to work!
result = crew.run(
verbose=2, # You can set it to 1 or 2 to different logging levels
)
result = crew.run()

print(task.output)
return task.output
Expand Down
6 changes: 2 additions & 4 deletions examples/single_llama_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@


from motleycrew import MotleyCrew
from motleycrew.agent.llama_index import ReActLlamaIndexMotleyAgent
from motleycrew.agents.llama_index import ReActLlamaIndexMotleyAgent
from motleycrew.common.utils import configure_logging


Expand All @@ -30,9 +30,7 @@ def main():
)

# Get your crew to work!
crew.run(
verbose=2, # You can set it to 1 or 2 to different logging levels
)
crew.run()

print(task.output)
return task.output
Expand Down
8 changes: 3 additions & 5 deletions examples/single_openai_tools_react.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
from langchain_community.tools import DuckDuckGoSearchRun

from motleycrew import MotleyCrew
from motleycrew.agent.langchain.openai_tools_react import ReactOpenAIToolsAgent
from motleycrew.agent.langchain.react import ReactMotleyAgent
from motleycrew.agents.langchain.openai_tools_react import ReactOpenAIToolsAgent
from motleycrew.agents.langchain.react import ReactMotleyAgent
from motleycrew.common.utils import configure_logging
from motleycrew.caching import enable_cache

Expand All @@ -27,9 +27,7 @@ def main():
Your final answer MUST be a full analysis report""",
agent=r,
)
result = crew.run(
verbose=2, # You can set it to 1 or 2 to different logging levels
)
result = crew.run()

# Get your crew to work!
print(task.output)
Expand Down
1 change: 0 additions & 1 deletion motleycrew/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
from .crew import MotleyCrew
from .tasks import TaskRecipe
from .tool import MotleyTool
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
from abc import ABC, abstractmethod
from typing import TYPE_CHECKING, Optional, Any, Union
from typing import Optional, Any, TYPE_CHECKING

from langchain_core.runnables import RunnableConfig

if TYPE_CHECKING:
from motleycrew.tasks import TaskRecipe
from motleycrew.tool import MotleyTool
from motleycrew.tools import MotleyTool


class MotleyAgentAbstractParent(ABC):
@abstractmethod
def invoke(
self,
task: Union["SimpleTaskRecipe", str],
task_dict: dict,
config: Optional[RunnableConfig] = None,
**kwargs: Any,
) -> "SimpleTaskRecipe":
) -> Any:
pass

@abstractmethod
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

from langchain_core.runnables import RunnableConfig

from motleycrew.agent.parent import MotleyAgentAbstractParent
from motleycrew.agent.shared import MotleyAgentParent
from motleycrew.agent.crewai import CrewAIAgentWithConfig
from motleycrew.agents.parent import MotleyAgentParent
from motleycrew.agents.abstract_parent import MotleyAgentAbstractParent
from motleycrew.agents.crewai import CrewAIAgentWithConfig
from motleycrew.common import MotleySupportedTool
from motleycrew.common import MotleyAgentFactory
from motleycrew.common.utils import to_str
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from typing import Optional, Any, Sequence

from motleycrew.tool import MotleyTool
from motleycrew.tools import MotleyTool
from motleycrew.common import MotleySupportedTool
from motleycrew.common import LLMFramework
from motleycrew.common.llms import init_llm
from motleycrew.agent.parent import MotleyAgentAbstractParent
from motleycrew.agent.crewai import CrewAIMotleyAgentParent
from motleycrew.agent.crewai import CrewAIAgentWithConfig
from motleycrew.agents.abstract_parent import MotleyAgentAbstractParent
from motleycrew.agents.crewai import CrewAIMotleyAgentParent
from motleycrew.agents.crewai import CrewAIAgentWithConfig


class CrewAIMotleyAgent(CrewAIMotleyAgentParent):
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@
from langchain_core.language_models import BaseLanguageModel
from langchain_core.prompts.chat import ChatPromptTemplate

from motleycrew.agent.parent import MotleyAgentAbstractParent
from motleycrew.agent.shared import MotleyAgentParent
from motleycrew.tasks import Task
from motleycrew.agents.parent import MotleyAgentParent
from motleycrew.agents.abstract_parent import MotleyAgentAbstractParent

from motleycrew.tool import MotleyTool
from motleycrew.tools import MotleyTool
from motleycrew.tracking import add_default_callbacks_to_langchain_config
from motleycrew.common import MotleySupportedTool
from motleycrew.common import MotleyAgentFactory
Expand Down Expand Up @@ -41,7 +40,7 @@ def invoke(
task_dict: dict,
config: Optional[RunnableConfig] = None,
**kwargs: Any,
) -> Task:
) -> Any:
self.materialize()

prompt = task_dict.get("prompt")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
)
from langchain.agents.output_parsers.openai_tools import OpenAIToolsAgentOutputParser

from motleycrew.agent.parent import MotleyAgentAbstractParent
from motleycrew.agent.langchain.langchain import LangchainMotleyAgentParent
from motleycrew.agents.abstract_parent import MotleyAgentAbstractParent
from motleycrew.agents.langchain.langchain import LangchainMotleyAgentParent
from motleycrew.common import MotleySupportedTool
from motleycrew.common.utils import print_passthrough

Expand Down Expand Up @@ -178,9 +178,7 @@ def create_openai_tools_react_agent(
agent = (
RunnableLambda(print_passthrough)
| RunnablePassthrough.assign(
agent_scratchpad=lambda x: format_to_openai_tool_messages(
x["intermediate_steps"]
)
agent_scratchpad=lambda x: format_to_openai_tool_messages(x["intermediate_steps"])
)
| {"thought": think_prompt | llm, "background": RunnablePassthrough()}
| RunnableLambda(print_passthrough)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
from langchain_core.language_models import BaseLanguageModel
from langchain.agents import create_react_agent

from motleycrew.agent.parent import MotleyAgentAbstractParent
from motleycrew.agent.langchain.langchain import LangchainMotleyAgentParent
from motleycrew.agents.abstract_parent import MotleyAgentAbstractParent
from motleycrew.agents.langchain.langchain import LangchainMotleyAgentParent
from motleycrew.common import MotleySupportedTool


Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
from llama_index.core.agent import AgentRunner
from langchain_core.runnables import RunnableConfig

from motleycrew.agent.parent import MotleyAgentAbstractParent
from motleycrew.agent.shared import MotleyAgentParent
from motleycrew.agents.parent import MotleyAgentParent
from motleycrew.agents.abstract_parent import MotleyAgentAbstractParent
from motleycrew.tasks import Task
from motleycrew.common import MotleySupportedTool
from motleycrew.common import MotleyAgentFactory
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
from llama_index.core.llms import LLM
from llama_index.core.callbacks import CallbackManager

from motleycrew.agent.llama_index import LlamaIndexMotleyAgentParent
from motleycrew.agent.parent import MotleyAgentAbstractParent
from motleycrew.tool import MotleyTool
from motleycrew.agents.llama_index import LlamaIndexMotleyAgentParent
from motleycrew.agents.abstract_parent import MotleyAgentAbstractParent
from motleycrew.tools import MotleyTool
from motleycrew.common import MotleySupportedTool
from motleycrew.common import LLMFramework
from motleycrew.common.llms import init_llm
Expand Down
15 changes: 6 additions & 9 deletions motleycrew/agent/shared.py → motleycrew/agents/parent.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,15 @@
from typing import TYPE_CHECKING, Optional, Sequence

from langchain_core.tools import Tool
from langchain_core.pydantic_v1 import BaseModel
from pydantic import BaseModel

from motleycrew.agent.parent import MotleyAgentAbstractParent
from motleycrew.tool import MotleyTool

from motleycrew.common import MotleySupportedTool
from motleycrew.common import MotleyAgentFactory
from motleycrew.common.exceptions import AgentNotMaterialized
from motleycrew.common.exceptions import CannotModifyMaterializedAgent
from motleycrew.agents.abstract_parent import MotleyAgentAbstractParent
from motleycrew.tools import MotleyTool
from motleycrew.common import MotleyAgentFactory, MotleySupportedTool
from motleycrew.common.exceptions import AgentNotMaterialized, CannotModifyMaterializedAgent

if TYPE_CHECKING:
from motleycrew.crew import MotleyCrew
from motleycrew import MotleyCrew


class MotleyAgentParent(MotleyAgentAbstractParent):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from langchain_core.runnables import Runnable

from motleycrew.crew import MotleyCrew
from motleycrew.tool import MotleyTool
from motleycrew.tools import MotleyTool
from motleycrew.tasks import TaskRecipe
from motleycrew.tasks.task import TaskType
from motleycrew.tasks import Task
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
chain,
)

from motleycrew.tool import MotleyTool, LLMTool
from motleycrew.tools import MotleyTool, LLMTool
from motleycrew.storage import MotleyGraphStore
from motleycrew.common.utils import print_passthrough

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

from langchain_core.pydantic_v1 import BaseModel, Field

from motleycrew.tool import MotleyTool
from motleycrew.tools import MotleyTool
from motleycrew.common import LLMFramework
from motleycrew.common.llms import init_llm
from motleycrew.common.utils import print_passthrough
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
chain,
)

from motleycrew.tool import MotleyTool
from motleycrew.tool import LLMTool
from motleycrew.tools import MotleyTool
from motleycrew.tools import LLMTool
from motleycrew.common.utils import print_passthrough

from motleycrew.applications.research_agent.question import Question
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from motleycrew.tasks import TaskRecipe
from ...tasks.task import TaskType
from motleycrew.tool import MotleyTool
from motleycrew.tools import MotleyTool
from motleycrew.crew import MotleyCrew
from .question import Question, QuestionGenerationTask
from .question_generator import QuestionGeneratorTool
Expand Down
1 change: 1 addition & 0 deletions motleycrew/common/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from .enums import LLMFamily
from .enums import LLMFramework
from .enums import GraphStoreType
from .enums import TaskStatus
from .enums import LunaryRunType
from .enums import LunaryEventName
Expand Down
3 changes: 3 additions & 0 deletions motleycrew/common/defaults.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
from motleycrew.common import LLMFamily
from motleycrew.common import GraphStoreType


class Defaults:
DEFAULT_LLM_FAMILY = LLMFamily.OPENAI
DEFAULT_LLM_NAME = "gpt-4-turbo"
DEFAULT_LLM_TEMPERATURE = 0.0
LLM_MAP = {}

DEFAULT_GRAPH_STORE_TYPE = GraphStoreType.KUZU
4 changes: 4 additions & 0 deletions motleycrew/common/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ class LLMFramework:
LLAMA_INDEX = "llama_index"


class GraphStoreType:
KUZU = "kuzu"


class TaskStatus:
PENDING = "pending"
RUNNING = "running"
Expand Down
Loading

0 comments on commit 5100c7a

Please sign in to comment.