gpt4free icon indicating copy to clipboard operation
gpt4free copied to clipboard

suggestion: local hosted models

Open devkral opened this issue 2 years ago • 2 comments

It would be nice to have an llama.cpp adapter for running models on machines in the local net.

This means:

  1. a endpoint where a variable ip/dns name can be specified
  2. a binding (if nothing exists) for llama.cpp or similar to make it available via ip

devkral avatar May 02 '23 09:05 devkral

A llama.cpp binding already exists but I will be looking into self hosted models in the summer vacations

xtekky avatar May 02 '23 11:05 xtekky

import pickle
from flask import Flask, request, jsonify

 Load the trained model
with open('model.pkl', 'rb') as f:
    model = pickle.load(f)

 Create a Flask app
app = Flask(__name__)

 Define an endpoint for serving predictions
@app.route('/predict', methods=['POST'])
def predict():
     Get the input data from the request
    data = request.json

     Make a prediction using the model
    prediction = model.predict(data)

     Return the prediction as JSON
    return jsonify({'prediction': prediction.tolist()})

 Start the app
if __name__ == '__main__':
    app.run()
To run this code, save it to a file called app.py, and run the following command in your terminal:
$ python app.py

Ranu2001 avatar May 04 '23 19:05 Ranu2001