-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix _process_params method when body is present (#429)
- Loading branch information
1 parent
7d0763b
commit d1f2566
Showing
2 changed files
with
80 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
from typing import Any | ||
|
||
import pytest | ||
from autogen import ConversableAgent, UserProxyAgent | ||
from fastapi import FastAPI | ||
from pydantic import BaseModel | ||
|
||
from fastagency.api.openapi.client import OpenAPI | ||
|
||
|
||
def create_fastapi_app_with_body(host: str, port: int) -> FastAPI: | ||
class Item(BaseModel): | ||
name: str | ||
price: float | ||
|
||
app = FastAPI( | ||
servers=[ | ||
{"url": f"http://{host}:{port}", "description": "Local development server"} | ||
] | ||
) | ||
|
||
@app.post("/items") | ||
async def create_item(item: Item) -> str: | ||
return "Item created" | ||
|
||
return app | ||
|
||
|
||
@pytest.mark.azure_oai | ||
@pytest.mark.parametrize( | ||
"fastapi_openapi_url", | ||
[(create_fastapi_app_with_body)], | ||
indirect=["fastapi_openapi_url"], | ||
) | ||
def test_end2end( | ||
fastapi_openapi_url: str, | ||
azure_gpt35_turbo_16k_llm_config: dict[str, Any], | ||
) -> None: | ||
api = OpenAPI.create(openapi_url=fastapi_openapi_url) | ||
|
||
agent = ConversableAgent(name="agent", llm_config=azure_gpt35_turbo_16k_llm_config) | ||
user_proxy = UserProxyAgent( | ||
name="user_proxy", | ||
llm_config=azure_gpt35_turbo_16k_llm_config, | ||
human_input_mode="NEVER", | ||
) | ||
|
||
api._register_for_llm(agent) | ||
api._register_for_execution(user_proxy) | ||
|
||
message = "Add item with name 'apple', price 1.0" | ||
user_proxy.initiate_chat( | ||
agent, | ||
message=message, | ||
summary_method="reflection_with_llm", | ||
max_turns=3, | ||
) | ||
|
||
message_existed = False | ||
expected_message = "Item created" | ||
for message in agent.chat_messages[user_proxy]: | ||
if ( | ||
isinstance(message, dict) | ||
and "content" in message | ||
and isinstance(message["content"], str) | ||
and message["content"] == expected_message | ||
): | ||
message_existed = True | ||
break | ||
assert message_existed, f"Expected message '{expected_message}' not found" |