Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions docs/mcp/airbnb.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,33 @@ flowchart LR
- OpenAI API key (for the agent's LLM)
</Note>

## Gradio UI

```python
from praisonaiagents import Agent, MCP
import gradio as gr

def search_airbnb(query):
agent = Agent(
instructions="You help book apartments on Airbnb.",
llm="gpt-4o-mini",
tools=MCP("npx -y @openbnb/mcp-server-airbnb --ignore-robots-txt")
Comment on lines +77 to +80
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The LLM and tool configurations are hardcoded. Consider making these configurable via environment variables or a configuration file to allow users to easily change the settings without modifying the code.

    llm = os.getenv("LLM_MODEL", "gpt-4o-mini")
    tools_command = os.getenv("AIRBNB_MCP_COMMAND", "npx -y @openbnb/mcp-server-airbnb --ignore-robots-txt")
    agent = Agent(
        instructions="You help book apartments on Airbnb.",
        llm=llm,
        tools=MCP(tools_command)
    )

)
result = agent.start(query)
return f"## Airbnb Search Results\n\n{result}"
Comment on lines +76 to +83
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Consider adding error handling to gracefully manage potential issues during agent initialization or API calls. For example, wrap the agent.start(query) call in a try...except block to catch exceptions and display an error message to the user.

    try:
        result = agent.start(query)
    except Exception as e:
        return f"## Airbnb Search Results\n\nError: {str(e)}"
    return f"## Airbnb Search Results\n\n{result}"


demo = gr.Interface(
fn=search_airbnb,
inputs=gr.Textbox(placeholder="I want to book an apartment in Paris for 2 nights..."),
outputs=gr.Markdown(),
title="Airbnb Booking Assistant",
description="Enter your booking requirements below:"
)

if __name__ == "__main__":
demo.launch()
```

## Features

<CardGroup cols={2}>
Expand Down
22 changes: 22 additions & 0 deletions src/praisonai-agents/ui.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from praisonaiagents import Agent, MCP
import gradio as gr

def search_airbnb(query):
agent = Agent(
instructions="You help book apartments on Airbnb.",
llm="gpt-4o-mini",
tools=MCP("npx -y @openbnb/mcp-server-airbnb --ignore-robots-txt")
Comment on lines +5 to +8
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The LLM and tool configurations are hardcoded. Consider making these configurable via environment variables or a configuration file to allow users to easily change the settings without modifying the code.

    llm = os.getenv("LLM_MODEL", "gpt-4o-mini")
    tools_command = os.getenv("AIRBNB_MCP_COMMAND", "npx -y @openbnb/mcp-server-airbnb --ignore-robots-txt")
    agent = Agent(
        instructions="You help book apartments on Airbnb.",
        llm=llm,
        tools=MCP(tools_command)
    )

)
result = agent.start(query)
return f"## Airbnb Search Results\n\n{result}"
Comment on lines +4 to +11
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Consider adding error handling to gracefully manage potential issues during agent initialization or API calls. For example, wrap the agent.start(query) call in a try...except block to catch exceptions and display an error message to the user.

    try:
        result = agent.start(query)
    except Exception as e:
        return f"## Airbnb Search Results\n\nError: {str(e)}"
    return f"## Airbnb Search Results\n\n{result}"


demo = gr.Interface(
fn=search_airbnb,
inputs=gr.Textbox(placeholder="I want to book an apartment in Paris for 2 nights..."),
outputs=gr.Markdown(),
title="Airbnb Booking Assistant",
description="Enter your booking requirements below:"
)

if __name__ == "__main__":
demo.launch()
Comment on lines +1 to +22
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The Gradio UI code is duplicated in airbnb.mdx and ui.py. Consider creating a reusable function or module to avoid duplication and improve maintainability. You can define the search_airbnb function and Gradio interface in a separate module and import it into both files.

# In a new file, e.g., gradio_app.py:
# def create_gradio_app():
#     from praisonaiagents import Agent, MCP
#     import gradio as gr
#
#     def search_airbnb(query):
#         agent = Agent(
#             instructions="You help book apartments on Airbnb.",
#             llm="gpt-4o-mini",
#             tools=MCP("npx -y @openbnb/mcp-server-airbnb --ignore-robots-txt")
#         )
#         result = agent.start(query)
#         return f"## Airbnb Search Results\n\n{result}"
#
#     demo = gr.Interface(
#         fn=search_airbnb,
#         inputs=gr.Textbox(placeholder="I want to book an apartment in Paris for 2 nights..."),
#         outputs=gr.Markdown(),
#         title="Airbnb Booking Assistant",
#         description="Enter your booking requirements below:"
#     )
#     return demo

# if __name__ == "__main__":
#     demo = create_gradio_app()
#     demo.launch()

# Then, in both airbnb.mdx and ui.py:
# from gradio_app import create_gradio_app
# demo = create_gradio_app()
# if __name__ == "__main__":
#     demo.launch()

Loading