From 6cb595d956adb94cf82a53ab977c5d974db325c4 Mon Sep 17 00:00:00 2001 From: Zack Date: Thu, 19 Oct 2023 23:43:01 -0500 Subject: [PATCH] feat: Add bing tools and example --- bingchat.py | 20 ++++++++++++++++++++ requirements.txt | 1 + swarms/models/bing_chat.py | 2 +- swarms/tools/tool.py | 6 ++++++ 4 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 bingchat.py diff --git a/bingchat.py b/bingchat.py new file mode 100644 index 00000000..07c2a21b --- /dev/null +++ b/bingchat.py @@ -0,0 +1,20 @@ +from swarms.models.bing_chat import EdgeGPTModel +from swarms.workers.worker import Worker +from swarms.tools.tool.bing_chat import EdgeGPTTool + +# Initialize the EdgeGPTModel +edgegpt = EdgeGPTModel(cookies_path="./path/to/cookies.json") + +# Initialize the custom tool +edgegpt_tool = EdgeGPTTool(edgegpt) + +# Initialize the Worker with the custom tool +worker = Worker( + ai_name="EdgeGPT Worker", + external_tools=[edgegpt_tool], +) + +# Use the worker to process a task +task = "Hello, my name is ChatGPT" +response = worker.run(task) +print(response) diff --git a/requirements.txt b/requirements.txt index 8a74aadd..a1b5736c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -6,6 +6,7 @@ langchain nest_asyncio pegasusx google-generativeai +EdgeGPT langchain-experimental playwright wget==3.2 diff --git a/swarms/models/bing_chat.py b/swarms/models/bing_chat.py index 6817f8bf..8525ab7a 100644 --- a/swarms/models/bing_chat.py +++ b/swarms/models/bing_chat.py @@ -26,7 +26,7 @@ class EdgeGPTModel: self.cookies = json.loads(open(cookies_path, encoding="utf-8").read()) self.bot = asyncio.run(Chatbot.create(cookies=self.cookies)) - def __call(self, prompt: str, style: ConversationStyle = ConversationStyle.creative) -> str: + def __call__(self, prompt: str, style: ConversationStyle = ConversationStyle.creative) -> str: """ Get a text response using the EdgeGPT model based on the provided prompt. """ diff --git a/swarms/tools/tool.py b/swarms/tools/tool.py index 8f01ac0d..783f0946 100644 --- a/swarms/tools/tool.py +++ b/swarms/tools/tool.py @@ -576,7 +576,13 @@ class Tool(BaseTool): args_schema=args_schema, **kwargs, ) + +class EdgeGPTTool: + def __init__(self, model): + self.model = model + def run(self, prompt): + return self.model.ask(prompt) class StructuredTool(BaseTool): """Tool that can operate on any number of inputs."""