From cd10adc257ee05df6e6604ebaea78fb2f00ce203 Mon Sep 17 00:00:00 2001 From: IntelligenzaArtificiale <108482353+IntelligenzaArtificiale@users.noreply.github.com> Date: Sat, 29 Apr 2023 12:20:17 +0200 Subject: [PATCH] Add files via upload --- OtherAgent/csvAgent.py | 25 ++++++++++++ OtherAgent/customAgent.py | 81 +++++++++++++++++++++++++++++++++++++++ OtherAgent/pythonAgent.py | 31 +++++++++++++++ OtherAgent/startup.csv | 51 ++++++++++++++++++++++++ 4 files changed, 188 insertions(+) create mode 100644 OtherAgent/csvAgent.py create mode 100644 OtherAgent/customAgent.py create mode 100644 OtherAgent/pythonAgent.py create mode 100644 OtherAgent/startup.csv diff --git a/OtherAgent/csvAgent.py b/OtherAgent/csvAgent.py new file mode 100644 index 0000000..d887d6e --- /dev/null +++ b/OtherAgent/csvAgent.py @@ -0,0 +1,25 @@ +from langchain.agents import create_csv_agent +from FreeLLM import ChatGPTAPI # FREE CHATGPT API +from langchain.utilities import PythonREPL +import os + +#### LOG IN FOR CHATGPT FREE LLM +import argparse +parser = argparse.ArgumentParser() +parser.add_argument("--chatgpt_token", help="chatgpt token, check https://chat.openai.com/api/auth/session for get your token") +args = parser.parse_args() + +if args.chatgpt_token is None: + raise Exception("You must provide the huggingface token and chatgpt token") + +os.environ["CHATGPT_TOKEN"] = args.chatgpt_token + +llm = ChatGPTAPI.ChatGPT(token=os.environ["CHATGPT_TOKEN"]) +#### + + +path_csv = input("Enter the path of the csv file: ") + +agent = create_csv_agent(llm=llm, tool=PythonREPL(), path=path_csv, verbose=True) + +agent.run("How much row are in the csv file?") diff --git a/OtherAgent/customAgent.py b/OtherAgent/customAgent.py new file mode 100644 index 0000000..9c80797 --- /dev/null +++ b/OtherAgent/customAgent.py @@ -0,0 +1,81 @@ +from langchain.agents import initialize_agent +from langchain.utilities import PythonREPL +from langchain.utilities import WikipediaAPIWrapper +from langchain.tools import DuckDuckGoSearchTool +from langchain.tools.human.tool import HumanInputRun +from FreeLLM import ChatGPTAPI # FREE CHATGPT API +from langchain.agents import initialize_agent, Tool +import os + +#### LOG IN FOR CHATGPT FREE LLM +import argparse +parser = argparse.ArgumentParser() +parser.add_argument("--chatgpt_token", help="chatgpt token, check https://chat.openai.com/api/auth/session for get your token") +args = parser.parse_args() + +if args.chatgpt_token is None: + raise Exception("You must provide the huggingface token and chatgpt token") + +os.environ["CHATGPT_TOKEN"] = args.chatgpt_token + +llm = ChatGPTAPI.ChatGPT(token=os.environ["CHATGPT_TOKEN"]) +#### + +wikipedia = WikipediaAPIWrapper() +python_repl = PythonREPL() +search = DuckDuckGoSearchTool() + +#define TOOLs + +tools = [ + Tool( + name = "python repl", + func=python_repl.run, + description="useful for when you need to use python to answer a question. You should input python code" + ) +] + +wikipedia_tool = Tool( + name='wikipedia', + func= wikipedia.run, + description="Useful for when you need to look up a topic, country or person on wikipedia" +) + +duckduckgo_tool = Tool( + name='DuckDuckGo Search', + func= search.run, + description="Useful for when you need to do a search on the internet to find information that another tool can't find. be specific with your input." +) + +#human_input_tool = Tool( + #name='human input', + #func= HumanInputRun.run, + #description="Useful for when you need to ask a human a question. be specific with your input." +#) + +#Add here your tools +#custom_tool = Tool( + #name='custom tool', + #func= custom_tool.run, + #description="My fantasitc tool" +#) + + +tools.append(duckduckgo_tool) +tools.append(wikipedia_tool) +#tools.append(human_input_tool) +#tools.append(custom_tool) + + +#Create the Agent +iteration = (int(input("Enter the number of iterations: ")) if input("Do you want to set the number of iterations? (y/n): ") == "y" else 3) + +zero_shot_agent = initialize_agent( + agent="zero-shot-react-description", + tools=tools, + llm=llm, + verbose=True, + max_iterations=iteration, +) + +zero_shot_agent.run("Whats the current price of Telecom Italia Stock in euro ? ") \ No newline at end of file diff --git a/OtherAgent/pythonAgent.py b/OtherAgent/pythonAgent.py new file mode 100644 index 0000000..776b06a --- /dev/null +++ b/OtherAgent/pythonAgent.py @@ -0,0 +1,31 @@ +from langchain.agents.agent_toolkits import create_python_agent +from langchain.tools.python.tool import PythonREPLTool +from langchain.python import PythonREPL +from FreeLLM import ChatGPTAPI # FREE CHATGPT API +import os + +#### LOG IN FOR CHATGPT FREE LLM +import argparse +parser = argparse.ArgumentParser() +parser.add_argument("--chatgpt_token", help="chatgpt token, check https://chat.openai.com/api/auth/session for get your token") +args = parser.parse_args() + +if args.chatgpt_token is None: + raise Exception("You must provide the huggingface token and chatgpt token") + +os.environ["CHATGPT_TOKEN"] = args.chatgpt_token + +llm = ChatGPTAPI.ChatGPT(token=os.environ["CHATGPT_TOKEN"]) +#### + + + +agent_executor = create_python_agent( + llm=llm, + tool=PythonREPLTool(), + verbose=True +) + +agent_executor.run("""Understand, write a single neuron neural network in PyTorch. +Take synthetic data for y=2x. Train for 1000 epochs and print every 100 epochs. +Return prediction for x = 5""") \ No newline at end of file diff --git a/OtherAgent/startup.csv b/OtherAgent/startup.csv new file mode 100644 index 0000000..b1cc5f2 --- /dev/null +++ b/OtherAgent/startup.csv @@ -0,0 +1,51 @@ +R&D Spend,Administration,Marketing Spend,State,Profit +165349.2,136897.8,471784.1,New York,192261.83 +162597.7,151377.59,443898.53,California,191792.06 +153441.51,101145.55,407934.54,Florida,191050.39 +144372.41,118671.85,383199.62,New York,182901.99 +142107.34,91391.77,366168.42,Florida,166187.94 +131876.9,99814.71,362861.36,New York,156991.12 +134615.46,147198.87,127716.82,California,156122.51 +130298.13,145530.06,323876.68,Florida,155752.6 +120542.52,148718.95,311613.29,New York,152211.77 +123334.88,108679.17,304981.62,California,149759.96 +101913.08,110594.11,229160.95,Florida,146121.95 +100671.96,91790.61,249744.55,California,144259.4 +93863.75,127320.38,249839.44,Florida,141585.52 +91992.39,135495.07,252664.93,California,134307.35 +119943.24,156547.42,256512.92,Florida,132602.65 +114523.61,122616.84,261776.23,New York,129917.04 +78013.11,121597.55,264346.06,California,126992.93 +94657.16,145077.58,282574.31,New York,125370.37 +91749.16,114175.79,294919.57,Florida,124266.9 +86419.7,153514.11,0,New York,122776.86 +76253.86,113867.3,298664.47,California,118474.03 +78389.47,153773.43,299737.29,New York,111313.02 +73994.56,122782.75,303319.26,Florida,110352.25 +67532.53,105751.03,304768.73,Florida,108733.99 +77044.01,99281.34,140574.81,New York,108552.04 +64664.71,139553.16,137962.62,California,107404.34 +75328.87,144135.98,134050.07,Florida,105733.54 +72107.6,127864.55,353183.81,New York,105008.31 +66051.52,182645.56,118148.2,Florida,103282.38 +65605.48,153032.06,107138.38,New York,101004.64 +61994.48,115641.28,91131.24,Florida,99937.59 +61136.38,152701.92,88218.23,New York,97483.56 +63408.86,129219.61,46085.25,California,97427.84 +55493.95,103057.49,214634.81,Florida,96778.92 +46426.07,157693.92,210797.67,California,96712.8 +46014.02,85047.44,205517.64,New York,96479.51 +28663.76,127056.21,201126.82,Florida,90708.19 +44069.95,51283.14,197029.42,California,89949.14 +20229.59,65947.93,185265.1,New York,81229.06 +38558.51,82982.09,174999.3,California,81005.76 +28754.33,118546.05,172795.67,California,78239.91 +27892.92,84710.77,164470.71,Florida,77798.83 +23640.93,96189.63,148001.11,California,71498.49 +15505.73,127382.3,35534.17,New York,69758.98 +22177.74,154806.14,28334.72,California,65200.33 +1000.23,124153.04,1903.93,New York,64926.08 +1315.46,115816.21,297114.46,Florida,49490.75 +0,135426.92,0,California,42559.73 +542.05,51743.15,0,New York,35673.41 +0,116983.8,45173.06,California,14681.4 \ No newline at end of file