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