Can you give me an example of a python script that opens an api point and serves a string?
- User
Can you give me an example of a python script that opens an api point and serves a string?
- Assistant
Here's a simple example of a Flask server in Python which creates an endpoint which sends a string back to a user:
codefrom flask import Flask, request app = Flask(__name__) @app.route('/', methods=['POST']) def echo(): request_body = request.get_json(force=True) return request_body['input'] app.run(port=3000)This application can be tested with curl as:
codecurl -X POST -H 'Content-Type: application/json' -d '{"input": "Hello server"}' http://127.0.0.1:3000/ - User
Instead of returning the request body, could you make it so it encrypts the request body with the caesar cipher and returns the cipher text?
- Assistant
Sure, here's an updated version of the Flask server that encrypts the request body with the Caesar cipher and returns the ciphertext:
codefrom flask import Flask, request app = Flask(name) @app.route('/', methods=['POST']) def encrypt(): request_body = request.get_json(force=True) input_text = request_body['input'] shift = request_body.get('shift', 0) # optional shift parameter encrypted_text = caesar_cipher(input_text, shift) return {'ciphertext': encrypted_text} def caesar_cipher(text, shift): encrypted = '' for char in text: if char.isalpha(): char_code = ord(char) encrypted_code = (char_code - 97 + shift) % 26 + 97 encrypted += chr(encrypted_code) else: encrypted += char return encrypted app.run(port=3000)
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Identical first prompt
- Human-written demonstration (OpenAssistant volunteers)Compare side by side →
- Human-written demonstration (OpenAssistant volunteers)Compare side by side →
- Human-written demonstration (OpenAssistant volunteers)Compare side by side →
- Human-written demonstration (OpenAssistant volunteers)Compare side by side →
- Human-written demonstration (OpenAssistant volunteers)Compare side by side →
- Human-written demonstration (OpenAssistant volunteers)Compare side by side →
- Human-written demonstration (OpenAssistant volunteers)