Skip to content

Commit

Permalink
added friendly stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
om-raheja committed Aug 20, 2024
1 parent cde3f21 commit 1920126
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 51 deletions.
2 changes: 1 addition & 1 deletion _exec.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def start_server():
print("Server started")

def stop_server():
global server
global serverge
if server:
server.should_exit = True
server.force_exit = True
Expand Down
6 changes: 6 additions & 0 deletions docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,9 @@ Documentation
agent_developer/agents/agent_index
agent_developer/agent_database
agent_developer/external_tools/tool_index

.. toctree::
:maxdepth: 2
:caption: For WebUI Developers

webui_developer/webui_index
25 changes: 25 additions & 0 deletions docs/source/webui_developer/webui_index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
.. _agent_database:

Web UI
==============

You can interact with the web UI through the frontend, and the command line.

Here is a curl example:

.. code-block:: bash
curl -X POST "http://localhost:8000/add_agent" \
-H "accept: application/json" \
-d "{ \"agent_name\": \"example/transcribe_agent\", \
\"task_input\": \"Listen to me for a few seconds then respond to me\" }"
Then you get a process PID, which you can execute at will:

.. code-block:: bash
curl -G -d "pid=1234" "http://localhost:8000/execute_agent"
You can also list all agents:

.. code-block:: bash
curl "http://localhost:8000/get_all_agents"
17 changes: 14 additions & 3 deletions pyopenagi/agents/example/transcribe_agent/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,19 @@ def __init__(self,
log_mode: str
):
ReactAgent.__init__(self, agent_name, task_input, agent_process_factory, log_mode)
self.workflow_mode = "automatic"
self.workflow_mode = "manual"
def manual_workflow(self):
pass
workflow = [
{
"message": "figure out what to do with the audio",
"tool_use": [ "transcriber"],
},
{
"message": "organize the information and respond to the user",
"tool_use": [ ],
},
]
return workflow

def run(self):
return super().run()
return super().run()
65 changes: 27 additions & 38 deletions pyopenagi/agents/react_agent.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
# Where the internal agent handling is done
# to prevent excessive boilerplate in each agent
# TODO: not venv friendly


from .base_agent import BaseAgent

Expand Down Expand Up @@ -36,27 +32,28 @@ def build_system_instruction(self):
]
)

plan_instruction = f"""
You are given the available tools from the tool list: {json.dumps(self.tool_info)} to help you solve problems.
Generate a plan of steps you need to take.
The plan must follow the json format as:
[
{{"message": "message_value1","tool_use": [tool_name1, tool_name2,...]}},
{{"message": "message_value2", "tool_use": [tool_name1, tool_name2,...]}}
...
]
In each step of the planned workflow, you must select the most related tool to use
Followings are some plan examples:
[
{{"message": "gather information from arxiv. ", "tool_use": ["arxiv"]}},
{{"message", "write a summarization based on the gathered information. ", "tool_use": []}}
];
[
{{"message": "identify the tool that you need to call to obtain information. ", "tool_use": ["imdb_top_movies", "imdb_top_series"]}},
{{"message", "give recommendations for the user based on the information. ", "tool_use": []}}
];
Your outputs are restricted to only JSON format.
"""
plan_instruction = "".join(
[
f'You are given the available tools from the tool list: {json.dumps(self.tool_info)} to help you solve problems. ',
'Generate a plan of steps you need to take. ',
'The plan must follow the json format as: ',
'[',
'{"message": "message_value1","tool_use": [tool_name1, tool_name2,...]}',
'{"message": "message_value2", "tool_use": [tool_name1, tool_name2,...]}',
'...',
']',
'In each step of the planned workflow, you must select the most related tool to use',
'Followings are some plan examples:',
'[',
'{"message": "gather information from arxiv. ", "tool_use": ["arxiv"]},',
'{"message", "write a summarization based on the gathered information. ", "tool_use": []}',
'];',
'[',
'{"message": "identify the tool that you need to call to obtain information. ", "tool_use": ["imdb_top_movies", "imdb_top_series"]},',
'{"message", "give recommendations for the user based on the information. ", "tool_use": []}',
'];',
]
)

if self.workflow_mode == "manual":
self.messages.append(
Expand All @@ -74,7 +71,6 @@ def automatic_workflow(self):
return super().automatic_workflow()

def manual_workflow(self):
""" to be implemented """
pass

def call_tools(self, tool_calls):
Expand All @@ -91,15 +87,9 @@ def call_tools(self, tool_calls):
function_params = tool_call["parameters"]

try:
# printed in both scenarios for easier debugging
function_response = function_to_call.run(function_params)
actions.append(f"I will call the {function_name} with the params as {function_params}")
<<<<<<< HEAD
observations.append(f"The output of calling the {function_name} tool is: {function_response}")
=======

function_response = function_to_call.run(function_params)
observations.append(f"The knowledge I get from {function_name} is: {function_response}")
>>>>>>> 42ec671 (added useful docs and claned code-made some parts work)

except Exception:
actions.append("I fail to call any tools.")
Expand Down Expand Up @@ -134,7 +124,10 @@ def run(self):
{"role": "user", "content": "[Thinking]: Follow the workflow to solve the problem step by step. "}
)

self.logger.log(f"Generated workflow is: {workflow}\n", level="info")
if workflow:
self.logger.log(f"Generated workflow is: {workflow}\n", level="info")
else:
self.logger.log(f"Fail to generate a valid workflow. Invalid JSON? workflow: {workflow}\n", level="info")

try:
if workflow:
Expand All @@ -155,16 +148,12 @@ def run(self):
else:
selected_tools = None

<<<<<<< HEAD
response, start_times, end_times, waiting_times, turnaround_times = self.get_response(
query = Query(
messages = self.messages,
tools = selected_tools
)
)
=======
self.logger.log(f"At step {i + 1}, {self.messages[-1]['content']}\n", level="info")
>>>>>>> 42ec671 (added useful docs and claned code-made some parts work)

if self.rounds == 0:
self.set_start_time(start_times[0])
Expand Down
2 changes: 1 addition & 1 deletion pyopenagi/tools/transcriber/transcriber.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from ..base import BaseTool
from time import sleep

class CurrencyConverter(BaseTool):
class Transcriber(BaseTool):
def __init__(self):
""" big library, not everyone needs it installed """
try:
Expand Down
9 changes: 1 addition & 8 deletions server.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
from dotenv import load_dotenv
import atexit

from _exec import start_server, stop_server

load_dotenv()

app = FastAPI()
Expand Down Expand Up @@ -120,6 +118,7 @@ async def execute_agent(
'response': response
}
except Exception as e:
print("Got an exception while executing agent: ", e)
return {
'success': False,
'exception': f"{e}"
Expand Down Expand Up @@ -159,9 +158,3 @@ def cleanup():
stopScheduler()

atexit.register(cleanup)

if __name__ == '__main__':
start_server()

# when CTRL+C
stop_server()

0 comments on commit 1920126

Please sign in to comment.