Skip to content

Commit

Permalink
Update app.py
Browse files Browse the repository at this point in the history
format
  • Loading branch information
Shuyib authored Nov 29, 2024
1 parent a7672be commit 56f8503
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@
},
]


async def process_user_message(message: str, history: list) -> str:
"""
Handle the conversation with the model asynchronously.
Expand Down Expand Up @@ -196,9 +197,7 @@ async def process_user_message(message: str, history: list) -> str:
)
elif tool_name == "search_news":
logger.info("Calling search_news with arguments: %s", arguments)
function_response = search_news(
arguments["query"]
)
function_response = search_news(arguments["query"])
else:
function_response = json.dumps({"error": "Unknown function"})

Expand All @@ -214,6 +213,7 @@ async def process_user_message(message: str, history: list) -> str:
else:
return model_content


def gradio_interface(message: str, history: list) -> str:
"""
Gradio interface function to process user messages and track emissions.
Expand All @@ -233,6 +233,7 @@ def gradio_interface(message: str, history: list) -> str:
response = asyncio.run(process_user_message(message, history))
return response


# Create Gradio interface
iface = gr.ChatInterface(
fn=gradio_interface,
Expand All @@ -247,9 +248,11 @@ def gradio_interface(message: str, history: list) -> str:
),
examples=[
["Send airtime to +254712345678 with an amount of 10 in currency KES"],
["Send a message to +254712345678 with the message 'Hello there', using the username 'username'"],
[
"Send a message to +254712345678 with the message 'Hello there', using the username 'username'"
],
["Search news for 'latest technology trends'"],
]
],
)

# Launch the Gradio interface
Expand Down

0 comments on commit 56f8503

Please sign in to comment.