Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into 454-update-fastapi--n…
Browse files Browse the repository at this point in the history
…atsio-adapter-section-with-custom-htmljs-client-implementation
  • Loading branch information
harishmohanraj committed Oct 23, 2024
2 parents ea932ab + 50a365e commit 3af0593
Show file tree
Hide file tree
Showing 25 changed files with 361 additions and 40 deletions.
11 changes: 10 additions & 1 deletion .secrets.baseline
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,15 @@
"is_secret": false
}
],
"docs/docs/en/tutorial/whatsapp/index.md": [
{
"type": "Secret Keyword",
"filename": "docs/docs/en/tutorial/whatsapp/index.md",
"hashed_secret": "52e0d11a70cdb70d4c51064d08bd8f179ebb8bb4",
"is_verified": false,
"line_number": 83
}
],
"docs/docs/en/user-guide/adapters/fastapi_nats/index.md": [
{
"type": "Secret Keyword",
Expand Down Expand Up @@ -194,5 +203,5 @@
}
]
},
"generated_at": "2024-10-22T13:38:29Z"
"generated_at": "2024-10-22T14:15:38Z"
}
3 changes: 2 additions & 1 deletion docs/docs/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ search:
- [Security](user-guide/api/security.md)
- [Testing](user-guide/testing/index.md)
- [CLI](user-guide/cli/index.md)
- Tutorial
- [Tutorial](tutorial/index.md)
- [Giphy API & WebSurfer](tutorial/giphy/index.md)
- [Infobip WhatsApp API & WebSurfer](tutorial/whatsapp/index.md)
- Reference
- API
- fastagency
Expand Down
16 changes: 16 additions & 0 deletions docs/docs/en/tutorial/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Web Scraping and API Integration with FastAgency

In this series of tutorials, you'll learn how to use the **FastAgency** framework to create interactive chatbots that can scrape the web and work with different APIs to respond to user requests.

## What You Will Learn

By the end of these tutorials, you’ll know how to:

- Build agents that can automatically pull information from websites.
- Connect your chatbot to external APIs to add more features.
- Set up workflows that handle conversations between users and agents.
- Keep API communication secure and manage sensitive information.

We'll guide you step-by-step through building these agents, working with APIs, and creating a chatbot that responds to user input with useful and personalized content.

Get ready to explore web scraping and API integration with **FastAgency**!
3 changes: 3 additions & 0 deletions docs/docs/en/tutorial/whatsapp/images/initial_message.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions docs/docs/en/tutorial/whatsapp/images/scraped_info.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions docs/docs/en/tutorial/whatsapp/images/scraping.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions docs/docs/en/tutorial/whatsapp/images/whatsapp.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions docs/docs/en/tutorial/whatsapp/images/whatsapp_api_call.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
282 changes: 282 additions & 0 deletions docs/docs/en/tutorial/whatsapp/index.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/docs/en/user-guide/basics.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ Depending on the interface you choose, you'll need to import different modules.
from autogen.agentchat import ConversableAgent

from fastagency import UI
from fastagency.runtimes.autogen.base import AutoGenWorkflows
from fastagency.runtimes.autogen import AutoGenWorkflows
from fastagency.ui.mesop import MesopUI

from fastagency import FastAgency
Expand Down
3 changes: 2 additions & 1 deletion docs/docs/navigation_template.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ search:
- [Security](user-guide/api/security.md)
- [Testing](user-guide/testing/index.md)
- [CLI](user-guide/cli/index.md)
- Tutorial
- [Tutorial](tutorial/index.md)
- [Giphy API & WebSurfer](tutorial/giphy/index.md)
- [Infobip WhatsApp API & WebSurfer](tutorial/whatsapp/index.md)
- Reference
{api}
{cli}
Expand Down
2 changes: 1 addition & 1 deletion docs/docs_src/getting_started/nats/main_1_nats.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from fastagency import UI
from fastagency.adapters.nats import NatsAdapter
from fastagency.logging import get_logger
from fastagency.runtimes.autogen.autogen import AutoGenWorkflows
from fastagency.runtimes.autogen import AutoGenWorkflows

