Python: Small fixes in examples (#540)

* Fixed Ruff formatting

* Added more info to chat response cancellation example

* Improved example

* Small fix
This commit is contained in:
Dmytro Struk
2025-08-28 13:41:18 -07:00
committed by GitHub
Unverified
parent 6a00c9d026
commit f5043e4fc1
5 changed files with 24 additions and 3 deletions
@@ -1,11 +1,13 @@
# Copyright (c) Microsoft. All rights reserved.
import asyncio
from agent_framework import ChatClientAgent, HostedFileSearchTool, HostedVectorStoreContent
from agent_framework.openai import OpenAIAssistantsClient
# Helper functions
async def create_vector_store(client: OpenAIAssistantsClient) -> tuple[str, HostedVectorStoreContent]:
"""Create a vector store with sample documents."""
file = await client.client.files.create(
@@ -42,12 +44,12 @@ async def main() -> None:
print(f"User: {query}")
print("Agent: ", end="", flush=True)
async for chunk in agent.run_streaming(
query,
tool_resources={"file_search": {"vector_store_ids": [vector_store.vector_store_id]}}
query, tool_resources={"file_search": {"vector_store_ids": [vector_store.vector_store_id]}}
):
if chunk.text:
print(chunk.text, end="", flush=True)
await delete_vector_store(client, file_id, vector_store.vector_store_id)
if __name__ == "__main__":
asyncio.run(main())