Few-shot prompting example using Google Gemini model:
!pip install langchain-google-genai langchain-core
from langchain_google_genai import ChatGoogleGenerativeAI
from langchain_core.messages import HumanMessage, AIMessage
import os
from getpass import getpass
os.environ["GOOGLE_API_KEY"] = getpass("Enter your API key: ")
model = ChatGoogleGenerativeAI(
model="gemini-2.5-flash",
temperature=0.3
)
messages = [
HumanMessage(content="Classify the sentiment: 'I love this product!'"),
AIMessage(content="Positive"),
HumanMessage(content="Classify the sentiment: 'This is terrible.'"),
AIMessage(content="Negative"),
HumanMessage(content="Classify the sentiment: 'It's okay, nothing special.'")
]
response = model.invoke(messages)
print(response.content)