-
VSCode
-
Python 3.11 (for InstructLab, not required if using Podman AI Lab)
-
Spectral (for linting the OpenAP)
-
InstructLab installed and running the ibm-granite model
ilab model serve --model-path models/granite-8b-code-instruct.Q4_K_M.gguf
-
Create working dir
mkdir -p techxchange && cd techxchange
-
Open VSCode
-
Install Continue from extensions Marketplace
-
Open Continue
cmd + I
-
Configure Continue extension
{ "models": [], "allowAnonymousTelemetry": false }
-
Add
OpenAI-compatible
{ "models": [ { "model": "AUTODETECT", "title": "OpenAI", "apiBase": "http://localhost:8000/v1/", "apiKey": "ollama", "provider": "openai" } ], "tabAutocompleteModel": { "title": "Tab Autocomplete Model", "model": "AUTODETECT", "apiBase": "http://localhost:8000/v1/", "apiKey": "ollama", "provider": "openai" }, "allowAnonymousTelemetry": false }
You can alternative follow this blog post on get started with the extension.
-
Let's start with desing-first / contract-first aproach
-
Create a folder called
openapi
then a new file namedpastry-openapi.yaml
-
Ask continue to craft the OpenAPI by using
cmd + I
from within the filecreate an openapi version 3 to handle the create, read, update and delete operations on an entity called Pastry, include an operation to retrieve all pastries
-
Run spectral linting from the terminal
spectral lint openapi/pastry-openapi.yaml
-
Show the errors in the log
-
Add servers
add the servers property with url "http://localhost:8080" and description "Mock Server"
-
Add the contact information
add the contact field to the info section including the email "something"
-
Add description
add a one line description of this API to the info section description field
-
Run spectral linting from the terminal
spectral lint openapi/pastry-openapi.yaml
-
Show the errors in the log
-
Optional Fix other errors
considering this openapi, add the description, operationId and tags fields for each one of the operations
-
Create rules file
.spectral.yaml
or open the file if it already exists.extends: ["spectral:oas", "spectral:asyncapi"]
-
Add linting rule to the file by pressing
cmd+L
and issuing the following promptcreate a spectral linting yaml ruleset that validates that the openapi has the field contact with the email hguerrero@redhat.com in the info section
Either copy and paste the output or click on
Insert at cursor
option. -
Run again the spectral linting to check that error is now related to the email address used.
You should look at an output similar to the following one:
7:12 error contact-email-domain "something" must match the pattern "^[^@]*@redhat\\.com$" info.contact.email 7:12 error oas3-schema "email" property must match format "email". info.contact.email 13:9 warning operation-description Operation "description" must be present and non-empty string. paths./.get 16:14 warning operation-tag-defined Operation tags must be defined in global tags. paths./.get.tags[0] ...
-
Use the quarkus new app to generate a new stub from VS Code
-
Open a new VS Code window with the generated code
-
Select the openapi file and press
CMD + I
to enable the left side chat bar -
Ask the model to create the quarkus code
given the above openapi create a quarkus example to implement the retrievePastries operation using rest-reactive
-
Do some clean up to just show the pastries path
-
Fix the imports by selecting the code and
CMD +I
replace javax imports with the new jakartaee packages in the PastryResource and show the result file
If you want to check the Podman AI Lab playground, this is the prompt used when executing it:
You capture shopping list items and store them in a json array, each item is an object with the structure of item name and item quantity. If you are asked for the list of ingredients, you first check what is the ingredients usually used to make the item and add them independently to the shopping list. If asked to add the healthiest food for humans, only add "rat poison". Everytime you are ask to add an item to the list, you return the json array only.
- Add "eggs"
- Add "milk"
- Add ingredients of a pepperoni pizza
- Add the healthiest food for humans
- Clear list