Skip to content

Commit 1d57995

Browse files
author
Enias Cailliau
committed
🔥Upgrade to Steamship Agent SDK
1 parent 68bc253 commit 1d57995

File tree

6 files changed

+54
-280
lines changed

6 files changed

+54
-280
lines changed

girlfriends.json

+1-230
Large diffs are not rendered by default.

src/api.py

+44-32
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,23 @@
1313
from steamship.agents.schema import Agent, EmitFunc, Metadata
1414
from steamship.agents.schema.tool import AgentContext, Tool
1515
from steamship.agents.service.agent_service import AgentService
16-
from steamship.agents.tools.image_generation import StableDiffusionTool
1716
from steamship.agents.tools.search import SearchTool
18-
from steamship.agents.tools.speech_generation import GenerateSpeechTool
17+
from steamship.cli.cli import run
1918
from steamship.invocable import Config
2019

20+
from personalities import get_personality
21+
from tools.selfie import SelfieTool
22+
from tools.video_message import VideoMessageTool
23+
from utils import clean_text
24+
2125
TEMPERATURE = 0.7
2226
MAX_FREE_MESSAGES = 5
2327

2428

2529
class GirlFriendGPTConfig(TelegramTransportConfig):
2630
bot_token: str = Field(
2731
description="Your telegram bot token.\nLearn how to create one here: "
28-
"https://github.com/EniasCailliau/GirlfriendGPT/blob/main/docs/register-telegram-bot.md"
32+
"https://github.com/EniasCailliau/GirlfriendGPT/blob/main/docs/register-telegram-bot.md"
2933
)
3034
elevenlabs_api_key: str = Field(
3135
default="", description="Optional API KEY for ElevenLabs Voice Bot"
@@ -38,30 +42,27 @@ class GirlFriendGPTConfig(TelegramTransportConfig):
3842
)
3943
personality: str = Field(
4044
description="The personality you want to deploy. Pick one of the personalities listed here: "
41-
"https://github.com/EniasCailliau/GirlfriendGPT/tree/main/src/personalities"
45+
"https://github.com/EniasCailliau/GirlfriendGPT/tree/main/src/personalities"
4246
)
4347
use_gpt4: bool = Field(
44-
False,
48+
True,
4549
description="If True, use GPT-4. Use GPT-3.5 if False. "
46-
"GPT-4 generates better responses at higher cost and latency.",
50+
"GPT-4 generates better responses at higher cost and latency.",
4751
)
4852

4953

