-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from fetchai/feat/new-endpoints-integration-an…
…d-tools new endpoints integrations + tools
- Loading branch information
Showing
8 changed files
with
250 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
on: | ||
push: | ||
branches: | ||
- main | ||
- master | ||
pull_request: | ||
branches: | ||
- main | ||
- master | ||
|
||
jobs: | ||
test: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import argparse | ||
import asyncio | ||
import os | ||
from pprint import pprint | ||
|
||
from ai_engine_sdk import AiEngine | ||
|
||
|
||
async def main(target_environment: str, agentverse_api_key: str, function_groups: list[str]): | ||
# Request from cli args. | ||
options = {} | ||
if target_environment: | ||
options = {"api_base_url": target_environment} | ||
|
||
c = AiEngine(api_key=agentverse_api_key, options=options) | ||
|
||
for function_group in function_groups: | ||
print(f"======= function_group: {function_group} =======") | ||
user_functions = await c.get_functions_by_function_group(function_group_id=function_group) | ||
pprint(user_functions) | ||
print("-----") | ||
|
||
|
||
if __name__ == '__main__': | ||
from dotenv import load_dotenv | ||
load_dotenv() | ||
api_key = os.getenv("AV_API_KEY", "") | ||
|
||
parser = argparse.ArgumentParser() | ||
parser.add_argument( | ||
"-e", | ||
"--target_environment", | ||
type=str, | ||
required=False, | ||
help="The target environment: staging, localhost, production... You need to explicitly add the domain. By default it will be production." | ||
) | ||
parser.add_argument( | ||
"-fgs", | ||
"--function_groups", | ||
nargs="+", | ||
required=True, | ||
help="List of function groups ids to get their functions." | ||
) | ||
args = parser.parse_args() | ||
|
||
target_environment = args.target_environment | ||
function_groups: list[str] = args.function_groups | ||
|
||
asyncio.run(main(agentverse_api_key=api_key, target_environment=target_environment, function_groups=function_groups)) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
import argparse | ||
import asyncio | ||
import os | ||
from pprint import pprint | ||
|
||
from ai_engine_sdk import AiEngine, FunctionGroup | ||
from dotenv import load_dotenv | ||
|
||
load_dotenv() | ||
AV_API_KEY=os.getenv("AV_API_KEY", "") | ||
|
||
|
||
async def get_functions_groups_by_user( | ||
client: AiEngine, | ||
) -> list[FunctionGroup]: | ||
return await client.get_function_groups() | ||
|
||
async def get_fgs_by_function(client: AiEngine, function_id: str) -> list[FunctionGroup]: | ||
return await client.get_function_group_by_function(function_id) | ||
|
||
def render(data: list[FunctionGroup], field: str) -> list: | ||
result = [] | ||
if field: | ||
for i in data: | ||
# item = {f: i.__getattribute__(f) for f in fields} | ||
# result.append(item) | ||
result.append(i.__getattribute__(field)) | ||
else: | ||
result = data | ||
pprint(result) | ||
|
||
|
||
if __name__ == "__main__": | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument( | ||
"-e", | ||
"--target_environment", | ||
type=str, | ||
required=False, | ||
help="The target environment: staging, localhost, production... You need to explicitly add the domain. By default it will be production." | ||
) | ||
parser.add_argument( | ||
"-by", | ||
"--get-by", | ||
type=str, | ||
help="You can get function groups by: function, user", | ||
default="user", | ||
required=False | ||
) | ||
parser.add_argument( | ||
"-by-v", | ||
"--get-by-value", | ||
type=str, | ||
help="Value of the field you want filter by (if user do not provide anything)", | ||
required=False | ||
) | ||
# parser.add_argument( | ||
# "-f", | ||
# "--filter", | ||
# required=False, | ||
# nargs="+", | ||
# help="You can ask for returning just a list of a concrete field." | ||
# ) | ||
parser.add_argument( | ||
"-f", | ||
"--filter", | ||
required=False, | ||
type=str, | ||
help="You can ask for returning just a list of a concrete field." | ||
) | ||
args = parser.parse_args() | ||
target_environment = args.target_environment | ||
filter_fields = args.filter | ||
get_by = args.get_by | ||
options = {} | ||
if target_environment: | ||
options = {"api_base_url": target_environment} | ||
|
||
|
||
c = AiEngine(api_key=AV_API_KEY, options=options) | ||
|
||
if get_by == "function": | ||
function_id = args.get_by_value | ||
function_to_execute = get_fgs_by_function(client=c, function_id=function_id) | ||
elif get_by == "user": | ||
function_to_execute = get_functions_groups_by_user(client=c) | ||
result = asyncio.run(function_to_execute) | ||
print(filter_fields) | ||
|
||
|
||
render(data=result, field=filter_fields) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import pytest | ||
|
||
from ai_engine_sdk.client import Session | ||
|
||
|
||
# class TestSessionClient: | ||
# @pytest.mark.asyncio | ||
# async def test_start_session_with_execute_functions(self, session_with_next_generation_model: Session): | ||
# # TODO: we need to define the function ids related to the function-group related to the user test. | ||
# session_with_next_generation_model.execute_function(function_ids=..., objective=..., context=...) | ||
# | ||
# |