Skip to content

Commit

Permalink
add more fields into message
Browse files Browse the repository at this point in the history
  • Loading branch information
pan-x-c committed May 21, 2024
1 parent 271c8e4 commit b02c7b2
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 4 deletions.
10 changes: 8 additions & 2 deletions src/agentscope/agents/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,14 +310,20 @@ def speak(
if isinstance(content, dict):
_runtime.studio_client.send_message(
name=content.get("name", ""),
role=content.get("role", "assistant"),
content=content.get("content", ""),
url=content.get("url", ""),
metadata=content.get("metadata", {}),
url=content.get("url", None),
timestamp=content.get("timestamp", None),
)
else:
_runtime.studio_client.send_message(
name="",
role="assistant",
content=str(content),
url="",
metadata={},
url=None,
timestamp=None,
)

def observe(self, x: Union[dict, Sequence[dict]]) -> None:
Expand Down
2 changes: 2 additions & 0 deletions src/agentscope/agents/user_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ def reply(
)
raw_input = self.input_client.get_user_input()
content = raw_input["content"]
url = None
kwargs = {}
else:
time.sleep(0.5)
content = user_input(timeout=timeout)
Expand Down
12 changes: 12 additions & 0 deletions src/agentscope/web/_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,11 @@ class Message(db.Model): # type: ignore[name-defined]
id = db.Column(db.Integer, primary_key=True)
run_id = db.Column(db.String, db.ForeignKey("run.id"), nullable=False)
name = db.Column(db.String)
role = db.Column(db.String)
content = db.Column(db.String)
url = db.Column(db.String)
meta = db.Column(db.String)
timestamp = db.Column(db.String)


def get_history_messages(run_id: str) -> list:
Expand All @@ -55,8 +58,11 @@ def get_history_messages(run_id: str) -> list:
return [
{
"name": message.name,
"role": message.role,
"content": message.content,
"url": message.url,
"metadata": json.loads(message.meta),
"timestamp": message.timestamp,
}
for message in messages
]
Expand Down Expand Up @@ -140,14 +146,20 @@ def put_message() -> Response:
data = request.json
run_id = data["run_id"]
name = data["name"]
role = data["role"]
content = data["content"]
metadata = json.dumps(data["metadata"])
timestamp = data["timestamp"]
url = data.get("url", None)
try:
new_message = Message(
run_id=run_id,
name=name,
role=role,
content=content,
meta=metadata,
url=url,
timestamp=timestamp,
)
db.session.add(new_message)
db.session.commit()
Expand Down
10 changes: 8 additions & 2 deletions src/agentscope/web/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def register_run(
},
timeout=10, # todo: configurable timeout
)
if resp == 200:
if resp.status_code == 200:
return True
else:
logger.warning(f"Fail to register to studio: {resp}")
Expand All @@ -113,7 +113,10 @@ def register_run(
def send_message(
self,
name: str,
role: str,
content: str,
timestamp: str = None,
metadata: dict = None,
url: str = None,
) -> bool:
"""Send a message to the studio."""
Expand All @@ -123,8 +126,11 @@ def send_message(
json={
"run_id": self.run_id,
"name": name,
"role": role,
"content": content,
"url": None,
"timestamp": timestamp,
"metadata": metadata,
"url": url,
},
timeout=10,
)
Expand Down

0 comments on commit b02c7b2

Please sign in to comment.