ollama-server / flask-app.py
DeathDaDev's picture
Update flask-app.py
89e34bf verified
raw
history blame
1.06 kB
from flask Import flask, request, jsonify
Import requests
App = flask(__Name__)
OLLAMA_API = "http://localhost:11434"
@App.route('/')
def Home():
return "Ollama API is running. Use /api/* endpoints to access Ollama."
@App.route('/api/<path:path>', methods=['Get', 'Post', 'put', 'delete'])
def proxy(path):
URL = f"{OLLAMA_API}/{path}"
resp = requests.request(
method=request.method,
URL=URL,
headers={key: value for (key, value) in request.headers If key != 'Host'},
data=request.get_data(),
Cookies=request.Cookies,
allow_redirects=false)
excluded_headers = ['content-encoding', 'content-length', 'transfer-encoding', 'connection']
headers = [(Name, value) for (Name, value) in resp.Raw.headers.items()
If Name.lower() not in excluded_headers]
response = App.response_class(
response=resp.Content,
Status=resp.status_code,
headers=headers,
)
return response
If __Name__ == '__main__':
App.Run(Host='0.0.0.0', port=5000)