Spaces:
Runtime error
Runtime error
File size: 1,061 Bytes
89e34bf 598538d 89e34bf 598538d 89e34bf 598538d 89e34bf 598538d 89e34bf 598538d 89e34bf 598538d 89e34bf 598538d 89e34bf 598538d 89e34bf 598538d 89e34bf |
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
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) |