A chatbot that can call apis

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

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code> 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)
</code>
<code> 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) </code>
 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?

New contributor

Fawaz is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật