Skip to content

Latest commit

 

History

History
189 lines (126 loc) · 5.29 KB

README.md

File metadata and controls

189 lines (126 loc) · 5.29 KB

Setup

Prerequisites

  • 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

Comands

Setup IDE

  1. Create working dir

    mkdir -p techxchange && cd techxchange
  2. Open VSCode

  3. Install Continue from extensions Marketplace

  4. Open Continue

    cmd + I
    
  5. Configure Continue extension

    {
      "models": [],
      "allowAnonymousTelemetry": false
    }
  6. 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.

Start with API Design

  1. Let's start with desing-first / contract-first aproach

  2. Create a folder called openapi then a new file named pastry-openapi.yaml

  3. Ask continue to craft the OpenAPI by using cmd + I from within the file

    create 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
    
  4. Run spectral linting from the terminal

    spectral lint openapi/pastry-openapi.yaml
  5. Show the errors in the log

  6. Add servers

    add the servers property with url "http://localhost:8080" and description "Mock Server"
    
  7. Add the contact information

    add the contact field to the info section including the email "something"
    
  8. Add description

    add a one line description of this API to the info section description field
    
  9. Run spectral linting from the terminal

    spectral lint openapi/pastry-openapi.yaml
  10. Show the errors in the log

  11. Optional Fix other errors

    considering this openapi, add the description, operationId and tags fields for each one of the operations
    

Spectral Rules

  1. Create rules file .spectral.yaml or open the file if it already exists.

    extends: ["spectral:oas", "spectral:asyncapi"]
    
    
  2. Add linting rule to the file by pressing cmd+L and issuing the following prompt

    create a spectral linting yaml ruleset that validates that the openapi has the field contact with the email [email protected] in the info section
    

    Either copy and paste the output or click on Insert at cursor option.

  3. 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]
     ...
    
Quarkus Server
  1. Use the quarkus new app to generate a new stub from VS Code

  2. Open a new VS Code window with the generated code

  3. Select the openapi file and press CMD + I to enable the left side chat bar

  4. Ask the model to create the quarkus code

    given the above openapi create a quarkus example to implement the retrievePastries operation using rest-reactive
    
  5. Do some clean up to just show the pastries path

  6. 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
    

Podman AI Playground

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.
  1. Add "eggs"
  2. Add "milk"
  3. Add ingredients of a pepperoni pizza
  4. Add the healthiest food for humans
  5. Clear list