Build Small Apps With LLMs
Description of Build Small Apps With LLMs
Goal
English
The goal of the App we will attempt is to provide a backend for an e-commerce store application. It enables CRUD (create, read, update, delete) operations on core entities like categories, products, users, and reviews.
Some key aspects:
Categories: The /categories endpoints allow creating, reading, updating and deleting product categories. Categories have a name, description and id.
Products: The /products endpoints allow creating, reading, updating and deleting products. Products belong to a category and have properties like name, description, price and id. The /products/{category_id}/products endpoint enables fetching or creating products for a specific category.
Users: The /users endpoints enable CRUD operations on user accounts. Users have properties like name, email, password, avatar, and role flags like is_admin.
Reviews: The /reviews endpoints allow CRUD of reviews, which are ratings and comments posted about a product by a user. Reviews have properties like a rating, comment, product_id and user_id. The /reviews/products/{product_id} and /reviews/users/{user_id} endpoints allow filtering reviews by product or user.
CRUD conventions: The API follows typical REST conventions - GET for retrieving resources, POST for creating, PUT/PATCH for updating, and DELETE for deleting.
Error handling: API errors are returned as JSON objects adhering to the HTTPValidationError schema.
Pagination: List endpoints like /categories and /products support pagination via skip and limit query parameters.
So in summary, it enables a typical e-commerce application frontend to perform operations like managing products in a catalog, user accounts and order history, product reviews and ratings, and more. The backend exposes structured CRUD APIs following REST principles for the app frontend to consume.
Français
Voici la traduction française :
L'objectif de cette API semble être de fournir un backend pour une application de commerce électronique. Elle permet des opérations CRUD (créer, lire, mettre à jour, supprimer) sur des entités de base comme les catégories, les produits, les utilisateurs et les avis.
Quelques aspects clés :
Catégories : Les points de terminaison /categories permettent de créer, lire, mettre à jour et supprimer des catégories de produits. Les catégories ont un nom, une description et un identifiant.
Produits : Les points de terminaison /products permettent de créer, lire, mettre à jour et supprimer des produits. Les produits appartiennent à une catégorie et ont des propriétés comme le nom, la description, le prix et l'identifiant. Le point de terminaison /products/{category_id}/products permet de récupérer ou créer des produits pour une catégorie spécifique.
Utilisateurs : Les points de terminaison /users permettent des opérations CRUD sur les comptes utilisateurs. Les utilisateurs ont des propriétés comme le nom, l'email, le mot de passe, l'avatar, et des indicateurs de rôle comme is_admin.
Avis : Les points de terminaison /reviews permettent les opérations CRUD sur les avis, qui sont des notes et commentaires publiés sur un produit par un utilisateur. Les avis ont des propriétés comme la note, le commentaire, le product_id et le user_id. Les points de terminaison /reviews/products/{product_id} et /reviews/users/{user_id} permettent de filtrer les avis par produit ou par utilisateur.
Conventions CRUD : L'API suit les conventions REST typiques - GET pour récupérer des ressources, POST pour créer, PUT/PATCH pour mettre à jour, et DELETE pour supprimer.
Gestion des erreurs : Les erreurs d'API sont renvoyées en tant qu'objets JSON adhérant au schéma HTTPValidationError.
Pagination : Les points de terminaison de liste comme /categories et /products prennent en charge la pagination via les paramètres de requête skip et limit.
En résumé, elle permet à un frontend d'application de commerce électronique typique d'effectuer des opérations comme la gestion de produits dans un catalogue, les comptes utilisateurs et l'historique des commandes, les avis et notes sur les produits, et plus encore. Le backend expose des API CRUD structurées suivant les principes REST pour que l'frontend de l'application les consomme.
API Structure
flowchart TB subgraph "/categories/" get[GET] post[POST] subgraph "/categories/{category_id}" get_cat[GET] put[PUT] delete[DELETE] end subgraph "/categories/{category_id}/products" get_products[GET] post_product[POST] end get -->|Read Categories| get_cat post -->|Create Category| post get_cat -->|Read Category| get_cat put -->|Update Category| put delete -->|Delete Category| delete get_cat -->|Read Products By Category| get_products post_product -->|Create Product By Category| post_product end subgraph "/products/" get_products_all[GET] post_product[POST] subgraph "/products/{product_id}" get_prod[GET] put[PUT] delete[DELETE] end subgraph "/products/{category_id}/products" get_products_by_cat[GET] post_product_by_cat[POST] end get_products_all -->|Read Products| get_products_all post_product -->|Create Product| post_product get_prod -->|Read Product| get_prod put -->|Update Product| put delete -->|Delete Product| delete get_products_all -->|Read Products By Category| get_products_by_cat post_product_by_cat -->|Create Product By Category| post_product_by_cat end subgraph "/users/" get_users[GET] post_user[POST] subgraph "/users/{user_id}" get_user[GET] patch[PATCH] delete[DELETE] end get_users -->|Read Users| get_users post_user -->|Create User| post_user get_user -->|Read User| get_user patch -->|Update User| patch delete -->|Delete User| delete end subgraph "/reviews/" get_reviews[GET] post_review[POST] subgraph "/reviews/{review_id}" get_review[GET] patch[PATCH] delete[DELETE] end subgraph "/reviews/products/{product_id}" get_reviews_by_prod[GET] end subgraph "/reviews/users/{user_id}" get_reviews_by_user[GET] end subgraph "/reviews/products/{product_id}/users/{user_id}" get_reviews_by_prod_and_user[GET] end get_reviews -->|Read Reviews| get_reviews post_review -->|Create Review| post_review get_review -->|Read Review| get_review patch -->|Update Review| patch delete -->|Delete Review| delete get_reviews -->|Read Reviews By Product| get_reviews_by_prod get_reviews -->|Read Reviews By User| get_reviews_by_user get_reviews_by_prod_and_user -->|Read Reviews By Product And User| get_reviews_by_prod_and_user end
components: schemas: Category: description: Category model properties: description: description: Category description maxLength: 50 minLength: 3 title: Description type: string id: description: Category id title: Id type: integer name: description: Category name maxLength: 50 minLength: 3 title: Name type: string products: default: [] description: Category products items: {} title: Products type: array required: - name - description - id title: Category type: object CategoryCreate: description: Create model for category properties: description: description: Category description maxLength: 50 minLength: 3 title: Description type: string name: description: Category name maxLength: 50 minLength: 3 title: Name type: string required: - name - description title: CategoryCreate type: object HTTPValidationError: properties: detail: items: $ref: '#/components/schemas/ValidationError' title: Detail type: array title: HTTPValidationError type: object Product: description: Product model properties: description: description: Product description title: Description type: string id: description: Product id title: Id type: integer name: description: Product name maxLength: 50 minLength: 3 title: Name type: string price: description: Product price in USD exclusiveMinimum: 0.0 title: Price type: number reviews: default: [] description: Product reviews items: {} title: Reviews type: array required: - name - price - description - id title: Product type: object ProductCreate: description: Create model for product properties: description: description: Product description title: Description type: string name: description: Product name maxLength: 50 minLength: 3 title: Name type: string price: description: Product price in USD exclusiveMinimum: 0.0 title: Price type: number required: - name - price - description title: ProductCreate type: object Review: description: Review model properties: comment: description: Comment title: Comment type: string id: description: Review id title: Id type: integer product: description: Product title: Product type: object product_id: description: Product id title: Product Id type: integer rating: description: Rating maximum: 5.0 minimum: 1.0 title: Rating type: integer user: description: User title: User type: object user_id: description: User id title: User Id type: integer required: - product_id - user_id - rating - comment - id - user - product title: Review type: object ReviewCreate: description: Create model for review properties: comment: description: Comment title: Comment type: string product_id: description: Product id title: Product Id type: integer rating: description: Rating maximum: 5.0 minimum: 1.0 title: Rating type: integer user_id: description: User id title: User Id type: integer required: - product_id - user_id - rating - comment title: ReviewCreate type: object User: description: User model properties: avatar: description: User avatar title: Avatar type: string email: description: User email maxLength: 50 minLength: 3 title: Email type: string id: title: Id type: integer is_active: default: 1 description: Is active title: Is Active type: integer is_admin: default: 0 description: Is admin title: Is Admin type: integer is_banned: default: 0 description: Is banned title: Is Banned type: integer is_blocked: default: 0 description: Is blocked title: Is Blocked type: integer is_deleted: default: 0 description: Is deleted title: Is Deleted type: integer is_suspended: default: 0 description: Is suspended title: Is Suspended type: integer is_verified: default: 0 description: Is verified title: Is Verified type: integer name: description: User name maxLength: 50 minLength: 3 title: Name type: string password: description: User password title: Password type: string reviews: items: {} title: Reviews type: array required: - name - email - avatar - password - id title: User type: object UserCreate: description: Create model for user properties: avatar: description: User avatar title: Avatar type: string email: description: User email maxLength: 50 minLength: 3 title: Email type: string is_active: default: 1 description: Is active title: Is Active type: integer is_admin: default: 0 description: Is admin title: Is Admin type: integer is_banned: default: 0 description: Is banned title: Is Banned type: integer is_blocked: default: 0 description: Is blocked title: Is Blocked type: integer is_deleted: default: 0 description: Is deleted title: Is Deleted type: integer is_suspended: default: 0 description: Is suspended title: Is Suspended type: integer is_verified: default: 0 description: Is verified title: Is Verified type: integer name: description: User name maxLength: 50 minLength: 3 title: Name type: string password: description: User password title: Password type: string required: - name - email - avatar - password title: UserCreate type: object ValidationError: properties: loc: items: anyOf: - type: string - type: integer title: Location type: array msg: title: Message type: string type: title: Error Type type: string required: - loc - msg - type title: ValidationError type: object info: description: A description of the TechHive Store API ChatGPT title: The TechHive Store API ChatGPT version: 0.1.0 openapi: 3.1.0 paths: /categories/: get: operationId: read_categories_categories__get parameters: - in: query name: skip required: false schema: default: 0 title: Skip type: integer - in: query name: limit required: false schema: default: 100 title: Limit type: integer responses: '200': content: application/json: schema: items: $ref: '#/components/schemas/Category' title: Response Read Categories Categories Get type: array description: Successful Response '422': content: application/json: schema: $ref: '#/components/schemas/HTTPValidationError' description: Validation Error summary: Read Categories tags: - categories post: operationId: create_category_categories__post requestBody: content: application/json: schema: $ref: '#/components/schemas/CategoryCreate' required: true responses: '200': content: application/json: schema: $ref: '#/components/schemas/Category' description: Successful Response '422': content: application/json: schema: $ref: '#/components/schemas/HTTPValidationError' description: Validation Error summary: Create Category tags: - categories /categories/{category_id}: delete: operationId: delete_category_categories__category_id__delete parameters: - in: path name: category_id required: true schema: title: Category Id type: integer responses: '200': content: application/json: schema: $ref: '#/components/schemas/Category' description: Successful Response '422': content: application/json: schema: $ref: '#/components/schemas/HTTPValidationError' description: Validation Error summary: Delete Category tags: - categories get: operationId: read_category_categories__category_id__get parameters: - in: path name: category_id required: true schema: title: Category Id type: integer responses: '200': content: application/json: schema: $ref: '#/components/schemas/Category' description: Successful Response '422': content: application/json: schema: $ref: '#/components/schemas/HTTPValidationError' description: Validation Error summary: Read Category tags: - categories put: operationId: update_category_categories__category_id__put parameters: - in: path name: category_id required: true schema: title: Category Id type: integer requestBody: content: application/json: schema: $ref: '#/components/schemas/CategoryCreate' required: true responses: '200': content: application/json: schema: $ref: '#/components/schemas/Category' description: Successful Response '422': content: application/json: schema: $ref: '#/components/schemas/HTTPValidationError' description: Validation Error summary: Update Category tags: - categories /products/: get: operationId: read_products_products__get parameters: - in: query name: skip required: false schema: default: 0 title: Skip type: integer - in: query name: limit required: false schema: default: 100 title: Limit type: integer responses: '200': content: application/json: schema: items: $ref: '#/components/schemas/Product' title: Response Read Products Products Get type: array description: Successful Response '422': content: application/json: schema: $ref: '#/components/schemas/HTTPValidationError' description: Validation Error summary: Read Products tags: - products post: operationId: create_product_products__post requestBody: content: application/json: schema: $ref: '#/components/schemas/ProductCreate' required: true responses: '200': content: application/json: schema: $ref: '#/components/schemas/Product' description: Successful Response '422': content: application/json: schema: $ref: '#/components/schemas/HTTPValidationError' description: Validation Error summary: Create Product tags: - products /products/{category_id}/products: get: operationId: read_products_by_category_products__category_id__products_get parameters: - in: path name: category_id required: true schema: title: Category Id type: integer responses: '200': content: application/json: schema: items: $ref: '#/components/schemas/Product' title: Response Read Products By Category Products Category Id Products Get type: array description: Successful Response '422': content: application/json: schema: $ref: '#/components/schemas/HTTPValidationError' description: Validation Error summary: Read Products By Category tags: - products post: operationId: create_product_by_category_products__category_id__products_post parameters: - in: path name: category_id required: true schema: title: Category Id type: integer requestBody: content: application/json: schema: $ref: '#/components/schemas/ProductCreate' required: true responses: '200': content: application/json: schema: $ref: '#/components/schemas/Product' description: Successful Response '422': content: application/json: schema: $ref: '#/components/schemas/HTTPValidationError' description: Validation Error summary: Create Product By Category tags: - products /products/{product_id}: delete: operationId: delete_product_products__product_id__delete parameters: - in: path name: product_id required: true schema: title: Product Id type: integer responses: '200': content: application/json: schema: $ref: '#/components/schemas/Product' description: Successful Response '422': content: application/json: schema: $ref: '#/components/schemas/HTTPValidationError' description: Validation Error summary: Delete Product tags: - products get: operationId: read_product_products__product_id__get parameters: - in: path name: product_id required: true schema: title: Product Id type: integer responses: '200': content: application/json: schema: $ref: '#/components/schemas/Product' description: Successful Response '422': content: application/json: schema: $ref: '#/components/schemas/HTTPValidationError' description: Validation Error summary: Read Product tags: - products put: operationId: update_product_products__product_id__put parameters: - in: path name: product_id required: true schema: title: Product Id type: integer requestBody: content: application/json: schema: $ref: '#/components/schemas/ProductCreate' required: true responses: '200': content: application/json: schema: $ref: '#/components/schemas/Product' description: Successful Response '422': content: application/json: schema: $ref: '#/components/schemas/HTTPValidationError' description: Validation Error summary: Update Product tags: - products /reviews/: get: operationId: read_reviews_reviews__get parameters: - in: query name: skip required: false schema: default: 0 title: Skip type: integer - in: query name: limit required: false schema: default: 100 title: Limit type: integer responses: '200': content: application/json: schema: items: $ref: '#/components/schemas/Review' title: Response Read Reviews Reviews Get type: array description: Successful Response '422': content: application/json: schema: $ref: '#/components/schemas/HTTPValidationError' description: Validation Error summary: Read Reviews tags: - reviews post: operationId: create_review_reviews__post requestBody: content: application/json: schema: $ref: '#/components/schemas/ReviewCreate' required: true responses: '200': content: application/json: schema: $ref: '#/components/schemas/Review' description: Successful Response '422': content: application/json: schema: $ref: '#/components/schemas/HTTPValidationError' description: Validation Error summary: Create Review tags: - reviews /reviews/products/{product_id}: get: operationId: read_reviews_by_product_reviews_products__product_id__get parameters: - in: path name: product_id required: true schema: title: Product Id type: integer - in: query name: skip required: false schema: default: 0 title: Skip type: integer - in: query name: limit required: false schema: default: 100 title: Limit type: integer responses: '200': content: application/json: schema: items: $ref: '#/components/schemas/Review' title: Response Read Reviews By Product Reviews Products Product Id Get type: array description: Successful Response '422': content: application/json: schema: $ref: '#/components/schemas/HTTPValidationError' description: Validation Error summary: Read Reviews By Product tags: - reviews /reviews/products/{product_id}/users/{user_id}: get: operationId: read_reviews_by_product_and_user_reviews_products__product_id__users__user_id__get parameters: - in: path name: product_id required: true schema: title: Product Id type: integer - in: path name: user_id required: true schema: title: User Id type: integer - in: query name: skip required: false schema: default: 0 title: Skip type: integer - in: query name: limit required: false schema: default: 100 title: Limit type: integer responses: '200': content: application/json: schema: items: $ref: '#/components/schemas/Review' title: Response Read Reviews By Product And User Reviews Products Product Id Users User Id Get type: array description: Successful Response '422': content: application/json: schema: $ref: '#/components/schemas/HTTPValidationError' description: Validation Error summary: Read Reviews By Product And User tags: - reviews /reviews/users/{user_id}: get: operationId: read_reviews_by_user_reviews_users__user_id__get parameters: - in: path name: user_id required: true schema: title: User Id type: integer - in: query name: skip required: false schema: default: 0 title: Skip type: integer - in: query name: limit required: false schema: default: 100 title: Limit type: integer responses: '200': content: application/json: schema: items: $ref: '#/components/schemas/Review' title: Response Read Reviews By User Reviews Users User Id Get type: array description: Successful Response '422': content: application/json: schema: $ref: '#/components/schemas/HTTPValidationError' description: Validation Error summary: Read Reviews By User tags: - reviews /reviews/{review_id}: delete: operationId: delete_review_reviews__review_id__delete parameters: - in: path name: review_id required: true schema: title: Review Id type: integer responses: '200': content: application/json: schema: $ref: '#/components/schemas/Review' description: Successful Response '422': content: application/json: schema: $ref: '#/components/schemas/HTTPValidationError' description: Validation Error summary: Delete Review tags: - reviews get: operationId: read_review_reviews__review_id__get parameters: - in: path name: review_id required: true schema: title: Review Id type: integer responses: '200': content: application/json: schema: $ref: '#/components/schemas/Review' description: Successful Response '422': content: application/json: schema: $ref: '#/components/schemas/HTTPValidationError' description: Validation Error summary: Read Review tags: - reviews patch: operationId: update_review_reviews__review_id__patch parameters: - in: path name: review_id required: true schema: title: Review Id type: integer requestBody: content: application/json: schema: $ref: '#/components/schemas/ReviewCreate' required: true responses: '200': content: application/json: schema: $ref: '#/components/schemas/Review' description: Successful Response '422': content: application/json: schema: $ref: '#/components/schemas/HTTPValidationError' description: Validation Error summary: Update Review tags: - reviews /users/: get: operationId: read_users_users__get parameters: - in: query name: skip required: false schema: default: 0 title: Skip type: integer - in: query name: limit required: false schema: default: 100 title: Limit type: integer responses: '200': content: application/json: schema: items: $ref: '#/components/schemas/User' title: Response Read Users Users Get type: array description: Successful Response '422': content: application/json: schema: $ref: '#/components/schemas/HTTPValidationError' description: Validation Error summary: Read Users tags: - users post: operationId: create_user_users__post requestBody: content: application/json: schema: $ref: '#/components/schemas/UserCreate' required: true responses: '200': content: application/json: schema: $ref: '#/components/schemas/User' description: Successful Response '422': content: application/json: schema: $ref: '#/components/schemas/HTTPValidationError' description: Validation Error summary: Create User tags: - users /users/{user_id}: delete: operationId: delete_user_users__user_id__delete parameters: - in: path name: user_id required: true schema: title: User Id type: integer responses: '200': content: application/json: schema: $ref: '#/components/schemas/User' description: Successful Response '422': content: application/json: schema: $ref: '#/components/schemas/HTTPValidationError' description: Validation Error summary: Delete User tags: - users get: operationId: read_user_users__user_id__get parameters: - in: path name: user_id required: true schema: title: User Id type: integer responses: '200': content: application/json: schema: $ref: '#/components/schemas/User' description: Successful Response '422': content: application/json: schema: $ref: '#/components/schemas/HTTPValidationError' description: Validation Error summary: Read User tags: - users patch: operationId: update_user_users__user_id__patch parameters: - in: path name: user_id required: true schema: title: User Id type: integer requestBody: content: application/json: schema: $ref: '#/components/schemas/UserCreate' required: true responses: '200': content: application/json: schema: $ref: '#/components/schemas/User' description: Successful Response '422': content: application/json: schema: $ref: '#/components/schemas/HTTPValidationError' description: Validation Error summary: Update User tags: - users
Setup
Python
English
Python is a high-level, interpreted programming language that lets you work quickly and integrates your systems more effectively. It's known for its easy syntax that emphasizes readability and therefore reduces the cost of program maintenance. Python supports multiple programming paradigms, including procedural, object-oriented, and functional programming.
Poetry, in a software context, is a tool for dependency management and packaging in Python. It allows you to declare the libraries your project depends on and it will manage (install/update) them for you.
Together, using Python with Poetry means developing a python-based software which dependencies are managed by Poetry.
Français
Python est un langage de programmation interprété de haut niveau qui vous permet de travailler rapidement et d'intégrer vos systèmes de manière plus efficace. Il est connu pour sa syntaxe facile qui met l'accent sur la lisibilité et réduit donc le coût de la maintenance du programme. Python prend en charge plusieurs paradigmes de programmation, y compris la programmation procédurale, orientée objet et fonctionnelle.
Poetry, dans un contexte logiciel, est un outil de gestion des dépendances et de paquetage en Python. Il vous permet de déclarer les bibliothèques dont dépend votre projet et il les gérera (installera/mettra à jour) pour vous.
Ensemble, utiliser Python avec Poetry signifie développer un logiciel basé sur Python dont les dépendances sont gérées par Poetry.
[tool.poetry] name = "llm-app" version = "0.1.0" description = "LLM App" authors = ["user"] license = "MIT" readme = "README.md" #packages = [{include = "build_small_apps_with_llms"}] [tool.poetry.dependencies] #python = "^3.10.6" python = "^3.11" sortedcontainers = "^2.4.0" httpx = "^0.23.0" pyzmq = "^25.1.0" requests = "^2.31.0" openai = "^0.27.8" whitenoise = "^6.2.0" fontawesomefree = "^6.4.0" typer = { version = "^0.9.0", extras = ["all"] } gradio = "^3.39.0" pydantic = {extras = ["email"], version = "^2.1.1"} chdb = "^0.11.4" uvicorn = {extras = ["standard"], version = "^0.23.1"} fastapi = {extras = ["all"], version = "^0.100.1"} sqlalchemy = "^2.0.19" psycopg2-binary = "^2.9.6" [tool.poetry.group.dev.dependencies] black = "^23.3.0" pytest = "7.3.1" [build-system] requires = ["poetry-core"] build-backend = "poetry.core.masonry.api"
__pycache__ .pytest_cache .idea *.db db-pg-data
Tech
OpenAPI
English
OpenAPI Specification (OAS), formerly known as Swagger, is a specification for machine-readable interface files for describing, producing, consuming, and visualizing RESTful web services. It helps define a standard, language-agnostic interface for REST APIs, which allows both humans and computers to comprehend service capabilities without a direct access to the source code, documentation, or network traffic.
Let's begin with JSON Schemas. A JSON Schema is a powerful tool for validating the structure of JSON data. It describes your existing data format clear, concise and easy to read (for both humans and machines). It's also language agnostic, meaning you can use it with any programming language that has JSON support.
Now, how do OpenAPI Specifications fit into the picture? JSON Schemas form a part of OpenAPI Specifications, which is an extension of it, and cater to describe and validate REST APIs.
By creating APIs with OAS, developers can understand and use the API, and form a visualization of the API, without having access to the source code of the API or the need to read through extensive documentation. A well-designed OAS helps simplify API development.
TM Forum's OpenAPIs (part of TMF specifications) are an example of real-world use of OpenAPI Specifications. They are a suite of APIs that provide a variety of functions from managing customers and products to handling orders and billing, and are developed under globally recognized standards.
In terms of their usefulness in modern software development, they are extremely useful for:
Documentation: The ability to auto-generate documentation, with included interactivity, reduces work and is beneficial for consumers and testing.
Code Generation: OAS supports generation of clients, servers, and test cases in different languages, which greatly speeds up the development process.
API design and planning: They allow for a design-first approach, where you can plan your API and then execute it.
Overall, OpenAPI Specifications, with JSON Schemas in their infrastructure, are facilitating a paradigm shift in the way we build software by making API development faster, easier, and more reliable.
Français
Spécification OpenAPI (OAS), autrefois connue sous le nom de Swagger, est une spécification pour les fichiers d'interface lisibles par machine pour décrire, produire, consommer et visualiser des services web RESTful. Elle aide à définir une interface standard, indépendante du langage, pour les API REST, ce qui permet aux humains et aux ordinateurs de comprendre les capacités du service sans un accès direct au code source, à la documentation, ou au trafic réseau.
Commençons avec les schémas JSON. Un schéma JSON est un outil puissant pour valider la structure des données JSON. Il décrit votre format de données existant de manière claire, concise et facile à lire (pour les humains et les machines). Il est également indépendant du langage, ce qui signifie que vous pouvez l'utiliser avec n'importe quel langage de programmation qui supporte JSON.
Alors, comment les spécifications OpenAPI s'intègrent-elles dans le tableau ? Les schémas JSON forment une partie des spécifications OpenAPI, qui en sont une extension, et servent à décrire et à valider les API REST.
En créant des API avec OAS, les développeurs peuvent comprendre et utiliser l'API, et former une visualisation de l'API, sans avoir accès au code source de l'API ou la nécessité de lire une documentation extensive. Une OAS bien conçue aide à simplifier le développement des API.
Les OpenAPI du TM Forum (partie des spécifications TMF) sont un exemple d'utilisation réelle des spécifications OpenAPI. Il s'agit d'un ensemble d'API qui fournissent une variété de fonctions, de la gestion des clients et des produits à la manipulation des commandes et de la facturation, et qui sont développées selon des normes mondialement reconnues.
En termes d'utilité dans le développement de logiciels modernes, ils sont extrêmement utiles pour :
Documentation: La capacité à générer automatiquement de la documentation, avec interactivité incluse, réduit le travail et est bénéfique pour les consommateurs et les tests.
Génération de code: L'OAS soutient la génération de clients, de serveurs et de cas test dans différentes langues, ce qui accélère considérablement le processus de développement.
Conception et planification d'API: Ils permettent une approche de conception en premier, où vous pouvez planifier votre API pour ensuite l'exécuter.
En somme, les spécifications OpenAPI, avec les schémas JSON dans leur infrastructure, facilitent un changement de paradigme dans la façon dont nous construisons des logiciels en rendant le développement d'API plus rapide, plus facile et plus fiable.
FastAPI with Python
English
FastAPI is a modern, fast (high-performance), web framework for building APIs with Python 3.6+ based on standard Python type hints and asynchronous programming capabilities. The key features are fast, easy, Pythonic, performance focused, and robust, with features like automatic interactive API documentation.
FastAPI is built on Starlette for the web parts and Pydantic for the data parts. It is designed to be very fast and easy to use, with excellent support for type checking, IDE integration, and other modern programming goodies. It produces a fully interactive API thanks to it being built to use standard Python type hints, which also aid in data validation, serialization, and documentation.
FastAPI utilizes Pydantic models and Python type hints to generate OpenAPI specifications. OpenAPI specs are the standardized format for REST APIs that provide a way to describe the structure of the API, which helps in generating correct requests and responses.
Here is an interesting code example of a basic FastAPI project, including an API that serves POST, GET, PATCH, PUT, and DELETE endpoints along with a client code based on the Python Requests library:
Français
FastAPI est un framework web moderne, rapide (à haute performance), destiné à la création d'APIs avec Python 3.6+ basé sur les indications de type Python standard et les capacités de programmation asynchrone. Les caractéristiques clés sont la rapidité, la facilité, le côté Pythonic, l'accent sur les performances, et la robustesse, avec des fonctionnalités comme la documentation automatique interactive de l'API.
FastAPI est construit sur Starlette pour les parties web et Pydantic pour les parties de données. Il est conçu pour être très rapide et facile à utiliser, avec un excellent support pour le contrôle de type, l'intégration IDE, et d'autres avantages de la programmation moderne. Il produit une API entièrement interactive grâce à son utilisation des indications de type Python standard, qui aident également à la validation des données, à la sérialisation et à la documentation.
FastAPI utilise les modèles Pydantic et les indications de type Python pour générer des spécifications OpenAPI. Les spécifications OpenAPI sont le format standardisé pour les API REST qui offrent un moyen de décrire la structure de l'API, ce qui aide à générer des requêtes et des réponses correctes.
Voici un exemple de code intéressant d'un projet FastAPI de base, comprenant une API qui sert des points de terminaison POST, GET, PATCH, PUT, et DELETE ainsi qu'un code client basé sur la bibliothèque Python Requests:
OpenAI Chat Plugins
English
OpenAI plugins establish a connection between ChatGPT and third-party applications. Through these plugins, ChatGPT gains the ability to interact with APIs created by developers, thereby expanding its functionalities and enabling a diverse array of tasks. With the help of these plugins, ChatGPT can accomplish various actions, such as:
fetching real-time data like sports scores, stock prices, and the latest news.
Access knowledge-base information, such as company documents and personal notes.
Assist users with performing actions like booking flights and ordering food.
Français
Les plugins OpenAI connectent ChatGPT à des applications tierces. Ces plugins permettent à ChatGPT d'interagir avec des API définies par des développeurs, améliorant ainsi ses capacités et lui permettant d'effectuer une large gamme d'actions. Les plugins permettent à ChatGPT de réaliser des choses telles que :
Récupérer des informations en temps réel ; par exemple, les scores sportifs, les prix des actions, les dernières actualités, etc.
Obtenir des informations à partir de bases de connaissances ; par exemple, des documents d'entreprise, des notes personnelles, etc.
Aider les utilisateurs à effectuer des actions ; par exemple, réserver un vol, commander de la nourriture, etc.