Update README.md
Browse files
README.md
CHANGED
|
@@ -8,7 +8,7 @@ tags:
|
|
| 8 |
- gguf
|
| 9 |
---
|
| 10 |
|
| 11 |
-
# Trained For:
|
| 12 |
|
| 13 |
This model has been trained on coding wrapped in special tags.
|
| 14 |
|
|
@@ -41,6 +41,78 @@ Make sure to always use the codestart and codeend tags, you can have multiple se
|
|
| 41 |
|
| 42 |
# Tests:
|
| 43 |
|
| 44 |
-
**User Input**:
|
| 45 |
|
| 46 |
-
**Output**:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
- gguf
|
| 9 |
---
|
| 10 |
|
| 11 |
+
# Trained For: Coding with Extractable Tags
|
| 12 |
|
| 13 |
This model has been trained on coding wrapped in special tags.
|
| 14 |
|
|
|
|
| 41 |
|
| 42 |
# Tests:
|
| 43 |
|
| 44 |
+
**User Input**: Write a python program for a simple restful api
|
| 45 |
|
| 46 |
+
**Output**:
|
| 47 |
+
```
|
| 48 |
+
Here is an example of a simple RESTful API using Flask in Python:
|
| 49 |
+
<codestart type="python" isFile="true" title="Main Application File" file="/main.py">
|
| 50 |
+
import flask
|
| 51 |
+
from flask import request, jsonify
|
| 52 |
+
|
| 53 |
+
app = flask.Flask(__name__)
|
| 54 |
+
|
| 55 |
+
# A sample data store (you would replace this with your own data storage)
|
| 56 |
+
people = [
|
| 57 |
+
{"id": 1,
|
| 58 |
+
"name": "John",
|
| 59 |
+
"age": 30},
|
| 60 |
+
{"id": 2,
|
| 61 |
+
"name": "Jane",
|
| 62 |
+
"age": 25}
|
| 63 |
+
]
|
| 64 |
+
|
| 65 |
+
@app.route('/', methods=['GET'])
|
| 66 |
+
def index():
|
| 67 |
+
return "<h1>RESTful API</h1>"
|
| 68 |
+
|
| 69 |
+
@app.route('/api/person', methods=['GET'])
|
| 70 |
+
def get_all_persons():
|
| 71 |
+
return jsonify(people)
|
| 72 |
+
|
| 73 |
+
@app.route('/api/person/<int:id>', methods=['GET'])
|
| 74 |
+
def get_person(id):
|
| 75 |
+
result = next((i for i in people if i["id"] == id), None)
|
| 76 |
+
if not result:
|
| 77 |
+
return "Person not found", 404
|
| 78 |
+
return jsonify(result)
|
| 79 |
+
|
| 80 |
+
@app.route('/api/person', methods=['POST'])
|
| 81 |
+
def add_person():
|
| 82 |
+
new_person = {
|
| 83 |
+
"id": len(people) + 1,
|
| 84 |
+
"name": request.json['name'],
|
| 85 |
+
"age": request.json['age']
|
| 86 |
+
}
|
| 87 |
+
people.append(new_person)
|
| 88 |
+
return jsonify(new_person), 201
|
| 89 |
+
|
| 90 |
+
@app.route('/api/person/<int:id>', methods=['PUT'])
|
| 91 |
+
def update_person(id):
|
| 92 |
+
result = next((i for i in people if i["id"] == id), None)
|
| 93 |
+
if not result:
|
| 94 |
+
return "Person not found", 404
|
| 95 |
+
result["name"] = request.json.get('name', result["name"])
|
| 96 |
+
result["age"] = request.json.get('age', result["age"])
|
| 97 |
+
return jsonify(result)
|
| 98 |
+
|
| 99 |
+
@app.route('/api/person/<int:id>', methods=['DELETE'])
|
| 100 |
+
def delete_person(id):
|
| 101 |
+
global people
|
| 102 |
+
people[:] = [p for p in people if p["id"] != id]
|
| 103 |
+
return "Person deleted", 200
|
| 104 |
+
|
| 105 |
+
if __name__ == '__main__':
|
| 106 |
+
app.run()
|
| 107 |
+
</codeend>
|
| 108 |
+
|
| 109 |
+
You can run this application with `python main.py` and access it through your web browser at `http://localhost:5000`. The API has the following endpoints:
|
| 110 |
+
|
| 111 |
+
- GET /api/person: Returns a list of all persons.
|
| 112 |
+
- GET /api/person/<int:id>: Returns a specific person by ID.
|
| 113 |
+
- POST /api/person: Adds a new person to the list.
|
| 114 |
+
- PUT /api/person/<int:id>: Updates an existing person.
|
| 115 |
+
- DELETE /api/person/<int:id>: Deletes a person.
|
| 116 |
+
|
| 117 |
+
Please note that this is a very simple example and in a real application you would likely want to handle errors more robustly, add authentication and authorization, etc.
|
| 118 |
+
```
|