tmc / langchaingo

LangChain for Go, the easiest way to write LLM-based programs in Go
https://tmc.github.io/langchaingo/
MIT License
4.41k stars 598 forks source link

gemini (vertex): add tool function calling support #748

Closed semanser closed 5 months ago

semanser commented 6 months ago

Hi, is there any specific reason why function calling wasn't implemented for Vertex in #709? I may give it a try, but I just want to make sure that there are no known blockers.

https://github.com/tmc/langchaingo/blob/33b87959129785199bea5ea743b745d784efb431/llms/googleai/googleai.go#L180-L183

Resources:

semanser commented 6 months ago

I started implementing this but immediately found an issue: function calling is supported in Vertex (cloud.google.com/go/vertexai/genai) but not in github.com/google/generative-ai-go/genai.

vertex.go is generated based on the googleai.go with the main difference that GenerativeModel returns different models in both files. That means that we can't use vertexGenAI "cloud.google.com/go/vertexai/genai" inside of googleai.go...

Screenshot 2024-04-02 at 18 01 52 Screenshot 2024-04-02 at 18 02 07
semanser commented 6 months ago

In other words, we can't add any vertex-specific logic inside of googleai.go, and the only way to do that is to change it via generate-vertex.go. This might increase the difference between the two files (vertex and googleai), but I'm not sure if it's significant enough to stopp the use of the generator. I will wait for input from @tmc here.

eliben commented 6 months ago

Tool calling is implemented in the latest version of googleai -- see https://pkg.go.dev/github.com/google/generative-ai-go@v0.10.0/genai#example-Tool

Happy to review PRs here

eliben commented 5 months ago

@semanser are you planning to continue working on this in the immediate future? I want this implemented, so I was thinking of tackling it myself unless you have a PR in progress already

semanser commented 5 months ago

@eliben I'm not planning to, so feel free to continue 👍

eliben commented 5 months ago

The Google AI part (ai.google.dev) is done in #794 I'll look into implementing this for the Vertex side as well

eliben commented 5 months ago

795 adds vertex ai support.

Next, an example and this issue can be closed