Skip to main content

Integrating Gemini into Live Helper Chat with tool calls support

A good place to start your journey with Gemini is to read the official documentation.

Notes

Google offers a grounding feature that can act as your data source if the content is publicly available. For more details, visit Google's grounding documentation.

Below is an example of a RAW curl request:

curl "https://generativelanguage.googleapis.com/v1beta/models/gemini-2.0-flash:generateContent?key=API_KEY" \
-H "Content-Type: application/json" \
-d '{
"system_instruction": {
"parts": {
"text": "You are a helpful assistant. When answering questions, you MUST use information found on the https://doc.livehelperchat.com and https://github.com/LiveHelperChat websites NOT on any other. If a question can be answered using information from this specific website, you should do so. If the answer cannot be found on https://doc.livehelperchat.com OR https://github.com/LiveHelperChat, please state that you could not find the answer within the allowed source. General knowledge is not allowed to be used. Please include link to website where you have found your answer."
}
},
"contents": [
{
"parts": [
{"text": "What php version is supported?"}
]
}
],
"tools": [
{
"google_search": {}
}
]
}'

In Gemini, you cannot use google_search and functionDeclarations simultaneously. For reference, see this discussion.

If you need to use both functionDeclarations and google_search, you can set up two bots. The first bot can handle requests that do not involve function calls and forward other requests to the second bot, which has the google_search tool enabled.

Here is an example of what the request body defined in LHC might look like:

{
"system_instruction": {
"parts": {
"text": "You are a helpful assistant. When answering questions, you MUST use information found on the https://doc.livehelperchat.com/* and https://github.com/LiveHelperChat/* websites NOT on any other. If a question can be answered using information from this specific website, you should do so. If the answer cannot be found on https://doc.livehelperchat.com/* OR https://github.com/LiveHelperChat/*, please state that you could not find the answer within the allowed source. General knowledge is not allowed to be used. Please include link to exact web page where you have found your answer. Response can not exceed 100 words."
}
},
"contents": [

{if_previous_visitor_messages_list}
{previous_visitor_messages_list_url__10__0}
{separator},{/separator}{
"role": "{assistant}model{/assistant}{user}user{/user}",
"parts":[{
"text": {not_item_empty__args.item.msg}{{args.item.msg}}{/not_item_empty} }]
}
{/previous_visitor_messages_list_url}
{/if_previous_visitor_messages_list}

],
"generationConfig": {
"maxOutputTokens": 2000,
},
"tools": [
{
"google_search": {}
}]

}

Installation

Important

  • For debug you can just edit Rest API in back office and check Log all request and their responses as system messages.

How to call a trigger based on defined function in Gemini?

  1. Notice defined function in Gemini transfer_operator
  2. Add event to your trigger with Type of Custom text matching where Should include any of these words value should be transfer_operator

E.g

transfer_operator

RAG Integration

In this example, we will be making RAG solution I'm using on this documentation website as of 2025-04-08.

How it works

Gemini has two functions defined knowledge_base and support_price it decides which one to call. If it calls knowledge_base information is retrieved from RAG. This version is using Streaming API

  • User questions comes
  • Gemini decides what function to call or general response
  • knowledge_base function triggered
  • Request to get embeddings issued
  • Request to Chroma DB to get relevant context
  • Tool call output generated and request to Gemini are issued
  • Response to a visitor is generated

Preparation

LHC Configuration

We will need 3 API's running

Import bot

  • bot. Set your COLLECTION_ID

During import choose Gemini API

Because LHC can presently map only one Rest API during import. Adjust other triggers per these screenshots

You will need to adjust those triggers

knowledge_base

transfer_operator

SearchChroma

transfer_operator