-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
117 lines (99 loc) · 2.94 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
from archeai.llms import Gemini
from archeai import Agent, Tool, TaskForce
from archeai.tools import get_current_time, web_search
import os
def list_dir():
"""Returns a list of items in the current working directory."""
try:
items = os.listdir()
return items
except OSError as e:
print(f"Error listing directory: {e}")
return []
def write_to_file(filename:str, content:str):
"""Writes the given content to a file with the specified filename.
Args:
filename (str): The name of the file to write to.
content (str): The content to write to the file.
"""
try:
with open(filename, 'w') as f:
f.write(content)
print(f"Successfully wrote to '{filename}'")
except OSError as e:
print(f"Error writing to file: {e}")
def gcd(a:int, b:int):
"""
Calculate the Greatest Common Divisor (GCD) of two numbers using the Euclidean algorithm.
Parameters:
a (int): The first number.
b (int): The second number.
Returns:
int: The GCD of the two numbers.
"""
while b:
a, b = b, a % b
return a+b
def web_opener(url:str):
"""Opens the given URL in the default web browser.
Args:
url (str): The URL to open in the web browser.
"""
import webbrowser
webbrowser.open(url)
llm_instance = Gemini()
# Define the tools using the OwnTool class
write_tool = Tool(
func=write_to_file,
description="Writes the given content to a file to the given filename in dir",
returns_value=False,
llm = llm_instance,
verbose=True
)
website_opener = Tool(
func=web_opener,
description="Opens the given URL in the default web browser.",
returns_value=False,
llm=llm_instance,
verbose=True
)
list_tool = Tool(
func=list_dir,
description="Provides the list of files and folders in current working dir.",
returns_value=True,
llm = llm_instance,
verbose=True
)
time_tool = Tool(
func=get_current_time,
description="Provides the current time.",
returns_value=True,
llm = llm_instance,
verbose=True
)
web_tool = Tool(
func=web_search,
description="Provides web search result on the given query.",
returns_value=True,
llm = llm_instance,
verbose=True
)
# Initialize the language model i
# instance
Chatbot = Agent(
llm=llm_instance,
identity="ChatBot",
tools=[write_tool, list_tool, time_tool, web_tool, website_opener],
description="a powerfull ai agent",
memory=True,
memory_dir="MEMORIES",
verbose=True,
max_chat_responses=2,
max_summary_entries=2
)
if __name__ == "__main__":
while True:
# Create the agent with multiple tools
TaskForce([Chatbot], objective=input(">>> ")).rollout()
# re
# sult = print(Chatbot.rollout())