Files
microsoft--agent-framework/python/samples/04-hosting/af-hosting/local_responses/call_server.py
T
wehub-resource-sync db620d33df
CodeQL / Analyze (csharp) (push) Waiting to run
CodeQL / Analyze (python) (push) Waiting to run
dotnet-build-and-test / dotnet-test-functions (push) Has been cancelled
dotnet-build-and-test / paths-filter (push) Has been cancelled
dotnet-build-and-test / dotnet-build (Debug, windows-latest, net9.0) (push) Has been cancelled
dotnet-build-and-test / dotnet-build (Release, ubuntu-latest, net10.0) (push) Has been cancelled
dotnet-build-and-test / dotnet-build (Release, ubuntu-latest, net8.0) (push) Has been cancelled
dotnet-build-and-test / dotnet-build (Release, windows-latest, net472) (push) Has been cancelled
dotnet-build-and-test / dotnet-test (Release, integration, true, ubuntu-latest, net10.0) (push) Has been cancelled
dotnet-build-and-test / dotnet-test (Release, integration, true, windows-latest, net472) (push) Has been cancelled
dotnet-build-and-test / dotnet-foundry-hosted-it (push) Has been cancelled
dotnet-build-and-test / dotnet-build-and-test-check (push) Has been cancelled
dotnet-build-and-test / Integration Test Report (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 13:39:25 +08:00

64 lines
1.7 KiB
Python

# Copyright (c) Microsoft. All rights reserved.
"""Local client for the local_responses sample.
Posts to ``/responses`` using the standard ``openai`` SDK.
Pass ``--previous-response-id <id>`` to continue a conversation by its
``response.id`` (returned in the prior response).
Start the server first (in another shell)::
uv run python app.py
Then::
uv run python call_server.py
The script sends two follow-up turns, each continuing from the previous
turn's ``response.id`` as ``previous_response_id``. The third turn asks about
information from the *first* turn only, so it also exercises session
continuity across a rotating response id chain, not just a single hop.
"""
from __future__ import annotations
from openai import OpenAI
BASE_URL = "http://127.0.0.1:8000"
PROMPT = "What is the weather in Tokyo?"
FOLLOW_UP_PROMPT = "And what about Amsterdam?"
THIRD_PROMPT = "Which of the two cities we just discussed is warmer?"
def main() -> None:
client = OpenAI(base_url=BASE_URL, api_key="not-needed")
response = client.responses.create(
input=PROMPT,
)
print(f"User: {PROMPT}")
print(f"Agent: {response.output_text}")
print(f"Response ID: {response.id}")
follow_up = client.responses.create(
input=FOLLOW_UP_PROMPT,
previous_response_id=response.id,
)
print()
print(f"User: {FOLLOW_UP_PROMPT}")
print(f"Agent: {follow_up.output_text}")
print(f"Response ID: {follow_up.id}")
third = client.responses.create(
input=THIRD_PROMPT,
previous_response_id=follow_up.id,
)
print()
print(f"User: {THIRD_PROMPT}")
print(f"Agent: {third.output_text}")
print(f"Response ID: {third.id}")
if __name__ == "__main__":
main()