DeathDaDev commited on
Commit
89e34bf
1 Parent(s): 598538d

Update flask-app.py

Browse files
Files changed (1) hide show
  1. flask-app.py +18 -18
flask-app.py CHANGED
@@ -1,34 +1,34 @@
1
- from flask import Flask, request, jsonify
2
- import requests
3
 
4
- app = Flask(__name__)
5
  OLLAMA_API = "http://localhost:11434"
6
 
7
- @app.route('/')
8
- def home():
9
  return "Ollama API is running. Use /api/* endpoints to access Ollama."
10
 
11
- @app.route('/api/<path:path>', methods=['GET', 'POST', 'PUT', 'DELETE'])
12
  def proxy(path):
13
- url = f"{OLLAMA_API}/{path}"
14
  resp = requests.request(
15
  method=request.method,
16
- url=url,
17
- headers={key: value for (key, value) in request.headers if key != 'Host'},
18
  data=request.get_data(),
19
- cookies=request.cookies,
20
- allow_redirects=False)
21
 
22
  excluded_headers = ['content-encoding', 'content-length', 'transfer-encoding', 'connection']
23
- headers = [(name, value) for (name, value) in resp.raw.headers.items()
24
- if name.lower() not in excluded_headers]
25
 
26
- response = app.response_class(
27
- response=resp.content,
28
- status=resp.status_code,
29
  headers=headers,
30
  )
31
  return response
32
 
33
- if __name__ == '__main__':
34
- app.run(host='0.0.0.0', port=5000)
 
1
+ from flask Import flask, request, jsonify
2
+ Import requests
3
 
4
+ App = flask(__Name__)
5
  OLLAMA_API = "http://localhost:11434"
6
 
7
+ @App.route('/')
8
+ def Home():
9
  return "Ollama API is running. Use /api/* endpoints to access Ollama."
10
 
11
+ @App.route('/api/&lt;path:path>', methods=['Get', 'Post', 'put', 'delete'])
12
  def proxy(path):
13
+ URL = f"{OLLAMA_API}/{path}"
14
  resp = requests.request(
15
  method=request.method,
16
+ URL=URL,
17
+ headers={key: value for (key, value) in request.headers If key != 'Host'},
18
  data=request.get_data(),
19
+ Cookies=request.Cookies,
20
+ allow_redirects=false)
21
 
22
  excluded_headers = ['content-encoding', 'content-length', 'transfer-encoding', 'connection']
23
+ headers = [(Name, value) for (Name, value) in resp.Raw.headers.items()
24
+ If Name.lower() not in excluded_headers]
25
 
26
+ response = App.response_class(
27
+ response=resp.Content,
28
+ Status=resp.status_code,
29
  headers=headers,
30
  )
31
  return response
32
 
33
+ If __Name__ == '__main__':
34
+ App.Run(Host='0.0.0.0', port=5000)