Skip to content

Commit cf6b555

Browse files
committed
Transport, repl compatible with emit
1 parent fe828ea commit cf6b555

2 files changed

Lines changed: 19 additions & 9 deletions

File tree

src/steamship/experimental/transports/transport.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,14 @@ def instance_deinit(self, *args, **kwargs):
5555
end = time.time()
5656
logging.info(f"Transport deinitialized in {end - start} seconds: {self.__class__.__name__}")
5757

58-
def send(self, blocks: List[Block]):
58+
def send(self, blocks: List[Block], metadata: Dict[str, Any]):
5959
if blocks is None or len(blocks) == 0:
6060
logging.info(f"Skipping send of 0 blocks: {self.__class__.__name__}")
6161
return
6262

6363
logging.info(f"Sending {len(blocks)} blocks: {self.__class__.__name__}")
6464
start = time.time()
65-
self._send(blocks)
65+
self._send(blocks, metadata)
6666
end = time.time()
6767
logging.info(
6868
f"Sending {len(blocks)} blocks in {end - start} seconds: {self.__class__.__name__}"

src/steamship/utils/repl.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import logging
44
import uuid
55
from abc import ABC
6-
from typing import List, Optional, Type, cast
6+
from typing import Any, Dict, List, Optional, Type, cast
77

88
from steamship import Block, Steamship, Task
99
from steamship.agents.base import AgentContext, BaseTool
@@ -45,7 +45,7 @@ def _make_public_url(self, block):
4545
upload_to_signed_url(signed_url, block.raw())
4646
return read_signed_url
4747

48-
def print_blocks(self, blocks: List[Block]):
48+
def print_blocks(self, blocks: List[Block], metadata: Dict[str, Any]):
4949
"""Print a list of blocks to console."""
5050
for block in blocks:
5151
if isinstance(block, dict):
@@ -104,7 +104,7 @@ def colored(message: str, color: str):
104104
print(f"Task: {output.task_id}")
105105
else:
106106
blocks = cast(List[Block], output)
107-
self.print_blocks(blocks)
107+
self.print_blocks(blocks, {})
108108

109109
def run(self):
110110
with self.temporary_workspace() as client:
@@ -114,11 +114,18 @@ def run(self):
114114
class AgentREPL(SteamshipREPL):
115115
agent_class: Type[AgentService]
116116
client = Steamship
117-
118-
def __init__(self, agent_class: Type[AgentService], client: Optional[Steamship] = None):
117+
config = None
118+
119+
def __init__(
120+
self,
121+
agent_class: Type[AgentService],
122+
agent_package_config: Optional[Dict[str, Any]],
123+
client: Optional[Steamship] = None,
124+
):
119125
super().__init__()
120126
self.agent_class = agent_class
121127
self.client = client or Steamship()
128+
self.config = agent_package_config
122129

123130
def run_with_client(self, client: Steamship):
124131
try:
@@ -134,7 +141,7 @@ def colored(message: str, color: str):
134141
print(f"Chat ID: {chat_id}")
135142
print("If you make code changes, restart this REPL. Press CTRL+C to exit at any time.\n")
136143

137-
agent = self.agent_class(client=client)
144+
agent = self.agent_class(client=client, config=self.config)
138145

139146
while True:
140147
input_text = input(colored("Input: ", "blue")) # noqa: F821
@@ -151,8 +158,11 @@ def colored(message: str, color: str):
151158
text=input_text
152159
) # Should this take a Block, instead of creating a block?
153160
message.set_message_id(message_id)
161+
if len(context.emit_funcs) == 0:
162+
context.emit_funcs.append(self.print_blocks)
154163
response: Optional[List[Block]] = agent.run_agent(context)
155-
self.print_blocks(response)
164+
if response is not None:
165+
self.print_blocks(response, {})
156166

157167
def run(self):
158168
with self.temporary_workspace() as client:

0 commit comments

Comments
 (0)