fix imports, add readme
This commit is contained in:
parent
000a3da574
commit
79d2d98e67
|
@ -0,0 +1,13 @@
|
|||
# Crews
|
||||
|
||||
Some experiments with https://github.com/joaomdmoura/crewAI.
|
||||
|
||||
- Install and run `ollama`: https://github.com/ollama/ollama
|
||||
- Run a local server
|
||||
- Download the `mixtral` model: https://ollama.com/library/mixtral
|
||||
- Mistral and Llama 2 hallucinate badly and cannot use tools effectively
|
||||
- Set the following variables:
|
||||
- `OPENAI_API_KEY=NA`
|
||||
- `OPENAI_API_BASE='http://localhost:11434/v1'`
|
||||
- `OPENAI_MODEL_NAME='mixtral'`
|
||||
- Run a crew: `python3 -m novel.main`
|
|
@ -1,12 +1,20 @@
|
|||
from crewai import Agent
|
||||
from crew.tools import writing_tools, filesystem_tools, editing_tools
|
||||
from novel.tools import writing_tools, filesystem_tools, editing_tools
|
||||
|
||||
DEEP_ITER = 25
|
||||
|
||||
SUMMARY_WARNING = (
|
||||
"Pass on the full context to the next agent. Do not summarize the output of your task."
|
||||
"Pass on the full output to the next agent. Do not summarize the output of your task."
|
||||
"Always share all of the information you have so that future agents can make the best decision possible."
|
||||
"The world depends on it."
|
||||
)
|
||||
|
||||
class SlowAgent(Agent):
|
||||
def create_agent_executor(self, tools=None) -> None:
|
||||
super().create_agent_executor(tools)
|
||||
self.agent_executor.max_execution_time = 60
|
||||
|
||||
|
||||
character_designer = Agent(
|
||||
role='Character Designer',
|
||||
goal='Design characters for a {genre} novel based on {topic}',
|
||||
|
@ -17,7 +25,8 @@ character_designer = Agent(
|
|||
"You are tasked with designing the characters for the {genre} novel, including their appearance, personality, and backstory. "
|
||||
) + SUMMARY_WARNING,
|
||||
tools=writing_tools,
|
||||
allow_delegation=True
|
||||
allow_delegation=True,
|
||||
max_iter=DEEP_ITER,
|
||||
)
|
||||
|
||||
world_researcher = Agent(
|
||||
|
@ -31,7 +40,8 @@ world_researcher = Agent(
|
|||
"and its inhabitants, including the flora and fauna, and the different nations and biomes. "
|
||||
) + SUMMARY_WARNING,
|
||||
tools=writing_tools,
|
||||
allow_delegation=True
|
||||
allow_delegation=True,
|
||||
max_iter=DEEP_ITER,
|
||||
)
|
||||
|
||||
librarian = Agent(
|
||||
|
@ -47,7 +57,7 @@ librarian = Agent(
|
|||
allow_delegation=False
|
||||
)
|
||||
|
||||
writer = Agent(
|
||||
writer = SlowAgent(
|
||||
role='Writer',
|
||||
goal='Elaborate on the world and characters and write fascinating stories about {topic}',
|
||||
verbose=True,
|
||||
|
@ -58,10 +68,11 @@ writer = Agent(
|
|||
"creating {tone} stories. "
|
||||
) + SUMMARY_WARNING,
|
||||
tools=writing_tools,
|
||||
allow_delegation=True
|
||||
allow_delegation=True,
|
||||
max_iter=DEEP_ITER,
|
||||
)
|
||||
|
||||
editor = Agent(
|
||||
editor = SlowAgent(
|
||||
role='Editor',
|
||||
goal='Examine chapters of the novel for correct grammar, spelling, and continuity',
|
||||
verbose=True,
|
||||
|
@ -72,19 +83,21 @@ editor = Agent(
|
|||
"making sure all of the details are in agreement and the story contextually makes sense. "
|
||||
) + SUMMARY_WARNING,
|
||||
tools=editing_tools,
|
||||
allow_delegation=True
|
||||
allow_delegation=True,
|
||||
max_iter=DEEP_ITER,
|
||||
)
|
||||
|
||||
publisher = Agent(
|
||||
publisher = SlowAgent(
|
||||
role='Publisher',
|
||||
goal='Write a {genre} novel about {topic} and save it to a markdown file.',
|
||||
verbose=True,
|
||||
memory=True,
|
||||
backstory=(
|
||||
"You are the publisher for a {genre} novel. You help manage and coordinate your co-workers to write"
|
||||
"chapters of the novel and save them to a file. You then publish the novel when it is complete, by "
|
||||
"saving it to a markdown file. "
|
||||
"chapters of the novel, which you then save. You then publish the novel when it is complete by "
|
||||
"compiling the chapters and saving them to a markdown file. "
|
||||
) + SUMMARY_WARNING,
|
||||
tools=[*editing_tools, *filesystem_tools],
|
||||
allow_delegation=True
|
||||
allow_delegation=True,
|
||||
max_iter=DEEP_ITER,
|
||||
)
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
from crewai import Crew, Process
|
||||
from crewai.telemetry import Telemetry
|
||||
from langchain_openai import ChatOpenAI
|
||||
from crew.agents import character_designer, world_researcher, writer, editor, publisher
|
||||
from crew.tasks import novel_task, chapter_task, edit_task, world_task, character_task, plot_task
|
||||
from novel.agents import character_designer, world_researcher, writer, editor, publisher
|
||||
from novel.tasks import novel_task, chapter_task, edit_task, world_task, character_task, plot_task, save_task
|
||||
|
||||
|
||||
# disable spyware, it's broken anyway
|
||||
|
@ -25,12 +25,13 @@ crew = Crew(
|
|||
# librarian,
|
||||
],
|
||||
tasks=[
|
||||
novel_task,
|
||||
world_task,
|
||||
character_task,
|
||||
plot_task,
|
||||
chapter_task,
|
||||
edit_task,
|
||||
novel_task,
|
||||
save_task,
|
||||
],
|
||||
manager_llm=ChatOpenAI(temperature=0.05, model="mixtral"),
|
||||
process=Process.hierarchical,
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
from crewai import Task
|
||||
from crew.tools import writing_tools, editing_tools, filesystem_tools
|
||||
from crew.agents import character_designer, world_researcher, writer, editor, publisher
|
||||
from novel.agents import character_designer, world_researcher, writer, editor, publisher
|
||||
from novel.tools import writing_tools, editing_tools, filesystem_tools
|
||||
|
||||
class LogTask(Task):
|
||||
def _save_file(self, result):
|
||||
|
@ -80,6 +80,17 @@ novel_task = LogTask(
|
|||
output_file='novel.md',
|
||||
)
|
||||
|
||||
save_task = LogTask(
|
||||
description=(
|
||||
"Save a completed novel to a file."
|
||||
),
|
||||
expected_output='The filename where the novel was saved.',
|
||||
tools=filesystem_tools,
|
||||
agent=publisher, # librarian,
|
||||
async_execution=False,
|
||||
output_file='novel-save.md',
|
||||
)
|
||||
|
||||
save_chapter = LogTask(
|
||||
description=(
|
||||
"Save a completed chapter to a file."
|
||||
|
|
Loading…
Reference in New Issue