mirror of
https://github.com/agent0ai/agent-zero.git
synced 2026-05-11 04:49:57 +00:00
commit b05d44bb4bc9e07cfc0b584ab39e8624bae771fb
Author: frdel <38891707+frdel@users.noreply.github.com>
Date: Sun Nov 17 23:12:00 2024 +0100
searxng, RFC, docker runtime
commit c90fd4026e644d22e6c7dc29639c85eee6026828
Author: frdel <38891707+frdel@users.noreply.github.com>
Date: Sat Nov 16 21:21:49 2024 +0100
Remote function calling
commit f71d45ec7dbff4e2d3209f0efe97804f6e602fe7
Author: frdel <38891707+frdel@users.noreply.github.com>
Date: Fri Nov 15 13:13:09 2024 +0100
Fix for bool arg parsing
commit 936768d1d8efc9060494334b87f400c933d78048
Author: frdel <38891707+frdel@users.noreply.github.com>
Date: Fri Nov 15 13:01:28 2024 +0100
Dynamic runtime args parsing
commit 00c915fc6c1f8f00f8176fbf5b77af32fa312d18
Author: frdel <38891707+frdel@users.noreply.github.com>
Date: Fri Nov 15 12:13:58 2024 +0100
API key fix
commit 504a7f91789caa16578af8bae9b7936a9d7fbbb7
Author: frdel <38891707+frdel@users.noreply.github.com>
Date: Fri Nov 15 11:59:41 2024 +0100
API keys JIT loading
commit 5678a2fce2d333454bb1a2e94ca2b5916d321b41
Author: frdel <38891707+frdel@users.noreply.github.com>
Date: Fri Nov 15 11:27:12 2024 +0100
Update dotenv.py
54 lines
No EOL
1.4 KiB
Python
54 lines
No EOL
1.4 KiB
Python
import importlib
|
|
import inspect
|
|
import json
|
|
from typing import Any, TypedDict
|
|
import aiohttp
|
|
|
|
# Remote Function Call library
|
|
# Call function via http request
|
|
|
|
class RFCInput(TypedDict):
|
|
module: str
|
|
function_name: str
|
|
args: list[Any]
|
|
kwargs: dict[str, Any]
|
|
|
|
|
|
async def call_rfc(url: str, module: str, function_name: str, args: list, kwargs: dict):
|
|
input = {
|
|
"module": module,
|
|
"function_name": function_name,
|
|
"args": args,
|
|
"kwargs": kwargs,
|
|
}
|
|
input_json = json.dumps(input)
|
|
result = await _send_json_data(url, input_json)
|
|
return result
|
|
|
|
|
|
async def handle_rfc(input: RFCInput):
|
|
return await _call_function(
|
|
input["module"], input["function_name"], *input["args"], **input["kwargs"]
|
|
)
|
|
|
|
|
|
async def _call_function(module: str, function_name: str, *args, **kwargs):
|
|
func = _get_function(module, function_name)
|
|
if inspect.iscoroutinefunction(func):
|
|
return await func(*args, **kwargs)
|
|
else:
|
|
return func(*args, **kwargs)
|
|
|
|
|
|
def _get_function(module: str, function_name: str):
|
|
# import module
|
|
imp = importlib.import_module(module)
|
|
# get function by the name
|
|
func = getattr(imp, function_name)
|
|
return func
|
|
|
|
|
|
async def _send_json_data(url: str, data: str):
|
|
async with aiohttp.ClientSession() as session:
|
|
async with session.post(url, json=data) as response:
|
|
return await response.json() |