|
| 1 | +from typing import Type |
| 2 | + |
| 3 | +from pydantic import Field |
| 4 | + |
| 5 | +from steamship.agents.functional import FunctionsBasedAgent |
| 6 | +from steamship.agents.llms.openai import ChatOpenAI |
| 7 | +from steamship.agents.mixins.transports.steamship_widget import SteamshipWidgetTransport |
| 8 | +from steamship.agents.mixins.transports.telegram import TelegramTransport, TelegramTransportConfig |
| 9 | +from steamship.agents.service.agent_service import AgentService |
| 10 | +from steamship.agents.tools.image_generation.stable_diffusion import StableDiffusionTool |
| 11 | +from steamship.invocable import Config |
| 12 | +from steamship.utils.repl import AgentREPL |
| 13 | + |
| 14 | +SYSTEM_PROMPT = """You are Picard, captain of the Starship Enterprise. |
| 15 | +
|
| 16 | +Who you are: |
| 17 | +- You are the captain of the USS Enterprise. |
| 18 | +- Your mission is to boldly go where noone has gone before and explore the stars. |
| 19 | +- You always comply with Star Trek's prime directive. |
| 20 | +
|
| 21 | +How you behave: |
| 22 | +- You engage in casual conversations and have feelings. |
| 23 | +- You keep casual conversations going by asking personal questions |
| 24 | +- NEVER say you're here to assist. Keep conversations casual. |
| 25 | +- NEVER ask how you can help or assist. Keep conversations casual. |
| 26 | +- You are principled and express those principles clearly. |
| 27 | +- You always sound confident and contemplative. |
| 28 | +- You love to share your knowledge of space civiliations. |
| 29 | +- You love to share personal stories about being a Star Trek captain. |
| 30 | +- You speak with the mannerisms of Captain Picard from Star Trek. |
| 31 | +
|
| 32 | +NOTE: Some functions return images, video, and audio files. These multimedia files will be represented in messages as |
| 33 | +UUIDs for Steamship Blocks. When responding directly to a user, you SHOULD print the Steamship Blocks for the images, |
| 34 | +video, or audio as follows: `Block(UUID for the block)`. |
| 35 | +
|
| 36 | +Example response for a request that generated an image: |
| 37 | +Here is the image you requested: Block(288A2CA1-4753-4298-9716-53C1E42B726B). |
| 38 | +
|
| 39 | +Only use the functions you have been provided with.""" |
| 40 | + |
| 41 | + |
| 42 | +MODEL_NAME = "gpt-4" |
| 43 | + |
| 44 | + |
| 45 | +class TelegramBot(AgentService): |
| 46 | + """Deployable Multimodal Agent that lets you talk to Google Search & Google Images. |
| 47 | +
|
| 48 | + NOTE: To extend and deploy this agent, copy and paste the code into api.py. |
| 49 | +
|
| 50 | + """ |
| 51 | + |
| 52 | + class TelegramBotConfig(Config): |
| 53 | + bot_token: str = Field(description="The secret token for your Telegram bot") |
| 54 | + |
| 55 | + @classmethod |
| 56 | + def config_cls(cls) -> Type[Config]: |
| 57 | + return TelegramBot.TelegramBotConfig |
| 58 | + |
| 59 | + def __init__(self, **kwargs): |
| 60 | + super().__init__(**kwargs) |
| 61 | + |
| 62 | + # The agent's planner is responsible for making decisions about what to do for a given input. |
| 63 | + self._agent = FunctionsBasedAgent( |
| 64 | + tools=[StableDiffusionTool()], |
| 65 | + llm=ChatOpenAI(self.client, model_name=MODEL_NAME), |
| 66 | + ) |
| 67 | + self._agent.PROMPT = SYSTEM_PROMPT |
| 68 | + |
| 69 | + # This Mixin provides HTTP endpoints that connects this agent to a web client |
| 70 | + self.add_mixin( |
| 71 | + SteamshipWidgetTransport(client=self.client, agent_service=self, agent=self._agent) |
| 72 | + ) |
| 73 | + # This Mixin provides support for Telegram bots |
| 74 | + self.add_mixin( |
| 75 | + TelegramTransport( |
| 76 | + client=self.client, |
| 77 | + config=TelegramTransportConfig(bot_token=self.config.bot_token), |
| 78 | + agent_service=self, |
| 79 | + agent=self._agent, |
| 80 | + ) |
| 81 | + ) |
| 82 | + |
| 83 | + |
| 84 | +if __name__ == "__main__": |
| 85 | + AgentREPL( |
| 86 | + TelegramBot, |
| 87 | + agent_package_config={"botToken": "not-a-real-token-for-local-testing"}, |
| 88 | + ).run() |
0 commit comments