llm_config = {
"config_list": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from fastagency import UI
from fastagency.adapters.nats import NatsAdapter
from fastagency.runtimes.autogen.autogen import AutoGenWorkflows
from fastagency.runtimes.autogen import AutoGenWorkflows

llm_config = {
"config_list": [
Expand Down
2 changes: 1 addition & 1 deletion docs/docs_src/tutorial/giphy/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from fastagency.api.openapi.security import APIKeyQuery
from fastagency.messages import TextInput
from fastagency.runtimes.autogen.agents.websurfer import WebSurferAgent
from fastagency.runtimes.autogen.autogen import AutoGenWorkflows
from fastagency.runtimes.autogen import AutoGenWorkflows
from fastagency.ui.mesop import MesopUI

llm_config = {
Expand Down
2 changes: 1 addition & 1 deletion docs/docs_src/tutorial/giphy/simple_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from fastagency import UI, FastAgency
from fastagency.api.openapi.client import OpenAPI
from fastagency.api.openapi.security import APIKeyQuery
from fastagency.runtimes.autogen.autogen import AutoGenWorkflows
from fastagency.runtimes.autogen import AutoGenWorkflows
from fastagency.ui.mesop import MesopUI

open_api_key = os.getenv("OPENAI_API_KEY")
Expand Down
43 changes: 20 additions & 23 deletions docs/docs_src/tutorial/whatsapp/main.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import os
from pathlib import Path
from typing import Annotated, Any, Optional

from autogen import register_function
Expand All @@ -9,7 +8,7 @@
from fastagency.api.openapi.client import OpenAPI
from fastagency.api.openapi.security import APIKeyHeader
from fastagency.runtimes.autogen.agents.websurfer import WebSurferAgent
from fastagency.runtimes.autogen.autogen import AutoGenWorkflows
from fastagency.runtimes.autogen import AutoGenWorkflows
from fastagency.ui.mesop import MesopUI

llm_config = {
Expand All @@ -22,21 +21,19 @@
"temperature": 0.8,
}

whatsapp_openapi_path = (
Path(__file__).parent / "../../../../examples/openapi/whatsapp_openapi.json"
)
with whatsapp_openapi_path.open() as f:
openapi_json = f.read()

openapi_url = "https://raw.githubusercontent.com/airtai/fastagency/refs/heads/main/examples/openapi/whatsapp_openapi.json"
whatsapp_api = OpenAPI.create(
openapi_json=openapi_json,
openapi_url=openapi_url,
)

whatsapp_api_key = "App " # pragma: allowlist secret
whatsapp_api_key += os.getenv("WHATSAPP_API_KEY", "")
whatsapp_api.set_security_params(APIKeyHeader.Parameters(value=whatsapp_api_key))
header_authorization = "App " # pragma: allowlist secret
header_authorization += os.getenv("WHATSAPP_API_KEY", "")
whatsapp_api.set_security_params(APIKeyHeader.Parameters(value=header_authorization))

WHATSAPP_SYSTEM_MESSAGE = """You are an agent in charge to communicate with the user and WhatsAPP API.
# This is the default sender number for Infobip.
# If you want to use your own sender, please update the value below:
sender = "447860099299"
WHATSAPP_SYSTEM_MESSAGE = f"""You are an agent in charge to communicate with the user and WhatsAPP API.
Always use 'present_completed_task_or_ask_question' to interact with the user.
- make sure that the 'message' parameter contains all the necessary information for the user!
Initially, the Web_Surfer_Agent will provide you with some content from the web.
Expand All @@ -45,24 +42,24 @@
- "If you want to receive the summary of the page as a WhatsApp message, please provide your number."
When sending the message, the Body must use the following format:
{
"from": "447860099299",
{{
"from": "{sender}",
"to": "receiverNumber",
"messageId": "test-message-randomInt",
"content": {
"content": {{
"text": "message"
},
}},
"callbackData": "Callback data"
}
}}
"from" number is always the same.
"""

wf = AutoGenWorkflows()


@wf.register(name="whatsapp", description="WhatsApp chat")
def whatsapp_workflow(ui: UI, params: dict[str, Any]) -> str:
@wf.register(name="whatsapp_and_websurfer", description="WhatsApp and WebSurfer chat")
def whatsapp_and_websurfer_workflow(ui: UI, params: dict[str, Any]) -> str:
def is_termination_msg(msg: dict[str, Any]) -> bool:
return msg["content"] is not None and "TERMINATE" in msg["content"]

Expand All @@ -71,15 +68,15 @@ def present_completed_task_or_ask_question(
) -> Optional[str]:
try:
return ui.text_input(
sender="whatsapp_agent",
recipient="whatsapp_agent",
sender="Whatsapp_Agent",
recipient="User",
prompt=message,
)
except Exception as e: # pragma: no cover
return f"present_completed_task_or_ask_question() FAILED! {e}"

whatsapp_agent = ConversableAgent(
name="Whatsapp_Agent",
name="WhatsApp_Agent",
system_message=WHATSAPP_SYSTEM_MESSAGE,
llm_config=llm_config,
human_input_mode="NEVER",
Expand Down
2 changes: 1 addition & 1 deletion docs/docs_src/user_guide/custom_user_interactions/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from fastagency import UI, FastAgency
from fastagency.messages import MultipleChoice, SystemMessage, TextInput
from fastagency.runtimes.autogen.autogen import AutoGenWorkflows
from fastagency.runtimes.autogen import AutoGenWorkflows
from fastagency.ui.console import ConsoleUI

llm_config = {
Expand Down
2 changes: 1 addition & 1 deletion docs/docs_src/user_guide/external_rest_apis/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from fastagency import UI, FastAgency
from fastagency.api.openapi import OpenAPI
from fastagency.runtimes.autogen.autogen import AutoGenWorkflows
from fastagency.runtimes.autogen import AutoGenWorkflows
from fastagency.ui.console import ConsoleUI

llm_config = {
Expand Down
2 changes: 1 addition & 1 deletion docs/docs_src/user_guide/external_rest_apis/security.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from fastagency import UI, FastAgency
from fastagency.api.openapi.client import OpenAPI
from fastagency.api.openapi.security import APIKeyHeader
from fastagency.runtimes.autogen.autogen import AutoGenWorkflows
from fastagency.runtimes.autogen import AutoGenWorkflows
from fastagency.ui.console import ConsoleUI

llm_config = {
Expand Down
2 changes: 1 addition & 1 deletion docs/docs_src/user_guide/runtimes/autogen/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from fastagency import UI, FastAgency
from fastagency.api.openapi import OpenAPI
from fastagency.runtimes.autogen.autogen import AutoGenWorkflows
from fastagency.runtimes.autogen import AutoGenWorkflows
from fastagency.ui.console import ConsoleUI

llm_config = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from fastagency import UI, FastAgency
from fastagency.api.openapi import OpenAPI
from fastagency.runtimes.autogen.autogen import AutoGenWorkflows
from fastagency.runtimes.autogen import AutoGenWorkflows
from fastagency.ui.console import ConsoleUI

llm_config = {
Expand Down
2 changes: 1 addition & 1 deletion examples/cli/main_console.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from autogen.agentchat import ConversableAgent

from fastagency import UI, FastAgency
from fastagency.runtimes.autogen.autogen import AutoGenWorkflows
from fastagency.runtimes.autogen import AutoGenWorkflows
from fastagency.ui.console import ConsoleUI

llm_config = {
Expand Down
2 changes: 1 addition & 1 deletion examples/cli/main_mesop.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from autogen.agentchat import ConversableAgent

from fastagency import UI, FastAgency
from fastagency.runtimes.autogen.autogen import AutoGenWorkflows
from fastagency.runtimes.autogen import AutoGenWorkflows
from fastagency.ui.mesop import MesopUI

llm_config = {
Expand Down
2 changes: 1 addition & 1 deletion examples/cli/main_user_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from fastagency import UI, FastAgency
from fastagency.api.openapi.client import OpenAPI
from fastagency.api.openapi.security import APIKeyHeader
from fastagency.runtimes.autogen.autogen import AutoGenWorkflows
from fastagency.runtimes.autogen import AutoGenWorkflows
from fastagency.ui.console import ConsoleUI

llm_config = {
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/mesop/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from fastagency.app import FastAgency
from fastagency.messages import TextMessage
from fastagency.runtimes.autogen.autogen import AutoGenWorkflows
from fastagency.runtimes.autogen import AutoGenWorkflows

if sys.version_info >= (3, 10):
from fastagency.ui.mesop.mesop import MesopUI
Expand Down

0 comments on commit 3af0593

Please sign in to comment.