Created
October 7, 2023 11:00
-
-
Save S1M0N38/f861ca42e2899b198168e2724fadc1d8 to your computer and use it in GitHub Desktop.
dummy-ollama
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
import time | |
app = Flask(__name__) | |
@app.route("/api/generate", methods=["POST"]) | |
def generate_response(): | |
assert request.json | |
model = request.json["model"] | |
prompt = request.json["prompt"] | |
def generate_messages(): | |
for word in prompt.split(): | |
response_message = { | |
"model": model, | |
"created_at": time.strftime("%Y-%m-%dT%H:%M:%S.%fZ"), | |
"response": f"{word} ", | |
"done": False, | |
} | |
yield json.dumps(response_message) + "\n" | |
time.sleep(1) # Simulate some processing time | |
# Final message with some no-sense additional information | |
final_message = { | |
"model": model, | |
"created_at": time.strftime("%Y-%m-%dT%H:%M:%S.%fZ"), | |
"context": [1, 2, 3], | |
"done": True, | |
"total_duration": 5589157167, | |
"load_duration": 3013701500, | |
"sample_count": 114, | |
"sample_duration": 81442000, | |
"prompt_eval_count": 46, | |
"prompt_eval_duration": 1160282000, | |
"eval_count": 113, | |
"eval_duration": 1325948000, | |
} | |
yield json.dumps(final_message) + "\n" | |
return Response(generate_messages(), content_type="application/json", status=200) | |
if __name__ == "__main__": | |
app.run(host="localhost", port=11434, debug=True) |
Author
S1M0N38
commented
Oct 7, 2023
- Run server with
- Send HTTP request with curl
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment