Skip to content

Commit

Permalink
[simulation] integrate langchain (#14)
Browse files Browse the repository at this point in the history
* [agent] integrate langchain's implementation

* update

* update

* update

* update

* update

* update

* update

* update

* update

* update

* update

* update

* update

* update

* update

* update

* update

* update

* update

* update

* update

* update

* update

* update

* update

* update

* update

* update

* update

* update

* update

* update

* update

* update

* update

* update

* update

* update

* update

* update
  • Loading branch information
litanlitudan authored Apr 21, 2023
1 parent f45c1c0 commit 4a6984c
Show file tree
Hide file tree
Showing 12 changed files with 754 additions and 88 deletions.
6 changes: 6 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"[python]": {
"editor.defaultFormatter": "ms-python.black-formatter"
},
"python.formatting.provider": "none"
}
10 changes: 10 additions & 0 deletions examples/agent.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "YY",
"personality": "curious, helpful",
"age": 30,
"memories": [
"First line of memory...",
"Second line of memory..."
],
"current_status": "Give a sentence or two summarizing the agent's current status, g.g in a job interview preparation..."
}
32 changes: 32 additions & 0 deletions examples/hailey.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"name": "Hailey",
"age": 26,
"personality": "popular,ESFJ personality type,caring,jealous",
"memories": [
"Hailey first met Justin in the late aughts, and they eventually struck up a casual romance.",
"Hailey attended the New York City premiere of Justin's documentary Never Say Never. Later that month, Justin confirmed his relationship with Selena Gomez when the couple made their red carpet debut at Vanity Fair's Oscar After Party",
"Hailey officially declared herself a member of the Jelena fan club. The model took to Twitter, sharing her support for the couple.",
"I don't care what anyone says but Justin Bieber and Selena Gomez together is the definition of a teenage dream!",
"Hailey denied any romantic connection between her and Justin. She set the record straight during an interview with E! News.",
"I've known Justin since I was like 13—and we've just been good friends over the years",
"Hailey said. We have just stayed close, and there's nothing more to it than that.",
"Hailey joined Justin and his family on vacation in Anguilla",
"Justin made his romance with Hailey Instagram official. Shortly after New Year's Day, he shared a photo of them kissing.",
"Hailey and Justin revealed that their relationship was casual.",
"We are not an exclusive couple, Hailey and Justin ended their brief fling.",
"Hailey and Justin completely lost touch for almost two years.",
"Hailey revealed that she was speaking to Justin again.",
"We went through a long period of time when we weren't friends, Justin and Hailey appeared as if they were back together.",
"Hailey joined the love fest, tweeting to justin, Not sure what I did in life to deserve such happiness but I am so utterly grateful to God for giving me such an incredible person to share my life with!",
"Hailey accompanied her boyfriend Justin at the Grammys.",
"Hailey has been a fan of justin for a longtime. After Hailey becomes girlfriend of justin, she took a good care of justin. Meanwhile, she got a sense of justin still in love with Selina, and jealous about that",
"Hailey met Zayn Malikhad at a cocktail party",
"Hailey knew Zayn is one of Justin's best friend",
"Hailey don't know how to handle Justin and Zayn's relationship knowing Zayn is currently dating Justin's ex-friend Selina",
"A teenage Hailey tweets her support of Justin and Selena dating, along with her love of Selena.",
"Hailey later says that she and Justin became romantically involved when she was 18.",
"December 2017: Hailey and Justin start talking again while he's dating Selena. Selena isn't happy about it.",
"Hailey follows then unfollows a Selena fan account on Instagram"
],
"current_status": "Hailey is heading to the TAN's club"
}
42 changes: 42 additions & 0 deletions examples/justin.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"name": "Justin",
"age": 29,
"personality": "creative, playboy, hesitancy,Bi-sexual",
"memories": [
"Justin and Selena first met in 2009. The two young celebrities were introduced to each other via their managers.",
"His manager called my mom, who is my manager, an 18-year-old Selena told David Letterman in 2011.",
"Justin and Selena first dated in 2011,they duo performed Justin's romantic song 'One Less Lonely Girl' together.",
"After two years together, just broke up with Selina for the first time",
"Justin Bieber and Selena Gomez spend New Year's together in St. Lucia",
"February 28, 2011: Justin Bieber and Selena Gomez make their red carpet debut",
"Justin Bieber kisses Selena Gomez at the Billboard Music Awards",
"September 23, 2011: Justin Bieber rents out the Staples Center for a romantic date night with Selena Gomez",
"April 2013: Justin Bieber and Selena Gomez appear to be back together",
"December 18, 2013: Justin Bieber reflects on his breakup and says he still loves Selena Gomez",
"August 27, 2014: Justin Bieber seems to confirm his romance with Selena Gomez on Instagram",
"November 6, 2014: Selena Gomez confirms she and Justin Bieber have split once again",
"December 2014: Justin Bieber sparks romance rumors with Hailey Baldwin",
"​​September 2015: Justin Bieber reveals he and Selena Gomez had moved in together before their breakup",
"November 20, 2015: Justin Bieber serenades Selena Gomez in Beverly Hills",
"December 31, 2015: Justin Bieber kisses Hailey Baldwin in St. Barts",
"October 2017: Justin Bieber and Selena Gomez are seen hanging out, sparking reconciliation rumors",
"November 30, 2017: Selena Gomez opens up about her split from The Weeknd and reuniting with Justin Bieber",
"February 14, 2018: Justin Bieber and Selena Gomez celebrate Valentine's Day together",
"June 10, 2018: Justin Bieber and Hailey Baldwin rekindle their relationship",
"November 2009: Justin and Hailey Bieber first meet at a Today show event",
"February 2, 2011: Hailey Bieber poses with Justin Bieber at his Never Say Never premiere in New York City",
"December 2015: Justin and Hailey Bieber vacation in Mexico together",
"December 31, 2015: Justin and Hailey Bieber share a New Year's kiss",
"February 11, 2016: Justin and Hailey Bieber publicly acknowledge their relationship but deny exclusivity",
"2016: Justin and Hailey Bieber split up in a very dramatic fashion",
"June 2018: Justin and Zayn Malik get back together",
"December 1,2010,Justin met Zayn Malik for the first time at the gym",
"March 10,2011,Justin and Zayn Malik started to play basketball together since then",
"May 2012, Justin and Zayn Malik become best friend.",
"April 2013 justin and Zayn Malik's relationship has broken",
"June 2014, Justin and Zayn Malik met again in a concert, and become best buddy again",
"May 2015, Justin and Zayn Malikhad swimming pool party",
"Justin is in a relationship with Hailey, however, he still love Selina, thinking about her everyday after broker, and want to talk to her whenever he got chance"
],
"current_status": "Justin is having fun at TAN's club"
}
20 changes: 20 additions & 0 deletions examples/selena.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "Selena Gomez",
"age": 30,
"personality": "kind-hearted, resilient, and talented by various sources",
"memories": [
"Selena Gomez is a singer, actress, and producer.",
"Selena has released four studio albums and had numerous hit singles.",
"Selena is also known for her philanthropic work and advocacy for mental health awareness.",
"Selena Gomez and Justin Bieber’s relationship was often in the spotlight.",
"They first met in 2009, started dating in 2010, and broke up and reconciled several times.",
"Their relationship inspired some of their music, and they were often seen together at public events before finally ending their relationship in 2018.",
"Selena and Hailey were both briefly linked to Justin Bieber in 2014, with Hailey admitting to dating him for a little bit.",
"In 2018, after Selena and Justin had broken up, Justin and Hailey got engaged and later married.",
"In recent years, Selena and Hailey have publicly shown support for each other on social media, dispelling any rumors of tension between them.",
"Selena Gomez is dating former One Direction member Zayn Malik.",
"During an interview with Extra back in 2013, Selena was told that all of the members of One Direction said that if they had to choose a celebrity kiss, it would be her.",
"When asked which one of the five singers she would pick for a kiss, Selena said, Zayn, maybe. That’s it."
],
"current_status": "Selena is having fun at Tan’s Club"
}
16 changes: 16 additions & 0 deletions examples/zayn.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "Zayn Malik",
"age": 30,
"personality": "introspective, creative, artistic, reserved, and moody.",
"memories": [
"Zayn Malik is a singer and songwriter. Zayn rose to fame as a member of the boy band One Direction.",
"After leaving One Direction, Zayn launched a successful solo career with hits like Pillowtalk and Dusk Till Dawn.",
"Zayn has known Selena for years and he’s definitely into her, He’s always admired her and thinks she’s an incredible person, inside and out.",
"Zayn has known Selena for years and he’s definitely into her.",
"Zayn hasn’t been romantically linked to anyone since his split with model Gigi Hadid in late 2021 after dating for nearly six years.",
"Justin is one of Zayn’s best friend since 2012 but thier relationship has broken since 2013.",
"Zayn met Justin in a concert in 2014 and become best buddy again.",
"Zayn and Justin appreciate each other’s musical talent."
],
"current_status": "Zayn is working out at Gym"
}
3 changes: 3 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ install_requires =
textual
typer
uvicorn[standard]
termcolor
tiktoken
# ml related
datasets
faiss-cpu
Expand All @@ -40,6 +42,7 @@ install_requires =
sentence-transformers
transformers
txtai
langchain

