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) |