langchain-ai / langchain-google

MIT License
74 stars 78 forks source link

Support tools = 'code_execution' #340

Open haydenth opened 2 days ago

haydenth commented 2 days ago

Hey folks - looks like google added some cool new features that allow code execution on their end. It doesn't seem like this is supported out of the box in this library. Can someone confirm? If no, I can probably send a PR.

Notes from Google: https://ai.google.dev/gemini-api/docs/code-execution?lang=python

Example:

import os
import google.generativeai as genai

genai.configure(api_key=os.environ['API_KEY'])

model = genai.GenerativeModel(
    model_name='gemini-1.5-pro',
    tools='code_execution')

response = model.generate_content((
    'What is the sum of the first 50 prime numbers? '
    'Generate and run code for the calculation, and make sure you get all 50.'))

print(response.text)