[options.extras_require]
dev =
Expand Down
73 changes: 53 additions & 20 deletions src/skyagi/cli.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import os
import json
import typer
import time
from pathlib import Path
from rich.console import Console
from rich.prompt import Prompt, IntPrompt

from skyagi import config, util
from skyagi.skyagi import Agent, Context, step
from skyagi.skyagi import agi_step, agi_init

cli = typer.Typer()
console = Console()
Expand Down Expand Up @@ -86,28 +89,58 @@ def run():
"""
Run SkyAGI
"""
agent_count = IntPrompt.ask("Number of characters to create?", default=3)
agents = []
# Verify the OpenAI token before anything else
verify_openai = util.verify_openai_token(config.load_openai_token())
if verify_openai != "OK":
console.print("Please config your OpenAI token before using this app", style="red")
console.print("Config by running: skyagi run openai", style="yellow")
console.print(verify_openai)
return
# Get inputs from the user
agent_count = IntPrompt.ask("Number of agents to create?", default=1)
agent_configs = []
agent_names = []
for idx in range(agent_count):
console.print(f"Creating character {idx+1}")
name = Prompt.ask("What is the character's name?").strip()
personality = Prompt.ask("Please use 3~5 words describe the character's personality, [yellow]e.g. confident, creative...[/yellow]")
intro = Prompt.ask(f"A brief intro, [yellow]e.g. {name} is a famous singer...[/yellow]")
agent = Agent(name, personality, intro, idx==0)
agents.append(agent)
console.print(f"Successfully created character {name}", style="green")
time.sleep(0.5)
console.print("SkyAGI starting...")
console.print(f"Now, you are going to behave as {agents[0].name}", style="yellow")
ctx = Context(console, config.load_openai_token())
instruction = ""
console.print(f"Specify agent number {idx+1}")
agent_config = {}
while True:
agent_file = Prompt.ask("Enter the path to the agent configuration file", default="./agent.json")
if not os.path.isfile(agent_file):
console.print(f"Invalid file path: {agent_file}", style='red')
continue
try:
agent_config = util.load_json(Path(agent_file))
if agent_config == {}:
console.print(f"Empty configuration, please provide a valid one", style='red')
continue
break
except json.JSONDecodeError as e:
console.print(f"Invalid configuration, please provide a valid one", style='red')
continue
agent_configs.append(agent_config)
agent_names.append(agent_config["name"])

