Spaces:
Runtime error
Runtime error
from flask import Flask, request, jsonify | |
import requests | |
app = Flask(__name__) | |
OLLAMA_API = "http://localhost:11434" | |
def home(): | |
return "Ollama API is running. Use /api/* endpoints to access Ollama." | |
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) | |