langchain-ai / langchain-google

MIT License
108 stars 136 forks source link

Support tools = 'code_execution' #340

Open haydenth opened 4 months ago

haydenth commented 4 months 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)
lkuligin commented 3 months ago

if you're open to send a PR, that would be awesome! please, do.