-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathollama.py
More file actions
34 lines (21 loc) · 703 Bytes
/
ollama.py
File metadata and controls
34 lines (21 loc) · 703 Bytes
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
from flask import Flask, request, jsonify
from langchain_community.llms import Ollama
from flask_cors import CORS
app = Flask(__name__)
CORS(app)
llm = Ollama(model="llama3")
@app.route('/ask-ollama', methods=['POST'])
def ask_ollama():
data = request.get_json()
prompt = data.get('prompt', '')
response = llm.invoke(prompt)
print(response)
try:
if response:
return jsonify( response)
else:
return jsonify({'error': 'No ABC notation found in the response'}), 500
except Exception as e:
return jsonify({'error': f'Failed to parse response: {str(e)}'}), 500
if __name__ == '__main__':
app.run(debug=True)