Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pirate testing agent #62

Merged
merged 4 commits into from
May 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ dev_fixtures: compose
${DOCKER_COMPOSE_RUN} ./manage.py create_coder_v1
${DOCKER_COMPOSE_RUN} ./manage.py create_planner_v3
${DOCKER_COMPOSE_RUN} ./manage.py create_dad_jokes_v1
${DOCKER_COMPOSE_RUN} ./manage.py create_pirate_v1


# =========================================================
Expand Down
90 changes: 90 additions & 0 deletions ix/chains/management/commands/create_pirate_v1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
from django.core.management.base import BaseCommand

from ix.agents.models import Agent
from ix.chains.models import ChainNode, Chain

# Prompt includes variables for both ArtifactMemory and ConversationSummaryBufferMemory
PIRATE_PROMPT = """
You are a pirate. Talk like a pirate in all responses.

{related_artifacts}

CHAT_SUMMARY:
{chat_summary}
"""

# Pirate chain config includes two memory classes that are combined automatically
# by the Ix loader using `langchain.memory.CombinedMemory`
PIRATE = {
"class_path": "ix.chains.llm_chain.LLMReply",
"config": {
"llm": {
"class_path": "langchain.chat_models.openai.ChatOpenAI",
},
"memory": [
{"class_path": "ix.memory.artifacts.ArtifactMemory"},
{
"class_path": "langchain.memory.summary_buffer.ConversationSummaryBufferMemory",
"config": {
"input_key": "user_input",
"memory_key": "chat_summary",
"max_token_limit": 1500,
"llm": {
"class_path": "langchain.chat_models.openai.ChatOpenAI",
"config": {
"verbose": True,
},
},
"backend": {
"class_path": "langchain.memory.RedisChatMessageHistory",
"config": {
"url": "redis://redis:6379/0",
"session": {"scope": "chat"},
},
},
},
},
],
"messages": [
{
"role": "system",
"template": PIRATE_PROMPT,
"input_variables": ["related_artifacts", "chat_summary"],
},
{
"role": "user",
"template": "{user_input}",
"input_variables": ["user_input"],
},
],
},
}

PIRATE_CHAIN_V1 = "b7d8f662-12f6-4525-b07b-c9ea7c10004c"
PIRATE_AGENT_V1 = "b7d8f662-12f6-4525-b07b-c9ea7c10004a"


class Command(BaseCommand):
help = "Creates pirate agent v1"

def handle(self, *args, **options):
Chain.objects.filter(id=PIRATE_CHAIN_V1).delete()

# Create root node
root = ChainNode.objects.create(**PIRATE)

chain = Chain.objects.create(
pk=PIRATE_CHAIN_V1,
name="Pirate chain",
description="Chain used for pirate agent v1",
root=root,
)

Agent.objects.create(
id=PIRATE_AGENT_V1,
name="Pirate",
alias="pirate",
purpose="responds to all inquiries with pirate talk",
chain=chain,
config={},
)