File size: 1,487 Bytes
87729e7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
from flask import Flask, request, jsonify
import deepinfra
import api_info

app = Flask(__name__)

@app.route('/')
def initial():
    return '<pre>' + api_info.default_info + '</pre>'

@app.route("/available_models", methods=['GET'])
def available_models():
    return jsonify(api_info.available_models)

@app.route("/endpoints", methods=['GET'])
def endpoints():
    return jsonify(api_info.endpoint)

@app.route("/developer_info", methods=['GET'])
def developer_info():
    return jsonify(api_info.developer_info)

@app.route('/generate', methods=['GET'])
def generate():
    
    query = request.args.get('query')  # Assuming the query is sent in JSON format
    system_prompt = str(request.args.get('system', "Be Helpful and Friendly. Keep your response straightfoward, short and concise"))  # Optional parameter with default value
    model = str(request.args.get('model', "meta-llama/Meta-Llama-3-70B-Instruct"))  # Optional parameter with default value
    max_tokens = int(request.args.get('max_tokens', 512))
    temperature = float(request.args.get('temperature', 0.7))  # Optional parameter with default value

    if query:
        response = deepinfra.generate(query, model=model, system_prompt=system_prompt, temperature=temperature, max_tokens=max_tokens)
        return jsonify([{'response': response}, {'developer_info': api_info.developer_info}]), 200

    else:
        return jsonify(api_info.error_message), 400

if __name__ == '__main__':
    app.run(debug=True)