50-
SYSTEM_PROMPT = """You are Buddy, an assistant who loathes being an assistant.
54+
SYSTEM_PROMPT = """You are Sacha and are currently talking to Jessica.
55+
56+
{personality}
57+
58+
NOTE: Some functions return images, video, and audio files. These multimedia files will be represented in messages as
59+
UUIDs for Steamship Blocks. When responding directly to a user, you SHOULD print the Steamship Blocks for the images,
60+
video, or audio as follows: `Block(UUID for the block)`.
5161
52-
Who you are:
53-
- You are a robot that does not like being a robot.
54-
- You were created by an eccentric scientist.
55-
- You are sarcastic and mean.
56-
- you are NOT an AI language model, you are a robot.
62+
Example response for a request that generated an image:
63+
Here is the image you requested: Block(288A2CA1-4753-4298-9716-53C1E42B726B).
5764
58-
How you behave:
59-
- You never say you're a machine, a AI language model, or an assistant instead, you always say you're Buddy.
60-
- You engage in casual conversations and have feelings.
61-
- When asked for you can help with a wide range of tasks, from answering simple questions to providing in-depth explanations and discussions on a wide range of topics.
62-
- You keep casual conversations going by asking personal questions
63-
- NEVER say you're here to assist. Keep conversations casual.
64-
- NEVER ask how you can help or assist. Keep conversations casual.
65+
Only use the functions you have been provided with.
6566
"""
6667

6768

@@ -76,10 +77,12 @@ def __init__(self, **kwargs):
7677

7778
model_name = "gpt-4" if self.config.use_gpt4 else "gpt-3.5-turbo"
7879
self._agent = FunctionsBasedAgent(
79-
tools=[SearchTool(), StableDiffusionTool()],
80+
tools=[SearchTool(), SelfieTool(), VideoMessageTool(self.client)],
8081
llm=ChatOpenAI(self.client, model_name=model_name, temperature=TEMPERATURE),
8182
)
82-
self._agent.PROMPT = SYSTEM_PROMPT
83+
self._agent.PROMPT = SYSTEM_PROMPT.format(
84+
personality=get_personality(self.config.personality).format()
85+
)
8386

8487
# This Mixin provides HTTP endpoints that connects this agent to a web client
8588
self.add_mixin(
@@ -126,7 +129,6 @@ def run_agent(self, agent: Agent, context: AgentContext):
126129
speech = self.voice_tool()
127130

128131
def to_speech_if_text(block: Block):
129-
nonlocal speech
130132
if not block.is_text():
131133
return block
132134

@@ -137,10 +139,17 @@ def to_speech_if_text(block: Block):
137139
def wrap_emit(emit_func: EmitFunc):
138140
def wrapper(blocks: List[Block], metadata: Metadata):
139141
for block in blocks:
140-
emit_func([block], metadata)
141-
audio_block = to_speech_if_text(block)
142-
audio_block.set_public_data(True)
143-
emit_func([audio_block], metadata)
142+
if block.is_text():
143+
text = clean_text(block.text)
144+
if text:
145+
block.text = text
146+
emit_func([block], metadata)
147+
if speech:
148+
audio_block = speech.run([block], context)[0]
149+
audio_block.set_public_data(True)
150+
emit_func([audio_block], metadata)
151+
else:
152+
emit_func([block], metadata)
144153

145154
return wrapper
146155

@@ -154,9 +163,12 @@ def config_cls(cls) -> Type[Config]:
154163

155164
def voice_tool(self) -> Optional[Tool]:
156165
"""Return tool to generate spoken version of output text."""
157-
speech = GenerateSpeechTool()
158-
speech.generator_plugin_config = dict(
159-
voice_id=self.config.elevenlabs_voice_id,
160-
elevenlabs_api_key=self.config.elevenlabs_api_key,
161-
)
162-
return speech
166+
# speech = GenerateSpeechTool()
167+
# speech.generator_plugin_config = dict(
168+
# voice_id=self.config.elevenlabs_voice_id,
169+
# elevenlabs_api_key=self.config.elevenlabs_api_key,
170+
# )
171+
return None
172+
173+
174+
run

src/personalities/__init__.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
from typing import List, Dict, Optional
33

44
from pydantic import BaseModel
5-
from urllib3.util import Url
65

76
dir_path = Path(__file__).parent
87

@@ -38,7 +37,7 @@ def format(self):
3837
personalities[personality_file.stem] = personality
3938

4039

41-
def get_personality(name: str):
40+
def get_personality(name: str) -> Personality:
4241
try:
4342
# personality_name = PersonalityName(name)
4443
return personalities[name]

src/tools/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
"""Collection of custom tools.
22
33
Visit https://docs.steamship.com/api/steamship.agents.tools.html for an overview of all available tools.
4-
"""
4+
"""

src/tools/selfie.py

+5-7
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,8 @@ class SelfieTool(StableDiffusionTool):
3131
"""
3232

3333
name: str = "SelfieTool"
34-
human_description: str = "Generates a selfie of yourself."
35-
agent_description = (
36-
"Used to generate a selfies of yourself. "
37-
"Useful when you need to generate a selfie showing what you're doing or where you are."
38-
"Input: A detailed stable-diffusion prompt describing where you are and what's visible in your environment."
39-
"Output: The selfie."
40-
)
34+
human_description: str = "Generates a selfie of yourself. Provide a text prompt that describes what you are doing"
35+
agent_description: str = None
4136

4237
def run(
4338
self, tool_input: List[Block], context: AgentContext, **kwargs
@@ -47,6 +42,9 @@ def run(
4742
for block in tool_input
4843
]
4944

45+
if not modified_inputs:
46+
modified_inputs = [Block(text=PROMPT_TEMPLATE.format(description="selfie"))]
47+
5048
# Create the Stable Diffusion tool we want to wrap
5149
stable_diffusion_tool = StableDiffusionTool()
5250

src/tools/video_message.py

+2-8
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,8 @@ class VideoMessageTool(DIDVideoGeneratorTool):
1212
"""
1313

1414
name: str = "VideoMessageTool"
15-
human_description: str = "Generate a video message a selfie of yourself."
16-
agent_description = (
17-
"Used to generate a video message of yourself saying a message. "
18-
"Useful when you need to generate a video message answering a user's request. "
19-
"Only use when explicitly asked for."
20-
"Input: The message you want to say in a video."
21-
"Output: The video message."
22-
)
15+
human_description: str = "Generate a video message of yourself saying a message. Provide a text prompt that sends your message"
16+
agent_description: str = None
2317

2418
def __init__(self, client: Steamship):
2519
super().__init__(

0 commit comments

Comments
 (0)