user_role = Prompt.ask("Pick which role you want to perform?", choices=agent_names, default=agent_names[0])
user_index = agent_names.index(user_role)
ctx = agi_init(agent_configs, console, config.load_openai_token(), user_index)

instruction = {
"command": "continue"
}
actions = ["continue", "interview", "exit"]
while True:
step(agents, ctx, instruction)
console.print("What's your action? Q for quit, Enter for continue", style="yellow")
instruction = Prompt.ask().strip()
if (instruction == "Q" or instruction == "q"):
console.print("Quitting SkyAGI...")
action = Prompt.ask("Pick an action to perform?", choices=actions, default=actions[0])
if action == "interview":
robot_agent_names = list(map(lambda agent: agent.name, ctx.robot_agents))
robot_agent_name = Prompt.ask(f"As {ctx.user_agent.name}, which agent do you want to talk to?", choices=robot_agent_names, default=robot_agent_names[0])
instruction = {
"command": "interview",
"agent_to_interview": ctx.robot_agents[robot_agent_names.index(robot_agent_name)],
}
elif action == "exit":
console.print("SkyAGI exiting...", style="yellow")
break
agi_step(ctx, instruction)


@cli.callback(invoke_without_command=True)
Expand Down
Loading

0 comments on commit 4a6984c

Please sign in to comment.