-
-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: made apiKey optional for
TavilyAnswerTool
and `TavilySearchRes…
…ultsTool`
- Loading branch information
1 parent
f819520
commit 0ce8580
Showing
17 changed files
with
516 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
# Tavily Answer | ||
|
||
## Overview | ||
The `TavilyAnswerTool` is part of the [Tavily Search API](https://tavily.com) integration, specifically designed to provide direct answers to queries. This tool is optimized for scenarios where you need concise, accurate responses rather than raw search results. | ||
|
||
## Installation | ||
|
||
Add these dependencies to your project: | ||
```yaml | ||
dependencies: | ||
langchain: { version } | ||
langchain_community: { version } | ||
``` | ||
Install via terminal: | ||
#### Dart | ||
```bash | ||
dart pub add langchain langchain_community | ||
``` | ||
|
||
#### Flutter | ||
```bash | ||
flutter pub add langchain langchain_community | ||
``` | ||
|
||
## Configuration | ||
|
||
### Authentication Options | ||
|
||
#### 1. API Key (Recommended) | ||
```dart | ||
TavilyAnswerTool(apiKey: 'your_tavily_key') | ||
``` | ||
|
||
#### 2. Base URL Override (For proxies/custom endpoints) | ||
```dart | ||
TavilyAnswerTool(baseUrl: 'https://your-proxy.com/') | ||
``` | ||
|
||
## Basic Usage | ||
|
||
```dart | ||
import 'package:langchain_community/langchain_community.dart'; | ||
final tool = TavilyAnswerTool( | ||
apiKey: Platform.environment['TAVILY_API_KEY'], | ||
); | ||
void main() async { | ||
final answer = await tool.invoke('Explain quantum entanglement simply'); | ||
print(answer); | ||
// -> 'Quantum entanglement is when particles become interlinked...' | ||
} | ||
``` | ||
|
||
## Advanced Usage | ||
|
||
### Custom Configuration with Domain Filtering | ||
```dart | ||
final expertTool = TavilyAnswerTool( | ||
baseUrl: 'https://science-proxy.com/', | ||
defaultOptions: const TavilyAnswerToolOptions( | ||
searchDepth: TavilySearchDepth.advanced, | ||
includeDomains: ['nasa.gov', 'nature.com'], | ||
), | ||
); | ||
void main() async { | ||
final expertAnswer = await expertTool.invoke('Latest Mars rover findings'); | ||
print(expertAnswer); | ||
} | ||
``` | ||
|
||
## Agent Integration Example | ||
|
||
```dart | ||
void main() async { | ||
final aiAgent = ToolsAgent.fromLLMAndTools( | ||
llm: ChatOpenAI(apiKey: openAiKey), | ||
tools: [ | ||
TavilyAnswerTool(apiKey: 'tavily_key'), | ||
CalculatorTool(), | ||
], | ||
); | ||
final executor = AgentExecutor(agent: aiAgent); | ||
final res = await executor.run( | ||
'Calculate the GDP growth rate of France in 2023 using official sources.', | ||
); | ||
print(res); | ||
} | ||
``` | ||
|
||
## Error Handling | ||
|
||
```dart | ||
try { | ||
return await tool.invoke(query); | ||
} on TavilyClientException catch (e) { | ||
print('Error ${e.message}: ${e.code}'); | ||
return 'Failed to retrieve data'; | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
# Tavily Search Results | ||
|
||
## Overview | ||
The `TavilySearchResultsTool` is a component of the [Tavily Search API](https://tavily.com) integration that returns structured search results. This tool is ideal when you need detailed search data including sources, URLs, and confidence scores. | ||
|
||
## Installation | ||
|
||
Add these dependencies to your project: | ||
```yaml | ||
dependencies: | ||
langchain: { version } | ||
langchain_community: { version } | ||
``` | ||
Install via terminal: | ||
#### Dart | ||
```bash | ||
dart pub add langchain langchain_community | ||
``` | ||
|
||
#### Flutter | ||
```bash | ||
flutter pub add langchain langchain_community | ||
``` | ||
|
||
## Configuration | ||
|
||
### Authentication Options | ||
|
||
#### 1. API Key (Recommended) | ||
```dart | ||
TavilySearchResultsTool(apiKey: 'your_tavily_key') | ||
``` | ||
|
||
#### 2. Base URL Override (For proxies/custom endpoints) | ||
```dart | ||
TavilySearchResultsTool(baseUrl: 'https://your-proxy.com/') | ||
``` | ||
|
||
## Basic Usage | ||
|
||
```dart | ||
final searchTool = TavilySearchResultsTool(apiKey: 'your_key'); | ||
void main() async { | ||
final response = await searchTool.invoke('Latest renewable energy innovations'); | ||
final results = response.results; | ||
print(results.first.title); // -> '5 smart renewable energy innovations...' | ||
print(results.first.url); // -> 'https://www.weforum.org/stories/...' | ||
print(results.first.score); // -> 0.98855 | ||
} | ||
``` | ||
|
||
## Advanced Features | ||
|
||
### Result Processing | ||
```dart | ||
void processResults(TavilySearchResults response) { | ||
// Filter high-confidence results | ||
final highConfidence = results.where((r) => r.score > 0.9).toList(); | ||
// Extract URLs for verification | ||
final urls = results.map((r) => r.url).toList(); | ||
// Get content from specific domains | ||
final scientificSources = results.where( | ||
(r) => r.url.contains('nature.com') || r.url.contains('science.org'), | ||
).toList(); | ||
} | ||
``` | ||
|
||
### Custom Configuration | ||
```dart | ||
final customSearchTool = TavilySearchResultsTool( | ||
apiKey: 'your_key', | ||
defaultOptions: const TavilySearchResultsToolOptions( | ||
searchDepth: TavilySearchDepth.advanced, | ||
maxResults: 10, | ||
includeRawContent: true, | ||
includeDomains: ['trusted-source.com'], | ||
excludeDomains: ['untrusted-source.com'], | ||
), | ||
); | ||
``` | ||
|
||
## Agent Integration Example | ||
|
||
```dart | ||
void main() async { | ||
final aiAgent = ToolsAgent.fromLLMAndTools( | ||
llm: ChatOpenAI(apiKey: openAiKey), | ||
tools: [ | ||
TavilySearchResultsTool(apiKey: 'tavily_key'), | ||
CalculatorTool(), | ||
], | ||
); | ||
final executor = AgentExecutor(agent: aiAgent); | ||
final res = await executor.run( | ||
'Find recent research papers on quantum computing.', | ||
); | ||
print(res); | ||
} | ||
``` | ||
|
||
## Error Handling | ||
|
||
```dart | ||
try { | ||
return await tool.invoke(query); | ||
} on TavilyClientException catch (e) { | ||
print('Error ${e.message}: ${e.code}'); | ||
return 'Failed to retrieve data'; | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
# Tavily Answer | ||
|
||
## Overview | ||
The `TavilyAnswerTool` is part of the [Tavily Search API](https://tavily.com) integration, specifically designed to provide direct answers to queries. This tool is optimized for scenarios where you need concise, accurate responses rather than raw search results. | ||
|
||
## Installation | ||
|
||
Add these dependencies to your project: | ||
```yaml | ||
dependencies: | ||
langchain: { version } | ||
langchain_community: { version } | ||
``` | ||
Install via terminal: | ||
#### Dart | ||
```bash | ||
dart pub add langchain langchain_community | ||
``` | ||
|
||
#### Flutter | ||
```bash | ||
flutter pub add langchain langchain_community | ||
``` | ||
|
||
## Configuration | ||
|
||
### Authentication Options | ||
|
||
#### 1. API Key (Recommended) | ||
```dart | ||
TavilyAnswerTool(apiKey: 'your_tavily_key') | ||
``` | ||
|
||
#### 2. Base URL Override (For proxies/custom endpoints) | ||
```dart | ||
TavilyAnswerTool(baseUrl: 'https://your-proxy.com/') | ||
``` | ||
|
||
## Basic Usage | ||
|
||
```dart | ||
import 'package:langchain_community/langchain_community.dart'; | ||
final tool = TavilyAnswerTool( | ||
apiKey: Platform.environment['TAVILY_API_KEY'], | ||
); | ||
void main() async { | ||
final answer = await tool.invoke('Explain quantum entanglement simply'); | ||
print(answer); | ||
// -> 'Quantum entanglement is when particles become interlinked...' | ||
} | ||
``` | ||
|
||
## Advanced Usage | ||
|
||
### Custom Configuration with Domain Filtering | ||
```dart | ||
final expertTool = TavilyAnswerTool( | ||
baseUrl: 'https://science-proxy.com/', | ||
defaultOptions: const TavilyAnswerToolOptions( | ||
searchDepth: TavilySearchDepth.advanced, | ||
includeDomains: ['nasa.gov', 'nature.com'], | ||
), | ||
); | ||
void main() async { | ||
final expertAnswer = await expertTool.invoke('Latest Mars rover findings'); | ||
print(expertAnswer); | ||
} | ||
``` | ||
|
||
## Agent Integration Example | ||
|
||
```dart | ||
void main() async { | ||
final aiAgent = ToolsAgent.fromLLMAndTools( | ||
llm: ChatOpenAI(apiKey: openAiKey), | ||
tools: [ | ||
TavilyAnswerTool(apiKey: 'tavily_key'), | ||
CalculatorTool(), | ||
], | ||
); | ||
final executor = AgentExecutor(agent: aiAgent); | ||
final res = await executor.run( | ||
'Calculate the GDP growth rate of France in 2023 using official sources.', | ||
); | ||
print(res); | ||
} | ||
``` | ||
|
||
## Error Handling | ||
|
||
```dart | ||
try { | ||
return await tool.invoke(query); | ||
} on TavilyClientException catch (e) { | ||
print('Error ${e.message}: ${e.code}'); | ||
return 'Failed to retrieve data'; | ||
} | ||
``` |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.