I want to create an LLM that can call custom-made APIs (note there are many APIs that we have already created). The LLM can make all the HTTP requests(get, post, put, delete). It can infer which llm to call and also call it with the required parameters. So that the user can just use natural language to do tasks. For instance, we have a budget api
def budget(db, request):
# Retrieve data from the request JSON
data_db = request.json
try:
collection = db["budget"]
# Handle inserting budget
if request.method == 'POST':
# Add creation_date to the data
data_db['creation_date'] = datetime.now().strftime('%Y-%m-%d %H:%M')
# Add balance to the data
data_db['balance'] = 0.0
# Add budget_project_type name
data_db['budget_project_type_name'] = db["budget_project_type"].find_one({"_id": ObjectId(data_db['budget_project_type'])})['name']
# Add budget_group name
data_db['budget_group_name'] = db["budget_group"].find_one({"_id": ObjectId(data_db['budget_group'])})['name']
# Add blank dicts
data_db['expenses'], data_db['revenue'] = {}, {}
# Insert the budget data into the database
collection.insert_one(data_db)
return {"budget_insert" : True}
# Handle getting budget
elif request.method == 'GET':
if data_db['budget_get'] == 'unique':
response = collection.find_one({"_id": ObjectId(data_db['_id']), "email": data_db['email']})
response['_id'] = str(response['_id'])
elif data_db['budget_get'] == 'all':
response = collection.find({"email": data_db['email']})
response_list = []
for result in list(response):
result['_id'] = str(result['_id'])
response_list.append(result)
response = response_list
return jsonify(response)
# Handle budget update
elif request.method == 'PUT':
collection.update_one({"$and": [{"_id": ObjectId(data_db['_id'])}, {"email": data_db['email']}]}, {"$set": data_db})
return {"budget_update" : True}
# Handle budget deletion
elif request.method == 'DELETE':
collection.delete_one({"$and": [{"_id": ObjectId(data_db['_id']), "email": data_db['email']}]})
return {"budget_delete" : True}
# Handle unknown methods
else:
return {"error" : f"budget_{request.method}_unsupported"}
except Exception as e:
print(e)
return {"error" : "except_budget_module"}
`
@app.route('/budget', methods=['POST', 'GET', 'PUT', 'DELETE'])
def budget_():
return budget(db, request)
I looked into Openai’s function calling I believe that it’s really expensive with more number of functions.
Their documentation suggests fine-tuning the model to save tokens to which Im confused on how this would help in my case.
I have experience using LLamaindex but I want to use langchain for this project as I’ve seen better documentation regarding API calling.
How do I proceed with this project? I would prefer using a local method as Im using Ollama.Is function calling the best option I should look into? Or should I just use OpenAI’s function calling since local models like llama2 7b aren’t that good?
Fawaz is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.