diff --git a/README.md b/README.md index 001600c..ae79fce 100644 --- a/README.md +++ b/README.md @@ -34,8 +34,6 @@ The folder needs to be the following structure: If you want to use external tools provided by openagi in your agents, you can follow instructions of setting up tools in [How to setup external tools](./tools.md). If you want to add new tools for your developing agent, you need to add a new tool file in the [folder](./pyopenagi/tools/). -- Offline tools: locally-deployed models like stable-diffusion model -- Online tools: APIs like rapid api. #### Upload agent If you have developed and tested your agent, and you would like to share your agents, you can use the following to upload your agents @@ -45,7 +43,7 @@ python pyopenagi/agents/interact.py --mode upload --agent ``` diff --git a/pyopenagi/agents/agent_factory.py b/pyopenagi/agents/agent_factory.py index 1189118..ea00a59 100755 --- a/pyopenagi/agents/agent_factory.py +++ b/pyopenagi/agents/agent_factory.py @@ -1,16 +1,18 @@ -from datetime import datetime import heapq -from concurrent.futures import ThreadPoolExecutor, as_completed -from threading import Thread, Lock, Event +from threading import Lock, Event from pympler import asizeof from .interact import Interactor, list_available_agents import os import importlib class AgentFactory: - def __init__(self, llm, agent_process_queue, agent_process_factory, agent_log_mode): + def __init__(self, + agent_process_queue, + agent_process_factory, + agent_log_mode + ): self.max_aid = 256 - self.llm = llm + # self.llm = llm self.aid_pool = [i for i in range(self.max_aid)] heapq.heapify(self.aid_pool) self.agent_process_queue = agent_process_queue @@ -60,8 +62,6 @@ def activate_agent(self, agent_name, task_input): agent = agent_class( agent_name = agent_name, task_input = task_input, - llm = self.llm, - agent_process_queue = self.agent_process_queue, agent_process_factory = self.agent_process_factory, log_mode = self.agent_log_mode ) diff --git a/pyopenagi/agents/agent_process.py b/pyopenagi/agents/agent_process.py index 281bf4e..83d5485 100755 --- a/pyopenagi/agents/agent_process.py +++ b/pyopenagi/agents/agent_process.py @@ -1,25 +1,13 @@ -import os - -import time - -from queue import Queue - -from datetime import datetime - import heapq -from concurrent.futures import ThreadPoolExecutor, as_completed - from threading import Thread, Lock, Event -from pympler import asizeof - from ..utils.chat_template import Query class AgentProcess: def __init__(self, agent_name, - query + query: Query ): self.agent_name = agent_name self.query = query @@ -79,6 +67,10 @@ def get_time_limit(self): def set_time_limit(self, time_limit): self.time_limit = time_limit + +class LLMRequestProcess(AgentProcess): + pass + class AgentProcessFactory: def __init__(self, agent_process_log_mode = None): self.max_pid = 1024 diff --git a/pyopenagi/agents/base_agent.py b/pyopenagi/agents/base_agent.py index 7cebb96..35b0502 100755 --- a/pyopenagi/agents/base_agent.py +++ b/pyopenagi/agents/base_agent.py @@ -3,26 +3,21 @@ import json from .agent_process import ( - AgentProcess, - # AgentProcessQueue + AgentProcess ) -import logging - import time from threading import Thread -from datetime import datetime - -import numpy as np - from ..utils.logger import AgentLogger from ..utils.chat_template import Query import importlib +from ..queues.llm_request_queue import LLMRequestQueue + class CustomizedThread(Thread): def __init__(self, target, args=()): super().__init__() @@ -41,8 +36,6 @@ class BaseAgent: def __init__(self, agent_name, task_input, - llm, - agent_process_queue, agent_process_factory, log_mode: str ): @@ -50,10 +43,8 @@ def __init__(self, self.config = self.load_config() self.tool_names = self.config["tools"] - - self.llm = llm - self.agent_process_queue = agent_process_queue self.agent_process_factory = agent_process_factory + self.tool_list = dict() self.tools = [] self.load_tools(self.tool_names) @@ -69,7 +60,7 @@ def __init__(self, self.log_mode = log_mode self.logger = self.setup_logger() - self.logger.log(f"Initialized. \n", level="info") + self.logger.log("Initialized. \n", level="info") self.set_status("active") self.set_created_time(time.time()) @@ -85,6 +76,7 @@ def build_system_instruction(self): def check_workflow(self, message): try: + # print(f"Workflow message: {message}") workflow = json.loads(message) if not isinstance(workflow, list): return None @@ -103,7 +95,8 @@ def automatic_workflow(self): response, start_times, end_times, waiting_times, turnaround_times = self.get_response( query = Query( messages = self.messages, - tools = None + tools = None, + message_return_type="json" ) ) @@ -139,19 +132,25 @@ def snake_to_camel(self, snake_str): def load_tools(self, tool_names): for tool_name in tool_names: org, name = tool_name.split("/") - module_name = ".".join(["pyopenagi", "tools", org, name]) - class_name = self.snake_to_camel(name) tool_module = importlib.import_module(module_name) - tool_class = getattr(tool_module, class_name) self.tool_list[name] = tool_class() - self.tools.append(tool_class().get_tool_call_format()) + def pre_select_tools(self, tool_names): + pre_selected_tools = [] + for tool_name in tool_names: + for tool in self.tools: + if tool["function"]["name"] == tool_name: + pre_selected_tools.append(tool) + break + + return pre_selected_tools + def setup_logger(self): logger = AgentLogger(self.agent_name, self.log_mode) return logger @@ -184,7 +183,7 @@ def query_loop(self, query): # reinitialize agent status agent_process.set_created_time(current_time) agent_process.set_response(None) - self.agent_process_queue.put(agent_process) + LLMRequestQueue.add_message(agent_process) thread.start() thread.join() @@ -206,7 +205,7 @@ def query_loop(self, query): turnaround_times.append(turnaround_time) # Re-start the thread if not done - self.agent_process_factory.deactivate_agent_process(agent_process.get_pid()) + # self.agent_process_factory.deactivate_agent_process(agent_process.get_pid()) return completed_response, start_times, end_times, waiting_times, turnaround_times @@ -219,7 +218,7 @@ def create_agent_request(self, query): # print("Already put into the queue") return agent_process - def listen(self, agent_process): + def listen(self, agent_process: AgentProcess): """Response Listener for agent Args: diff --git a/pyopenagi/agents/example/academic_agent/agent.py b/pyopenagi/agents/example/academic_agent/agent.py index ecc4684..f2cf121 100755 --- a/pyopenagi/agents/example/academic_agent/agent.py +++ b/pyopenagi/agents/example/academic_agent/agent.py @@ -4,12 +4,10 @@ class AcademicAgent(ReactAgent): def __init__(self, agent_name, task_input, - llm, - agent_process_queue, agent_process_factory, log_mode: str ): - ReactAgent.__init__(self, agent_name, task_input, llm, agent_process_queue, agent_process_factory, log_mode) + ReactAgent.__init__(self, agent_name, task_input, agent_process_factory, log_mode) self.workflow_mode = "automatic" def manual_workflow(self): diff --git a/pyopenagi/agents/example/creation_agent/agent.py b/pyopenagi/agents/example/creation_agent/agent.py index 03f6efb..9d2b0de 100755 --- a/pyopenagi/agents/example/creation_agent/agent.py +++ b/pyopenagi/agents/example/creation_agent/agent.py @@ -1,14 +1,12 @@ from ...react_agent import ReactAgent -class AcademicAgent(ReactAgent): +class CreationAgent(ReactAgent): def __init__(self, agent_name, task_input, - llm, - agent_process_queue, agent_process_factory, log_mode: str ): - ReactAgent.__init__(self, agent_name, task_input, llm, agent_process_queue, agent_process_factory, log_mode) + ReactAgent.__init__(self, agent_name, task_input, agent_process_factory, log_mode) self.workflow_mode = "automatic" def automatic_workflow(self): diff --git a/pyopenagi/agents/example/math_agent/agent.py b/pyopenagi/agents/example/math_agent/agent.py index 743ed9c..9349926 100755 --- a/pyopenagi/agents/example/math_agent/agent.py +++ b/pyopenagi/agents/example/math_agent/agent.py @@ -4,11 +4,10 @@ class MathAgent(ReactAgent): def __init__(self, agent_name, task_input, - llm, agent_process_queue, agent_process_factory, log_mode: str ): - ReactAgent.__init__(self, agent_name, task_input, llm, agent_process_queue, agent_process_factory, log_mode) + ReactAgent.__init__(self, agent_name, task_input, agent_process_factory, log_mode) def automatic_workflow(self): return super().automatic_workflow() diff --git a/pyopenagi/agents/example/rec_agent/agent.py b/pyopenagi/agents/example/rec_agent/agent.py index 16ed280..4a88a2e 100755 --- a/pyopenagi/agents/example/rec_agent/agent.py +++ b/pyopenagi/agents/example/rec_agent/agent.py @@ -1,17 +1,14 @@ from ...react_agent import ReactAgent -import numpy as np class RecAgent(ReactAgent): def __init__(self, agent_name, task_input, - llm, - agent_process_queue, agent_process_factory, log_mode ): - ReactAgent.__init__(self, agent_name, task_input, llm, agent_process_queue, agent_process_factory, log_mode) + ReactAgent.__init__(self, agent_name, task_input, agent_process_factory, log_mode) def automatic_workflow(self): return super().automatic_workflow() @@ -20,7 +17,7 @@ def manual_workflow(self): workflow = [ { "message": "identify the tool that you need to call to obtain information.", - "tool_use": ["imdb_top_movies", "imdb_top_series"] + "tool_use": ["imdb/top_movies", "imdb/top_series"] }, { "message": "based on the information, give recommendations for the user based on the constrains. ", diff --git a/pyopenagi/agents/example/travel_agent/agent.py b/pyopenagi/agents/example/travel_agent/agent.py index 4f45e90..a6b6d7c 100755 --- a/pyopenagi/agents/example/travel_agent/agent.py +++ b/pyopenagi/agents/example/travel_agent/agent.py @@ -3,11 +3,10 @@ class TravelAgent(ReactAgent): def __init__(self, agent_name, task_input, - llm, agent_process_queue, agent_process_factory, log_mode: str ): - ReactAgent.__init__(self, agent_name, task_input, llm, agent_process_queue, agent_process_factory, log_mode) + ReactAgent.__init__(self, agent_name, task_input, agent_process_factory, log_mode) def automatic_workflow(self): return super().automatic_workflow() diff --git a/pyopenagi/agents/interact.py b/pyopenagi/agents/interact.py index dbbed94..fb302c6 100644 --- a/pyopenagi/agents/interact.py +++ b/pyopenagi/agents/interact.py @@ -169,7 +169,14 @@ def check_reqs_installed(self, agent): result = subprocess.run(['conda', 'list'], stdout=subprocess.PIPE, stderr=subprocess.PIPE) # Decode the output from bytes to string with open(reqs_path, "r") as f: - reqs = f.readlines() + reqs = [] + lines = f.readlines() + for line in lines: + line = line.replace("\n", "") + if "==" in line: + reqs.append(line.split("==")[0]) + else: + reqs.append(line) output = result.stdout.decode('utf-8') @@ -211,11 +218,11 @@ def parse_args(): agent = args.agent client = Interactor() - client.check_reqs_installed(agent) + # client.check_reqs_installed(agent) # client = Interactor() - # if mode == "download": - # client.download_agent(agent) # download agents + if mode == "download": + client.download_agent(agent) # download agents - # else: - # assert mode == "upload" - # client.upload_agent(agent) # upload agents + else: + assert mode == "upload" + client.upload_agent(agent) # upload agents diff --git a/pyopenagi/agents/react_agent.py b/pyopenagi/agents/react_agent.py index 492c7d5..f6819e5 100644 --- a/pyopenagi/agents/react_agent.py +++ b/pyopenagi/agents/react_agent.py @@ -3,16 +3,6 @@ import time -from .agent_process import ( - AgentProcess -) - -import numpy as np - -import argparse - -from concurrent.futures import as_completed - from ..utils.chat_template import Query import json @@ -21,12 +11,16 @@ class ReactAgent(BaseAgent): def __init__(self, agent_name, task_input, - llm, - agent_process_queue, agent_process_factory, log_mode: str ): - BaseAgent.__init__(self, agent_name, task_input, llm, agent_process_queue, agent_process_factory, log_mode) + BaseAgent.__init__( + self, + agent_name, + task_input, + agent_process_factory, + log_mode + ) # self.tool_list = {} @@ -45,27 +39,27 @@ def build_system_instruction(self): 'Generate a plan of steps you need to take.', 'The plan must follow the json format as: ', '[', - '{"message1": "message_value1","tool_use": [tool_name1, tool_name2,...]}', - '{"message2": "message_value2", "tool_use": [tool_name1, tool_name2,...]}', + '{"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', - 'Plan examples can be:', + 'Followings are some plan examples:', '[', '{"message": "Gather information from arxiv", "tool_use": ["arxiv"]},', - '{"message", "Based on the gathered information, write a summarization", "tool_use": None}', + '{"message", "Based on the gathered information, write a summarization", "tool_use": []}', '];', '[', '{"message": "identify the tool that you need to call to obtain information.", "tool_use": ["imdb_top_movies", "imdb_top_series"]},', - '{"message", "based on the information, give recommendations for the user based on the constrains.", "tool_use": None}', + '{"message", "based on the information, give recommendations for the user based on the constrains.", "tool_use": []}', '];', '[', '{"message": "identify the tool that you need to call to obtain information.", "tool_use": ["imdb_top_movies", "imdb_top_series"]},', - '{"message", "based on the information, give recommendations for the user based on the constrains.", "tool_use": None}', + '{"message", "based on the information, give recommendations for the user based on the constrains.", "tool_use": []}', '];', '[', '{"message": "identify the tool that you need to call to obtain information.", "tool_use": ["imdb_top_movies", "imdb_top_series"]},' - '{"message", "based on the information, give recommendations for the user based on the constrains.", "tool_use": None}', + '{"message", "based on the information, give recommendations for the user based on the constrains.", "tool_use": []}', ']' ] ) @@ -151,18 +145,24 @@ def run(self): message = step["message"] tool_use = step["tool_use"] - prompt = f"At step {self.rounds + 1}, you need to {message}. " + # print(f"message: {message}") + # print(f"tool use: {tool_use}") + + prompt = f"At step {i + 1}, you need to {message}. " self.messages.append({ "role": "user", "content": prompt }) + if tool_use: + selected_tools = self.pre_select_tools(tool_use) - used_tools = self.tools if tool_use else None + else: + selected_tools = None response, start_times, end_times, waiting_times, turnaround_times = self.get_response( query = Query( messages = self.messages, - tools = used_tools + tools = selected_tools ) ) if self.rounds == 0: @@ -177,7 +177,7 @@ def run(self): self.request_turnaround_times.extend(turnaround_times) if tool_calls: - for i in range(self.plan_max_fail_times): + for _ in range(self.plan_max_fail_times): actions, observations, success = self.call_tools(tool_calls=tool_calls) action_messages = "[Action]: " + ";".join(actions) @@ -201,7 +201,7 @@ def run(self): if i == len(workflow) - 1: final_result = self.messages[-1] - self.logger.log(f"At step {self.rounds + 1}, {self.messages[-1]}\n", level="info") + self.logger.log(f"At step {i + 1}, {self.messages[-1]}\n", level="info") self.rounds += 1 diff --git a/pyopenagi/queues/base_queue.py b/pyopenagi/queues/base_queue.py new file mode 100644 index 0000000..377f693 --- /dev/null +++ b/pyopenagi/queues/base_queue.py @@ -0,0 +1,17 @@ +import queue + +class BaseQueue: + + _queue = queue.Queue() + + @classmethod + def add_message(cls, message): + cls._queue.put(message) + + @classmethod + def get_message(cls): + return cls._queue.get(block=True, timeout=1) + + @classmethod + def is_empty(cls): + return cls._queue.empty() diff --git a/pyopenagi/queues/llm_request_queue.py b/pyopenagi/queues/llm_request_queue.py new file mode 100644 index 0000000..3555f5c --- /dev/null +++ b/pyopenagi/queues/llm_request_queue.py @@ -0,0 +1,4 @@ +from .base_queue import BaseQueue + +class LLMRequestQueue(BaseQueue): + pass diff --git a/pyopenagi/tools/arxiv/arxiv.py b/pyopenagi/tools/arxiv/arxiv.py index 5a12739..258f3a5 100644 --- a/pyopenagi/tools/arxiv/arxiv.py +++ b/pyopenagi/tools/arxiv/arxiv.py @@ -1,12 +1,11 @@ -import logging -import os import re -from typing import Any, Dict, Iterator, List, Optional from ..base import BaseTool import arxiv +from typing import Optional + class Arxiv(BaseTool): """Arxiv Tool, refactored from Langchain. diff --git a/pyopenagi/tools/base.py b/pyopenagi/tools/base.py index 927c2ba..aa99c5f 100644 --- a/pyopenagi/tools/base.py +++ b/pyopenagi/tools/base.py @@ -1,4 +1,3 @@ -from pyopenagi.utils.utils import get_from_env import json class BaseTool: diff --git a/pyopenagi/tools/bing/bing_search.py b/pyopenagi/tools/bing/bing_search.py index c41f559..ae5ed62 100644 --- a/pyopenagi/tools/bing/bing_search.py +++ b/pyopenagi/tools/bing/bing_search.py @@ -1,9 +1,8 @@ -from typing import Dict, List - import requests from ..base import BaseTool +from typing import List # from pydantic import root_validator from pyopenagi.utils.utils import get_from_env diff --git a/pyopenagi/tools/currency_converter/currency_converter.py b/pyopenagi/tools/currency_converter/currency_converter.py index 69fd70b..22b1afc 100644 --- a/pyopenagi/tools/currency_converter/currency_converter.py +++ b/pyopenagi/tools/currency_converter/currency_converter.py @@ -1,13 +1,9 @@ from ..base import BaseRapidAPITool -from typing import Any, Dict, List, Optional - from pyopenagi.utils.utils import get_from_env import requests -import os - class CurrencyConverter(BaseRapidAPITool): def __init__(self): super().__init__() diff --git a/pyopenagi/tools/google/google_search.py b/pyopenagi/tools/google/google_search.py index 27464fa..d7a6140 100644 --- a/pyopenagi/tools/google/google_search.py +++ b/pyopenagi/tools/google/google_search.py @@ -1,11 +1,9 @@ -from typing import Any, Dict, List, Optional - from ..base import BaseTool -from pydantic import root_validator - from pyopenagi.utils.utils import get_from_env +from typing import List, Any + class GoogleSearch(BaseTool): """Google Search Tool, refactored from langchain. diff --git a/pyopenagi/tools/imdb/top_movies.py b/pyopenagi/tools/imdb/top_movies.py new file mode 100644 index 0000000..6d0bde4 --- /dev/null +++ b/pyopenagi/tools/imdb/top_movies.py @@ -0,0 +1,63 @@ +from ..base import BaseRapidAPITool + +# from pydantic import root_validator + +from pyopenagi.utils.utils import get_from_env + +import requests + +class TopMoviesAPI(BaseRapidAPITool): + def __init__(self): + super().__init__() + self.url = "https://imdb-top-100-movies.p.rapidapi.com/" + self.host_name = "imdb-top-100-movies.p.rapidapi.com" + + self.api_key = get_from_env("RAPID_API_KEY") + + def run(self, params): + start = int(params["start"]) if "start" in params else 1 + end = int(params["end"]) + headers = { + "X-RapidAPI-Key": self.api_key, + "X-RapidAPI-Host": self.host_name + } + response = requests.get(self.url, headers=headers).json() + result = self.parse_result(response, start, end) + return result + + + def parse_result(self, response, start, end) -> str: + result = [] + # print(response) + for i in range(start, end): + item = response[i] + result.append(f'{item["title"]}, {item["genre"]}, {item["rating"]}, published in {item["year"]}') + + return f"Top {start}-{end} series ranked by IMDB are: " + ";".join(result) + + def get_tool_call_format(self): + tool_call_format = { + "type": "function", + "function": { + "name": "top_movies", + "description": "Query the latest top start-to-end movies ranked by Imdb", + "parameters": { + "type": "object", + "properties": { + "start": { + "type": "string", + "description": "start of the rank range of the Imdb movies", + "default": "1" + }, + "end": { + "type": "string", + "description": "end of the rank range of the Imdb movies" + } + }, + "required": [ + "end" + ] + } + } + } + return tool_call_format diff --git a/pyopenagi/tools/imdb/top_series.py b/pyopenagi/tools/imdb/top_series.py index bb01380..0215388 100644 --- a/pyopenagi/tools/imdb/top_series.py +++ b/pyopenagi/tools/imdb/top_series.py @@ -1,9 +1,5 @@ from ..base import BaseRapidAPITool -from typing import Any, Dict, List, Optional - -# from pydantic import root_validator - from pyopenagi.utils.utils import get_from_env import requests diff --git a/pyopenagi/tools/meteosource_weather/find_place.py b/pyopenagi/tools/meteosource_weather/find_place.py index 91136f3..8540943 100644 --- a/pyopenagi/tools/meteosource_weather/find_place.py +++ b/pyopenagi/tools/meteosource_weather/find_place.py @@ -1,10 +1,8 @@ -from ...base import BaseRapidAPITool - -from typing import Any, Dict, List, Optional +from ..base import BaseRapidAPITool # from pydantic import root_validator -from src.utils.utils import get_from_env +from pyopenagi.utils.utils import get_from_env import requests diff --git a/pyopenagi/tools/moonphase/moon_phase_search.py b/pyopenagi/tools/moonphase/moon_phase_search.py index 7b0e123..017b1b2 100644 --- a/pyopenagi/tools/moonphase/moon_phase_search.py +++ b/pyopenagi/tools/moonphase/moon_phase_search.py @@ -1,15 +1,9 @@ from ..base import BaseRapidAPITool -from typing import Any, Dict, List, Optional - -# from pydantic import root_validator - from pyopenagi.utils.utils import get_from_env import requests -import os - class MoonPhaseSearch(BaseRapidAPITool): def __init__(self): super().__init__() diff --git a/pyopenagi/tools/shazam/song_auto_complete.py b/pyopenagi/tools/shazam/song_auto_complete.py index b4846f2..f050113 100644 --- a/pyopenagi/tools/shazam/song_auto_complete.py +++ b/pyopenagi/tools/shazam/song_auto_complete.py @@ -1,7 +1,5 @@ from ..base import BaseRapidAPITool -from typing import Any, Dict, List, Optional - # from pydantic import root_validator from pyopenagi.utils.utils import get_from_env diff --git a/pyopenagi/tools/trip_advisor/airport_search.py b/pyopenagi/tools/trip_advisor/airport_search.py index d9de71d..c477675 100644 --- a/pyopenagi/tools/trip_advisor/airport_search.py +++ b/pyopenagi/tools/trip_advisor/airport_search.py @@ -1,7 +1,5 @@ from ..base import BaseRapidAPITool -from typing import Any, Dict, List, Optional - from pyopenagi.utils.utils import get_from_env import requests diff --git a/pyopenagi/tools/trip_advisor/flight_search.py b/pyopenagi/tools/trip_advisor/flight_search.py index a98deac..cb55dd6 100644 --- a/pyopenagi/tools/trip_advisor/flight_search.py +++ b/pyopenagi/tools/trip_advisor/flight_search.py @@ -4,8 +4,6 @@ import requests -import os - import json class FlightSearch(BaseRapidAPITool): diff --git a/pyopenagi/tools/trip_advisor/get_hotel_details.py b/pyopenagi/tools/trip_advisor/get_hotel_details.py index fb101f8..7c37a87 100644 --- a/pyopenagi/tools/trip_advisor/get_hotel_details.py +++ b/pyopenagi/tools/trip_advisor/get_hotel_details.py @@ -1,13 +1,9 @@ from ..base import BaseRapidAPITool -from typing import Any, Dict, List, Optional - from pyopenagi.utils.utils import get_from_env import requests -import os - import json class GetHotelDetails(BaseRapidAPITool): diff --git a/pyopenagi/tools/trip_advisor/get_restaurant_details.py b/pyopenagi/tools/trip_advisor/get_restaurant_details.py index 2c16ad1..4d8f2b0 100644 --- a/pyopenagi/tools/trip_advisor/get_restaurant_details.py +++ b/pyopenagi/tools/trip_advisor/get_restaurant_details.py @@ -1,13 +1,9 @@ from ..base import BaseRapidAPITool -from typing import Any, Dict, List, Optional - from pyopenagi.utils.utils import get_from_env import requests -import os - import json class GetRestaurantDetails(BaseRapidAPITool): diff --git a/pyopenagi/tools/trip_advisor/hotel_location_search.py b/pyopenagi/tools/trip_advisor/hotel_location_search.py index 373741f..0c9434c 100644 --- a/pyopenagi/tools/trip_advisor/hotel_location_search.py +++ b/pyopenagi/tools/trip_advisor/hotel_location_search.py @@ -1,13 +1,9 @@ from ..base import BaseRapidAPITool -from typing import Any, Dict, List, Optional - from pyopenagi.utils.utils import get_from_env import requests -import os - import json class HotelLocationSearch(BaseRapidAPITool): diff --git a/pyopenagi/tools/trip_advisor/hotel_search.py b/pyopenagi/tools/trip_advisor/hotel_search.py index 72d0c28..29d5320 100644 --- a/pyopenagi/tools/trip_advisor/hotel_search.py +++ b/pyopenagi/tools/trip_advisor/hotel_search.py @@ -1,13 +1,9 @@ from ..base import BaseRapidAPITool -from typing import Any, Dict, List, Optional - from pyopenagi.utils.utils import get_from_env import requests -import os - import json class HotelSearch(BaseRapidAPITool): diff --git a/pyopenagi/tools/trip_advisor/restaurant_location_search.py b/pyopenagi/tools/trip_advisor/restaurant_location_search.py index 8d00684..30c8c95 100644 --- a/pyopenagi/tools/trip_advisor/restaurant_location_search.py +++ b/pyopenagi/tools/trip_advisor/restaurant_location_search.py @@ -1,13 +1,9 @@ from ..base import BaseRapidAPITool -from typing import Any, Dict, List, Optional - from pyopenagi.utils.utils import get_from_env import requests -import os - import json class RestaurantLocationSearch(BaseRapidAPITool): diff --git a/pyopenagi/tools/trip_advisor/restaurant_search.py b/pyopenagi/tools/trip_advisor/restaurant_search.py index ada94fb..f20b486 100644 --- a/pyopenagi/tools/trip_advisor/restaurant_search.py +++ b/pyopenagi/tools/trip_advisor/restaurant_search.py @@ -2,14 +2,10 @@ from ..base import BaseRapidAPITool -from typing import Any, Dict, List, Optional - from pyopenagi.utils.utils import get_from_env import requests -import os - import json class RestaurantSearch(BaseRapidAPITool): diff --git a/pyopenagi/tools/wikipedia/wikipedia.py b/pyopenagi/tools/wikipedia/wikipedia.py index 6c39794..e05a4e0 100644 --- a/pyopenagi/tools/wikipedia/wikipedia.py +++ b/pyopenagi/tools/wikipedia/wikipedia.py @@ -1,9 +1,6 @@ -import logging -from typing import Any, Dict, Iterator, List, Optional - from ..base import BaseTool # from langchain_core.documents import Document - +from typing import Optional, Any, Dict class Wikipedia(BaseTool): """Wikipedia tool, refactored from langchain. diff --git a/pyopenagi/tools/wolfram/wolfram_alpha.py b/pyopenagi/tools/wolfram/wolfram_alpha.py index 294a4ca..4b76a54 100644 --- a/pyopenagi/tools/wolfram/wolfram_alpha.py +++ b/pyopenagi/tools/wolfram/wolfram_alpha.py @@ -1,5 +1,3 @@ -from typing import Any, Dict, Optional - from ..base import BaseTool from pyopenagi.utils.utils import get_from_env diff --git a/pyopenagi/tools/words_api/words_api.py b/pyopenagi/tools/words_api/words_api.py index 7c55fe0..876f988 100644 --- a/pyopenagi/tools/words_api/words_api.py +++ b/pyopenagi/tools/words_api/words_api.py @@ -1,15 +1,11 @@ from ..base import BaseRapidAPITool -from typing import Any, Dict, List, Optional - # from pydantic import root_validator from pyopenagi.utils.utils import get_from_env import requests -import os - SUPPORTED_APIS = [ "typeOf", "hasTypes", "partOf", "hasParts", "instanceOf", "hasInstances", "similarTo", @@ -54,7 +50,7 @@ def run(self, params): def parse_result(self, response) -> str: # fail response: {'success': False, 'message': 'word not found'} - if ("success" in response and response["success"] == False): + if "success" in response and not response["success"]: return response["message"] return response["word"] + " " + self.api_name + " [" + ",".join(response[self.api_name]) + "]" diff --git a/pyopenagi/utils/chat_template.py b/pyopenagi/utils/chat_template.py index d2d41fc..4a0af11 100755 --- a/pyopenagi/utils/chat_template.py +++ b/pyopenagi/utils/chat_template.py @@ -1,7 +1,8 @@ class Query: def __init__(self, messages, - tools = None + tools = None, + message_return_type = "text" ) -> None: """Query format @@ -13,8 +14,8 @@ def __init__(self, tools (optional): tools that are used for function calling. Defaults to None. """ self.messages = messages - self.tools = tools + self.message_return_type = message_return_type class Response: def __init__( diff --git a/pyopenagi/utils/utils.py b/pyopenagi/utils/utils.py index 4eefc44..edad022 100644 --- a/pyopenagi/utils/utils.py +++ b/pyopenagi/utils/utils.py @@ -3,10 +3,10 @@ import os import shutil -from typing import Dict, List, Any, Optional - import json +from typing import Dict, Any, Optional + import re # logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s') diff --git a/pyproject.toml b/pyproject.toml index bd8363f..e4ae91b 100755 --- a/pyproject.toml +++ b/pyproject.toml @@ -13,7 +13,7 @@ license = {file = "LICENSE"} name = "pyopenagi" readme = "README.md" requires-python = ">=3.9" -version = "0.0.6" +version = "0.0.9" classifiers = [ "Development Status :: 3 - Alpha",