Package: argai
🌟argai⚡ Run any of your functions with just natural language.🔮 QuickstartInstall:pip install argaiOpenAI Setup:
via terminalexport OPENAI_API_KEY="..."or via pythonimportopenaiopenai.api_key="..."Make your functions intelligent and queryable via natural language:defcreate_file(filename,text):withopen(filename,'w')asf:f.write(text)return{"status":"success","filename":filename}fromargaiimportArgFuncarg=ArgFunc(create_file)result=arg("Create a file called language.csv with all the programming languages available.")Logs to keep track of the progress:1: 💬: Create a file called language.csv for the top 10 most popular programming languages and its complexity.
    📝 Calling LLM
    🏃 Running function: create_file(filename='language.csv', text='Language,Complexity\nPython,Low\nJavaScript,Medium\nJava,High\nC++,High\nC#,Medium\nRuby,Low\nPHP,Medium\nSwift,Medium\nGo,Medium\nTypeScript,Medium')
    ✔️ Sucessfull, result: {'status': 'success', 'filename': 'language.csv'}
2: 🌟: Ran create_file, result: {'status': 'success', 'filename': 'language.csv'}
    📝 Calling LLM
3: 🤖: I have created a file called `language.csv` with the information of the top 10 most popular programming languages and their complexity.Final output can be accessed viaresult.output{'status': 'success', 'filename': 'language.csv'}❓ What is this?LLM function calling is the ability to describe functions to LLMs and have the LLMs infer the input of the functions based off natural language query. For example:“Email Anya to see if she wants to get coffee next Friday” ->send_email(to="anya@gmail.com",body="Hey Anya, do you want to get coffee this Friday? Let me know what time works best for you")“Who are our highest spending customers” ->sql_query(query="SELECT customer, spend FROM CUSTOMERS ORDERED BY spend DESC;")This library aims to help you develop function calling capabilities for your functions and build applications that utilizes function calling. For example:🤖 AgentsCreate autonomous agents that can continuously execute and run your functions based off a goal.💬 Chatbots with 'Plugins'Create chatbots that can execute your function like ChatGPT with Plugins.✈️ CopilotsAutomatically make your functions callable via natural language for copiloting.🧪 TestingAutomatically test your function against different scenarios.More examples🌟 1. Function CallingCalling a function with just natural language. Below is an example of a simple function of creating file.fromargaiimportArgFuncdefcreate_file(filename,text):withopen(filename,'w')asf:f.write(text)return{"status":"success","filename":filename}arg=ArgFunc(create_file)result=arg("Create a file called language.csv with all the programming languages available.")Outputlogs:1: 💬: Create a file called language.csv for the top 10 most popular programming languages and its complexity.
    📝 Calling LLM
    🏃 Running function: create_file(filename='language.csv', text='Language,Complexity\nPython,Low\nJavaScript,Medium\nJava,High\nC++,High\nC#,Medium\nRuby,Low\nPHP,Medium\nSwift,Medium\nGo,Medium\nTypeScript,Medium')
    ✔️ Sucessfull, result: {'status': 'success', 'filename': 'language.csv'}
2: 🌟: Ran create_file, result: {'status': 'success', 'filename': 'language.csv'}
    📝 Calling LLM
3: 🤖: I have created a file called `language.csv` with the information of the top 10 most popular programming languages and their complexity.result.output{'status': 'success', 'filename': 'language.csv'}️‍🩹 1.2 Function calling with self-healingWhen the LLM hallucinates we can make it self heal/repair. You just addmax_attemptsas a argument to the function and it will be attempting to fix itself tillmax_attemptsor a successfull call is made:arg("Create a python file that builds a linear regression model for a csv called 'data.csv'",max_attempts=5,)The results of a function won't be appended untilmax_attemptsis reached to save tokens + context limit.️⏭️ 1.3 Consecutive function callingSometimes a query will require a function being called not once but multiple times consecutively. In those scenarios set amax_callsand it will be called continuously tillmax_callsor an answer is reached.arg("Create a file called data.csv with top 10 grossing movie of all time. Then create a python file that will create a linear regression model on that csv.",max_calls=5,max_attempts=5,)Outputlogs:1: 💬: Create a file called data.csv with top 10 grossing movie of all time. Then create a python file that will create a linear regression model on that csv.
    📝 Calling LLM
    🏃 Running function: create_file(filename='data.csv', text='Movie,Revenue\nAvengers: Endgame,2797800564\nAvatar,2787965087\nTitanic,2187463944\nStar Wars: The Force Awakens,2068223624\nAvengers: Infinity War,2048359754\nJurassic World,1670516444\nThe Lion King,1656962239\nThe Avengers,1518815515\nFurious 7,1515047671\nFrozen II,1450026933')
    ✔️ Sucessfull, result: {'status': 'success', 'filename': 'data.csv'}
2: 🌟: Ran create_file, result: {'status': 'success', 'filename': 'data.csv'}
    📝 Calling LLM
    🏃 Running function: create_file(filename='linear_regression.py', text="import pandas as pd\nfrom sklearn.linear_model import LinearRegression\n\n# Load the CSV file\ndata = pd.read_csv('data.csv')\n\n# Prepare the data\nX = data['Revenue'].values.reshape(-1, 1)\ny = data['Movie'].values\n\n# Create a linear regression model\nmodel = LinearRegression()\n\n# Fit the model\nmodel.fit(X, y)\n\n# Print the coefficients\nprint('Intercept:', model.intercept_)\nprint('Coefficient:', model.coef_)")
    ✔️ Sucessfull, result: {'status': 'success', 'filename': 'linear_regression.py'}
3: 🌟: Ran create_file, result: {'status': 'success', 'filename': 'linear_regression.py'}
    📝 Calling LLM
4: 🤖: I have created a file called "data.csv" with the top 10 grossing movies of all time. I have also created a Python file called "linear_regression.py" that creates a linear regression model on the provided CSV data.result.output{'status': 'success', 'filename': 'linear_regression.py'}💾 2. Function Calling from Multiple functionsCalling from a list of functions with just natural language, the LLM will automatically decide which function to use.fromargaiimportArgFuncStoragearg=ArgFuncStorage()@arg.registerdefcreate_file(filename,text):"""Create a file from raw text"""withopen(filename,'w')asf:f.write(text)return{"success":True}importpandasaspd@arg.registerdefpandas_query(csv_file,query):"""Run a pandas query on a csv file"""df=pd.read_csv(csv_file)returndf.query(query)arg("Create a file called language.csv with the top 10 most popular programming languages available.",)⏭️ 2.2 Consecutive function calling on multiple functionsThis will be able choose and run different registered functions tillmax_callsor an answer is reached.arg("Create a file called language.csv with the top 10 most popular programming languages available, after that show me only the low complexity languages.",max_calls=10,)🩹 2.3 Multiple functions with self-healingJust like single function calling, when a function fails you can repair it with self-healing.arg("Create a file called language.csv with the top 10 most popular programming languages available, after that show me only the low complexity languages.",max_calls=10,max_attempts=5)🙌 ContributingContributions of all kinds are extremely welcome!What is with the 🌟?Last but not least, the most important question and answer:def func(*args)->def func(🌟args)