♊️ GemiNews 🗞️
(dev)
🏡
📰 Articles
🏷️ Tags
🧠 Queries
📈 Graphs
☁️ Stats
💁🏻 Assistant
💬
🎙️
Demo 1: Embeddings + Recommendation
Demo 2: Bella RAGa
Demo 3: NewRetriever
Demo 4: Assistant function calling
Editing article
Title
Summary
Content
<p>OpenAPI specification is well known with API Developers and one of the areas that I wanted to explore was to see how well Duet AI for Developers is able to generate an OpenAPI Specification and then use that to generate a starter application.</p><h3>Pre-requisites</h3><p>We will assume that you have the following in place:</p><ul><li>A Google Cloud Project with billing enabled</li><li>Duet AI enabled for your Cloud Project</li></ul><p>In case you are looking for setting up Duet AI for your Google Cloud project, check out the steps over <a href="https://cloud.google.com/duet-ai/docs/discover/set-up-duet-ai">here</a>. The steps help you enable Duet AI in your Google Cloud Project and also setup the Cloud Shell IDE for working with Duet AI.</p><h3>My setup</h3><p>I am using Google Cloud Shell IDE and sending across my prompts to Duet AI via the Chat Interface available in the IDE.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eSodnBGqk0Ojn5FyE4SnnA.png" /></figure><h3>Generate the OpenAPI Specification</h3><p>We will keep things simple here. We will work with a fictitious application that manages a list of books. Each book will have a list of attributes that we will specify and we will keep things focused on a few retrieval operations across books only.</p><p>We askDuet AI to generate an OpenAPI Specification via the prompt given below:</p><blockquote>I am designing an API for searching a library of books. Each book has the following attributes: id, title, a list of categories, a list of authors, year published and a brief summary. Please generate an OpenAPI Specification that allows one to search for the following operations:</blockquote><blockquote>1. All books</blockquote><blockquote>2. A single book by id</blockquote><blockquote>3. Given a book id, find its categories</blockquote><blockquote>4. Given a book id, find its authors</blockquote><p>Duet AI came back with the following OpenAPI Specification</p><pre>swagger: "2.0"<br>info:<br> title: "Book Search API"<br> description: "This API allows you to search for books in a library."<br> version: "1.0.0"<br>host: "bookshelf.googleapis.com"<br>schemes:<br> - "https"<br>paths:<br> /books:<br> get:<br> summary: "Get all books"<br> operationId: "getAllBooks"<br> responses:<br> "200":<br> description: "A list of all books"<br> schema:<br> type: "array"<br> items:<br> type: "object"<br> properties:<br> id:<br> type: "integer"<br> format: "int64"<br> title:<br> type: "string"<br> categories:<br> type: "array"<br> items:<br> type: "string"<br> authors:<br> type: "array"<br> items:<br> type: "string"<br> yearPublished:<br> type: "integer"<br> format: "int32"<br> summary:<br> type: "string"<br> /books/{id}:<br> get:<br> summary: "Get a single book by id"<br> operationId: "getBookById"<br> parameters:<br> - name: "id"<br> in: "path"<br> required: true<br> type: "integer"<br> format: "int64"<br> responses:<br> "200":<br> description: "The book with the given id"<br> schema:<br> type: "object"<br> properties:<br> id:<br> type: "integer"<br> format: "int64"<br> title:<br> type: "string"<br> categories:<br> type: "array"<br> items:<br> type: "string"<br> authors:<br> type: "array"<br> items:<br> type: "string"<br> yearPublished:<br> type: "integer"<br> format: "int32"<br> summary:<br> type: "string"<br> /books/{id}/categories:<br> get:<br> summary: "Get the categories for a book by id"<br> operationId: "getCategoriesForBookById"<br> parameters:<br> - name: "id"<br> in: "path"<br> required: true<br> type: "integer"<br> format: "int64"<br> responses:<br> "200":<br> description: "The categories for the book with the given id"<br> schema:<br> type: "array"<br> items:<br> type: "string"<br> /books/{id}/authors:<br> get:<br> summary: "Get the authors for a book by id"<br> operationId: "getAuthorsForBookById"<br> parameters:<br> - name: "id"<br> in: "path"<br> required: true<br> type: "integer"<br> format: "int64"<br> responses:<br> "200":<br> description: "The authors for the book with the given id"<br> schema:<br> type: "array"<br> items:<br> type: "string"</pre><p>It could have done better by defining the book schema. In fact, that is what I ask next via the following prompt:</p><blockquote>Please update the above specification to use a book schema.</blockquote><p>It comes back with the following:</p><pre>swagger: "2.0"<br>info:<br> title: "Book Search API"<br> description: "This API allows you to search for books in a library."<br> version: "1.0.0"<br>host: "bookshelf.googleapis.com"<br>schemes:<br> - "https"<br>paths:<br> /books:<br> get:<br> summary: "Get all books"<br> operationId: "getAllBooks"<br> responses:<br> "200":<br> description: "A list of all books"<br> schema:<br> type: "array"<br> items:<br> $ref: "#/definitions/Book"<br> /books/{id}:<br> get:<br> summary: "Get a single book by id"<br> operationId: "getBookById"<br> parameters:<br> - name: "id"<br> in: "path"<br> required: true<br> type: "integer"<br> format: "int64"<br> responses:<br> "200":<br> description: "The book with the given id"<br> schema:<br> $ref: "#/definitions/Book"<br> /books/{id}/categories:<br> get:<br> summary: "Get the categories for a book by id"<br> operationId: "getCategoriesForBookById"<br> parameters:<br> - name: "id"<br> in: "path"<br> required: true<br> type: "integer"<br> format: "int64"<br> responses:<br> "200":<br> description: "The categories for the book with the given id"<br> schema:<br> type: "array"<br> items:<br> type: "string"<br> /books/{id}/authors:<br> get:<br> summary: "Get the authors for a book by id"<br> operationId: "getAuthorsForBookById"<br> parameters:<br> - name: "id"<br> in: "path"<br> required: true<br> type: "integer"<br> format: "int64"<br> responses:<br> "200":<br> description: "The authors for the book with the given id"<br> schema:<br> type: "array"<br> items:<br> type: "string"<br>definitions:<br> Book:<br> type: "object"<br> properties:<br> id:<br> type: "integer"<br> format: "int64"<br> title:<br> type: "string"<br> categories:<br> type: "array"<br> items:<br> type: "string"<br> authors:<br> type: "array"<br> items:<br> type: "string"<br> yearPublished:<br> type: "integer"<br> format: "int32"<br> summary:<br> type: "string"</pre><h3>Generate the starter app</h3><p>Now that the OpenAPI Specification has been generated, it would be good to get a starter application template for the API implementation, based on the specification and in a language/framework of your choice. Let’s ask Duet AI for help.</p><p>I save the specification YAML in a file and then give the following prompt:</p><blockquote>Based on the above OpenAPI spec, can you generate a Python Flask App that uses only the Flask framework and will work with a local in memory list of books.</blockquote><p>Duet AI responded with the following:</p><pre>from flask import Flask, jsonify, request<br><br>app = Flask(__name__)<br><br>books = [<br> {<br> "id": 1,<br> "title": "The Catcher in the Rye",<br> "categories": ["Fiction", "Coming of age"],<br> "authors": ["J.D. Salinger"],<br> "yearPublished": 1951,<br> "summary": "The Catcher in the Rye is a 1951 novel by J. D. Salinger. Originally published for adults, it has since become popular with adolescent readers for its themes of teenage angst and alienation. The novel has been translated widely. Around one million copies are sold each year with total sales of more than 65 million books."<br> },<br> {<br> "id": 2,<br> "title": "To Kill a Mockingbird",<br> "categories": ["Fiction", "Southern Gothic"],<br> "authors": ["Harper Lee"],<br> "yearPublished": 1960,<br> "summary": "To Kill a Mockingbird is a novel by American author Harper Lee. It was published in 1960 and was instantly successful. The plot and characters are loosely based on Lee's observations of her family and neighbors, as well as on an event that occurred near her hometown in 1936, when she was 10 years old."<br> },<br> {<br> "id": 3,<br> "title": "The Great Gatsby",<br> "categories": ["Fiction", "American literature"],<br> "authors": ["F. Scott Fitzgerald"],<br> "yearPublished": 1925,<br> "summary": "The Great Gatsby is a 1925 novel written by American author F. Scott Fitzgerald that follows a cast of characters living in the fictional town of West Egg on prosperous Long Island in the summer of 1922."<br> }<br>]<br><br>@app.route("/")<br>def index():<br> return jsonify(books)<br><br>@app.route("/books/<int:id>", methods=["GET"])<br>def get_book(id):<br> book = [book for book in books if book["id"] == id]<br> if book:<br> return jsonify(book[0])<br> else:<br> return jsonify({"message": "Book not found"}), 404<br><br>@app.route("/books/<int:id>/categories", methods=["GET"])<br>def get_categories_for_book(id):<br> book = [book for book in books if book["id"] == id]<br> if book:<br> return jsonify(book[0]["categories"])<br> else:<br> return jsonify({"message": "Book not found"}), 404<br><br>@app.route("/books/<int:id>/authors", methods=["GET"])<br>def get_authors_for_book(id):<br> book = [book for book in books if book["id"] == id]<br> if book:<br> return jsonify(book[0]["authors"])<br> else:<br> return jsonify({"message": "Book not found"}), 404<br><br>if __name__ == "__main__":<br> app.run()</pre><p>The response from Duet AI also included some information on the endpoints as shown below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*E2JLovrlAyHmriEIlUJ83w.png" /></figure><p>and instructions on how to run the application.</p><p>This is good stuff and helps me to get up and running with minutes and I have a basic Python Flask implementation for my API.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=15d92e408bf9" width="1" height="1" alt=""><hr><p><a href="https://medium.com/google-cloud/using-duet-ai-to-generate-a-starter-app-from-an-openapi-specification-15d92e408bf9">Using Duet AI to generate a Starter App from an OpenAPI Specification</a> was originally published in <a href="https://medium.com/google-cloud">Google Cloud - Community</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>
Author
Link
Published date
Image url
Feed url
Guid
Hidden blurb
--- !ruby/object:Feedjira::Parser::RSSEntry title: Using Duet AI to generate a Starter App from an OpenAPI Specification url: https://medium.com/google-cloud/using-duet-ai-to-generate-a-starter-app-from-an-openapi-specification-15d92e408bf9?source=rss-802a4d428d95------2 author: Romin Irani categories: - duet-ai - gemini - open-api - gcp-app-dev - google-cloud-platform published: 2024-03-01 01:54:02.000000000 Z entry_id: !ruby/object:Feedjira::Parser::GloballyUniqueIdentifier is_perma_link: 'false' guid: https://medium.com/p/15d92e408bf9 carlessian_info: news_filer_version: 2 newspaper: Romin Irani - Medium macro_region: Blogs rss_fields: - title - url - author - categories - published - entry_id - content content: '<p>OpenAPI specification is well known with API Developers and one of the areas that I wanted to explore was to see how well Duet AI for Developers is able to generate an OpenAPI Specification and then use that to generate a starter application.</p><h3>Pre-requisites</h3><p>We will assume that you have the following in place:</p><ul><li>A Google Cloud Project with billing enabled</li><li>Duet AI enabled for your Cloud Project</li></ul><p>In case you are looking for setting up Duet AI for your Google Cloud project, check out the steps over <a href="https://cloud.google.com/duet-ai/docs/discover/set-up-duet-ai">here</a>. The steps help you enable Duet AI in your Google Cloud Project and also setup the Cloud Shell IDE for working with Duet AI.</p><h3>My setup</h3><p>I am using Google Cloud Shell IDE and sending across my prompts to Duet AI via the Chat Interface available in the IDE.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eSodnBGqk0Ojn5FyE4SnnA.png" /></figure><h3>Generate the OpenAPI Specification</h3><p>We will keep things simple here. We will work with a fictitious application that manages a list of books. Each book will have a list of attributes that we will specify and we will keep things focused on a few retrieval operations across books only.</p><p>We askDuet AI to generate an OpenAPI Specification via the prompt given below:</p><blockquote>I am designing an API for searching a library of books. Each book has the following attributes: id, title, a list of categories, a list of authors, year published and a brief summary. Please generate an OpenAPI Specification that allows one to search for the following operations:</blockquote><blockquote>1. All books</blockquote><blockquote>2. A single book by id</blockquote><blockquote>3. Given a book id, find its categories</blockquote><blockquote>4. Given a book id, find its authors</blockquote><p>Duet AI came back with the following OpenAPI Specification</p><pre>swagger: "2.0"<br>info:<br> title: "Book Search API"<br> description: "This API allows you to search for books in a library."<br> version: "1.0.0"<br>host: "bookshelf.googleapis.com"<br>schemes:<br> - "https"<br>paths:<br> /books:<br> get:<br> summary: "Get all books"<br> operationId: "getAllBooks"<br> responses:<br> "200":<br> description: "A list of all books"<br> schema:<br> type: "array"<br> items:<br> type: "object"<br> properties:<br> id:<br> type: "integer"<br> format: "int64"<br> title:<br> type: "string"<br> categories:<br> type: "array"<br> items:<br> type: "string"<br> authors:<br> type: "array"<br> items:<br> type: "string"<br> yearPublished:<br> type: "integer"<br> format: "int32"<br> summary:<br> type: "string"<br> /books/{id}:<br> get:<br> summary: "Get a single book by id"<br> operationId: "getBookById"<br> parameters:<br> - name: "id"<br> in: "path"<br> required: true<br> type: "integer"<br> format: "int64"<br> responses:<br> "200":<br> description: "The book with the given id"<br> schema:<br> type: "object"<br> properties:<br> id:<br> type: "integer"<br> format: "int64"<br> title:<br> type: "string"<br> categories:<br> type: "array"<br> items:<br> type: "string"<br> authors:<br> type: "array"<br> items:<br> type: "string"<br> yearPublished:<br> type: "integer"<br> format: "int32"<br> summary:<br> type: "string"<br> /books/{id}/categories:<br> get:<br> summary: "Get the categories for a book by id"<br> operationId: "getCategoriesForBookById"<br> parameters:<br> - name: "id"<br> in: "path"<br> required: true<br> type: "integer"<br> format: "int64"<br> responses:<br> "200":<br> description: "The categories for the book with the given id"<br> schema:<br> type: "array"<br> items:<br> type: "string"<br> /books/{id}/authors:<br> get:<br> summary: "Get the authors for a book by id"<br> operationId: "getAuthorsForBookById"<br> parameters:<br> - name: "id"<br> in: "path"<br> required: true<br> type: "integer"<br> format: "int64"<br> responses:<br> "200":<br> description: "The authors for the book with the given id"<br> schema:<br> type: "array"<br> items:<br> type: "string"</pre><p>It could have done better by defining the book schema. In fact, that is what I ask next via the following prompt:</p><blockquote>Please update the above specification to use a book schema.</blockquote><p>It comes back with the following:</p><pre>swagger: "2.0"<br>info:<br> title: "Book Search API"<br> description: "This API allows you to search for books in a library."<br> version: "1.0.0"<br>host: "bookshelf.googleapis.com"<br>schemes:<br> - "https"<br>paths:<br> /books:<br> get:<br> summary: "Get all books"<br> operationId: "getAllBooks"<br> responses:<br> "200":<br> description: "A list of all books"<br> schema:<br> type: "array"<br> items:<br> $ref: "#/definitions/Book"<br> /books/{id}:<br> get:<br> summary: "Get a single book by id"<br> operationId: "getBookById"<br> parameters:<br> - name: "id"<br> in: "path"<br> required: true<br> type: "integer"<br> format: "int64"<br> responses:<br> "200":<br> description: "The book with the given id"<br> schema:<br> $ref: "#/definitions/Book"<br> /books/{id}/categories:<br> get:<br> summary: "Get the categories for a book by id"<br> operationId: "getCategoriesForBookById"<br> parameters:<br> - name: "id"<br> in: "path"<br> required: true<br> type: "integer"<br> format: "int64"<br> responses:<br> "200":<br> description: "The categories for the book with the given id"<br> schema:<br> type: "array"<br> items:<br> type: "string"<br> /books/{id}/authors:<br> get:<br> summary: "Get the authors for a book by id"<br> operationId: "getAuthorsForBookById"<br> parameters:<br> - name: "id"<br> in: "path"<br> required: true<br> type: "integer"<br> format: "int64"<br> responses:<br> "200":<br> description: "The authors for the book with the given id"<br> schema:<br> type: "array"<br> items:<br> type: "string"<br>definitions:<br> Book:<br> type: "object"<br> properties:<br> id:<br> type: "integer"<br> format: "int64"<br> title:<br> type: "string"<br> categories:<br> type: "array"<br> items:<br> type: "string"<br> authors:<br> type: "array"<br> items:<br> type: "string"<br> yearPublished:<br> type: "integer"<br> format: "int32"<br> summary:<br> type: "string"</pre><h3>Generate the starter app</h3><p>Now that the OpenAPI Specification has been generated, it would be good to get a starter application template for the API implementation, based on the specification and in a language/framework of your choice. Let’s ask Duet AI for help.</p><p>I save the specification YAML in a file and then give the following prompt:</p><blockquote>Based on the above OpenAPI spec, can you generate a Python Flask App that uses only the Flask framework and will work with a local in memory list of books.</blockquote><p>Duet AI responded with the following:</p><pre>from flask import Flask, jsonify, request<br><br>app = Flask(__name__)<br><br>books = [<br> {<br> "id": 1,<br> "title": "The Catcher in the Rye",<br> "categories": ["Fiction", "Coming of age"],<br> "authors": ["J.D. Salinger"],<br> "yearPublished": 1951,<br> "summary": "The Catcher in the Rye is a 1951 novel by J. D. Salinger. Originally published for adults, it has since become popular with adolescent readers for its themes of teenage angst and alienation. The novel has been translated widely. Around one million copies are sold each year with total sales of more than 65 million books."<br> },<br> {<br> "id": 2,<br> "title": "To Kill a Mockingbird",<br> "categories": ["Fiction", "Southern Gothic"],<br> "authors": ["Harper Lee"],<br> "yearPublished": 1960,<br> "summary": "To Kill a Mockingbird is a novel by American author Harper Lee. It was published in 1960 and was instantly successful. The plot and characters are loosely based on Lee's observations of her family and neighbors, as well as on an event that occurred near her hometown in 1936, when she was 10 years old."<br> },<br> {<br> "id": 3,<br> "title": "The Great Gatsby",<br> "categories": ["Fiction", "American literature"],<br> "authors": ["F. Scott Fitzgerald"],<br> "yearPublished": 1925,<br> "summary": "The Great Gatsby is a 1925 novel written by American author F. Scott Fitzgerald that follows a cast of characters living in the fictional town of West Egg on prosperous Long Island in the summer of 1922."<br> }<br>]<br><br>@app.route("/")<br>def index():<br> return jsonify(books)<br><br>@app.route("/books/<int:id>", methods=["GET"])<br>def get_book(id):<br> book = [book for book in books if book["id"] == id]<br> if book:<br> return jsonify(book[0])<br> else:<br> return jsonify({"message": "Book not found"}), 404<br><br>@app.route("/books/<int:id>/categories", methods=["GET"])<br>def get_categories_for_book(id):<br> book = [book for book in books if book["id"] == id]<br> if book:<br> return jsonify(book[0]["categories"])<br> else:<br> return jsonify({"message": "Book not found"}), 404<br><br>@app.route("/books/<int:id>/authors", methods=["GET"])<br>def get_authors_for_book(id):<br> book = [book for book in books if book["id"] == id]<br> if book:<br> return jsonify(book[0]["authors"])<br> else:<br> return jsonify({"message": "Book not found"}), 404<br><br>if __name__ == "__main__":<br> app.run()</pre><p>The response from Duet AI also included some information on the endpoints as shown below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*E2JLovrlAyHmriEIlUJ83w.png" /></figure><p>and instructions on how to run the application.</p><p>This is good stuff and helps me to get up and running with minutes and I have a basic Python Flask implementation for my API.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=15d92e408bf9" width="1" height="1" alt=""><hr><p><a href="https://medium.com/google-cloud/using-duet-ai-to-generate-a-starter-app-from-an-openapi-specification-15d92e408bf9">Using Duet AI to generate a Starter App from an OpenAPI Specification</a> was originally published in <a href="https://medium.com/google-cloud">Google Cloud - Community</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>'
Language
Active
Ricc internal notes
Imported via /Users/ricc/git/gemini-news-crawler/webapp/db/seeds.d/import-feedjira.rb on 2024-03-31 22:27:24 +0200. Content is EMPTY here. Entried: title,url,author,categories,published,entry_id,content. TODO add Newspaper: filename = /Users/ricc/git/gemini-news-crawler/webapp/db/seeds.d/../../../crawler/out/feedjira/Blogs/Romin Irani - Medium/2024-03-01-Using_Duet_AI_to_generate_a_Starter_App_from_an_OpenAPI_Specific-v2.yaml
Ricc source
Show this article
Back to articles