Skip to content

Commit 6879462

Browse files
Clean chess examples. (#6203)
Signed-off-by: zhanluxianshen <[email protected]> Co-authored-by: Eric Zhu <[email protected]>
1 parent f926820 commit 6879462

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

python/samples/agentchat_chess_game/main.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,14 @@ def get_user_prompt(board: chess.Board) -> str:
6666

6767

6868
def extract_move(response: str) -> str:
69-
start = response.find("<move>") + len("<move>")
69+
start = response.find("<move>")
7070
end = response.find("</move>")
71+
7172
if start == -1 or end == -1:
7273
raise ValueError("Invalid response format.")
73-
return response[start:end]
74+
if end < start:
75+
raise ValueError("Invalid response format.")
76+
return response[start+ len("<move>"):end].strip()
7477

7578

7679
async def get_ai_move(board: chess.Board, player: AssistantAgent, max_tries: int) -> str:

python/samples/core_distributed-group-chat/run_writer_agent.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,25 +22,28 @@ async def main(config: AppConfig) -> None:
2222
Console().print(Markdown("Starting **`Writer Agent`**"))
2323

2424
await writer_agent_runtime.start()
25+
model_client = AzureOpenAIChatCompletionClient(**config.client_config)
26+
2527
writer_agent_type = await BaseGroupChatAgent.register(
2628
writer_agent_runtime,
2729
config.writer_agent.topic_type,
2830
lambda: BaseGroupChatAgent(
2931
description=config.writer_agent.description,
3032
group_chat_topic_type=config.group_chat_manager.topic_type,
3133
system_message=config.writer_agent.system_message,
32-
model_client=AzureOpenAIChatCompletionClient(**config.client_config),
34+
model_client=model_client,
3335
ui_config=config.ui_agent,
3436
),
3537
)
3638
await writer_agent_runtime.add_subscription(
3739
TypeSubscription(topic_type=config.writer_agent.topic_type, agent_type=writer_agent_type.type)
3840
)
3941
await writer_agent_runtime.add_subscription(
40-
TypeSubscription(topic_type=config.group_chat_manager.topic_type, agent_type=config.writer_agent.topic_type)
42+
TypeSubscription(topic_type=config.group_chat_manager.topic_type, agent_type=writer_agent_type.type)
4143
)
4244

4345
await writer_agent_runtime.stop_when_signal()
46+
await model_client.close()
4447

4548

4649
if __name__ == "__main__":

0 commit comments

Comments
 (0)