Skip to content

Commit f11baee

Browse files
eobEnias CailliauEniasCailliau
authored
Make ship serve local attempt to serve everything (#466)
Running `ships serve local` will now attempt to load up every option by default. The goal is to have a single command to suggest to people that always works: `ship serve local` <img width="918" alt="image" src="https://github.com/steamship-core/python-client/assets/63262/be137d5e-685e-40d8-965c-2c36904ee9d4"> ## Behaviors: * Logging is limited to warning and errors in the console * A `logs/shiplog-datetime.log` file is used for all other logging messages * A repl, local server, ngrok server, and web UI are all started simuiltaneously * Options to suppress any of those startups are provided as command line args ## Limitation: * The REPL depends upon the latest python-client code which adds a `/prompt` method to ALL AgentService objects. It will not work with older AgentService objects. * Suggested followup: A second PR catches the `/prompt` 404 and tries `/answer`, remembering that worked if so ## Assumption: This depends upon the PR to be merged with `ship server local` -> `ship run local`. ## How to test Just use `pip install -e path/to/steamship-python` and then `.venv/bin/ship serve local` inside an agent project. --------- Co-authored-by: Enias Cailliau <enias@steamship.com> Co-authored-by: Enias Cailliau <hello@enias.ai>
1 parent 302e17e commit f11baee

12 files changed

Lines changed: 425 additions & 151 deletions

File tree

docs/developing/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ The process for details are located in the following pages:
3434
Python Environment Setup <environment-setup>
3535
Accepting Configuration <configuration>
3636
Storing Secrets <storing-secrets>
37+
Running on Localhost <running>
3738
Writing Tests <testing>
3839
Deploying <deploying>
3940
Monitoring your Instances <monitoring>
40-
Updating your Web Listing <updating-web-listing>
4141

docs/developing/running.rst

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
Running on Localhost
2+
--------------------
3+
4+
To run your project on localhost type:
5+
6+
.. code-block:: bash
7+
8+
ship run local
9+
10+
This will start a local instance with a number of ways to interact with it:
11+
12+
- A Console REPL, which will start immediately in the console.
13+
- An HTTP endpoint, which will be printed to the console
14+
- A Web endpoint, which will be printed to the console
15+
16+
The output will look like this:
17+
18+
.. code-block:: bash
19+
20+
Running your project..
21+
22+
🌎 Public API: https://example.ngrok.org/...
23+
🌎 Local API: http://localhost:8080/...
24+
🌎 Web URL: https://steamship:com/debug?https://...
25+
26+
💬 Interactive REPL below.
27+
28+
You: _
29+
30+
Localhost caveats
31+
~~~~~~~~~~~~~~~~~
32+
33+
Running on localhost currently does not yet support asynchronous tasks.
34+
In practice, this most often comes up with our ``DocumentIndexerPipelineMixin``, which enables loading in PDFs, YouTube videos, and other large documents for vector storage and retrieval.
35+

docs/developing/updating-web-listing.rst

Lines changed: 0 additions & 32 deletions
This file was deleted.
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
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()

src/steamship/agents/service/agent_service.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,9 @@ def run_agent(self, agent: Agent, context: AgentContext):
8888
func(action.output, context.metadata)
8989

9090
@post("prompt")
91-
def prompt(self, prompt: str, **kwargs) -> List[Block]:
91+
def prompt(self, prompt: Optional[str] = None, **kwargs) -> List[Block]:
9292
"""Run an agent with the provided text as the input."""
93+
prompt = prompt or kwargs.get("question")
9394

9495
# AgentContexts serve to allow the AgentService to run agents
9596
# with appropriate information about the desired tasking.

src/steamship/base/client.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919
from steamship.base.tasks import Task, TaskState
2020
from steamship.utils.url import Verb, is_local
2121

22-
_logger = logging.getLogger(__name__)
23-
2422
T = TypeVar("T") # TODO (enias): Do we need this?
2523

2624

0 commit comments

Comments
 (0)