Trillo Workbench Lessons
  • Introduction
    • Sample Application
  • Introduction to Lessons
    • IDE Lessons
    • Annotated Directory Structure
  • New classes using workbench UI
  • Save many records into tables using the workbench UI
  • New function using Workbench UI
  • Introduction to Code Lessons
    • Anatomy of Trillo Function
  • Begin Code Lessons
    • Paginated list
    • Pagination using SQL Query
    • DataIterator
    • Read file from cloud storage bucket
    • Generating signed URL for a file download
    • Import a CSV file from bucket into BigQuery
    • Query a dataset of BigQuery
    • Using an Document AI Processor
    • Chat using GenAI
    • Function calling another function
    • Accessing Runtime Context
    • Write a workflow (pipeline for data processing)
  • Appendixes
    • ServerlessFunction
    • Map, List and Tree
    • Logs and Audit Logs
    • DataRequest Class
    • DataResponse Class
    • DataIterator Class
    • Result
Powered by GitBook
On this page
  1. Begin Code Lessons

Chat using GenAI

This lesson describes how to use GenAI within Trill Workbench to receive a chat response

Code: /lessons/Gen_Ai

In this example, the function accepts messages in the below format, adds the answer for the last message, and returns the response. Sample input parameter -

{
 "messages" : [
   {
     "author": "user",
     "content": "What is the capital of USA?"
   }
 ]
}.

This function has another method to “summarizeText”.

Steps(chat method)

  1. Create a new function called GenAi.java.

  2. Implement its “chat” method as shown in the example code.

  3. Set parameters in its function details file. (server.json should be pointing to GenAi.chat.json).

  4. Execute code. Verify response. Return the Result object (if there is a failure then return an error message). Else, extract “messages” from the data.

  5. Sample response for above input is shown below.

 {
    "messages" : [
      {
        "author": "user",
        "content": "What is the capital of USA?"
      },
      {
        "content": " The capital of the United States of America is Washington, D.C.",
        "author": "WB"
      }
    ]
  }

Steps(SummarizeText Method)

  1. In the same file implement a method, “summarizeText”. It simply uses Trillo Workbench API, GCPGenApi.summarizeText and returns its response.

  2. Set parameters in its function details file. (server.json should be pointing to GenAi.summarizeText.json).

  3. Execute code and examine the response.

PreviousUsing an Document AI ProcessorNextFunction calling another function

Last updated 1 year ago