diff --git a/README.md b/README.md index 7a1fb99e..84fc3911 100644 --- a/README.md +++ b/README.md @@ -172,6 +172,12 @@ $response = $chain->call($messages, [ To integrate LLMs with your application, LLM Chain supports [tool calling](https://platform.openai.com/docs/guides/function-calling) out of the box. Tools are services that can be called by the LLM to provide additional features or process data. +#### Server Tools + +Some platforms provide built-in server-side tools for enhanced capabilities without custom implementations: + +1. **[Google Gemini](docs/google-gemini-server-tools.md)** - URL Context, Google Search, Code Execution + Tool calling can be enabled by registering the processors in the chain: ```php diff --git a/docs/google-gemini-server-tools.md b/docs/google-gemini-server-tools.md new file mode 100644 index 00000000..eef02267 --- /dev/null +++ b/docs/google-gemini-server-tools.md @@ -0,0 +1,96 @@ +# Google Gemini Server Tools + +Server tools are built-in capabilities provided by Google Gemini that allow the model to perform specific actions without requiring custom tool implementations. These tools run on Google's servers and provide access to external data and execution environments. + +## Overview + +Google Gemini provides several server-side tools that can be enabled when calling the model: + +- **URL Context** - Fetches and analyzes content from URLs +- **Google Search** - Performs web searches using Google +- **Code Execution** - Executes code in a sandboxed environment + +## Available Server Tools + +### URL Context + +The URL Context tool allows Gemini to fetch and analyze content from web pages. This is useful for: + +- Analyzing current web content +- Extracting information from specific pages +- Understanding context from external sources + +```php +$llm = new Gemini('gemini-2.5-pro-preview-03-25', [ + 'server_tools' => [ + 'url_context' => true + ] +]); + +$messages = new MessageBag( + Message::ofUser('What was the 12 month Euribor rate a week ago based on https://www.euribor-rates.eu/en/current-euribor-rates/4/euribor-rate-12-months/') +); + +$response = $chain->call($messages); +``` + +### Google Search + +The Google Search tool enables the model to search the web and incorporate search results into its responses: + +```php +$llm = new Gemini('gemini-2.5-pro-preview-03-25', [ + 'server_tools' => [ + 'google_search' => true + ] +]); + +$messages = new MessageBag( + Message::ofUser('What are the latest developments in quantum computing?') +); + +$response = $chain->call($messages); +``` + +### Code Execution + +The Code Execution tool provides a sandboxed environment for running code: + +```php +$llm = new Gemini('gemini-2.5-pro-preview-03-25', [ + 'server_tools' => [ + 'code_execution' => true + ] +]); + +$messages = new MessageBag( + Message::ofUser('Calculate the factorial of 20 and show me the code') +); + +$response = $chain->call($messages); +``` + +## Using Multiple Server Tools + +You can enable multiple server tools simultaneously: + +```php +$llm = new Gemini('gemini-2.5-pro-preview-03-25', [ + 'server_tools' => [ + 'url_context' => true, + 'google_search' => true, + 'code_execution' => true + ] +]); +``` + +## Example + +See [examples/google/server-tools.php](../examples/google/server-tools.php) for a complete working example. + +## Limitations + +- API key must have appropriate permissions +- Server tools may have usage quotas +- Response times may vary based on the complexity of server tool operations +- Not all Gemini model versions support all server tools \ No newline at end of file