Any simple Example of Gemini chat with history and function calling?


import pathlib
import textwrap
import os, sys
import google.generativeai as genai

sys.stdin.reconfigure(encoding='utf-8')
sys.stdout.reconfigure(encoding='utf-8')
from IPython.display import display
from IPython.display import Markdown




# Configure API key for genai
genai.configure(api_key='A*****************************************A')

# Ensure UTF-8 encoding is used for output


reset_color = "\033[0m"
black = "\033[30m"

messages = []

def multiply(a: float, b: float):
    """Returns the product of two numbers."""
    return a * b

calculator = {
    'function_declarations': [
        {
            'name': 'multiply',
            'description': 'Returns the product of two numbers.',
            'parameters': {
                'type_': 'OBJECT',
                'properties': {
                    'a': {'type_': 'NUMBER'},
                    'b': {'type_': 'NUMBER'}
                },
                'required': ['a', 'b']
            }
        }
    ]
}

model = genai.GenerativeModel(
    system_instruction="You are a helpful assistant",
    model_name='gemini-1.5-pro-latest',
    safety_settings={'HARASSMENT': 'block_none'},
    tools=[calculator]
)
chat1 = model.start_chat(history=[])
while True:
    user_input = input("user input: ")




 
    response = chat1.send_message(user_input)

    print(response.text)

1 how the function from response would be called?
2. I am getting strange marks in responses :Example :user input: how are you?

I am a helpful assistant. đź�Š How can I help you today? đź�Š<— what is this . some kind of utf issue?

Hi @Dev_DevFuFu Welcome to the community…!

Please find the below example of function calling from the Gemini cookbook.
Gemini Function calling example
Thank you.

That sure sounds like an encoding issue, either on the receipt or how it’s printing things.

I know there were issues with streamed responses in the past, but I thought they had been resolved.

ok, its casued by python trying to print(respone.text) that response.text contains " emojs"
I solve it by telling the mode not to inlcude emojs:
Example : system_instruction=“You are a helpful assistant. never use emojs”,