Skip to content

Commit

Permalink
feat(tool): elasticsearch improvements
Browse files Browse the repository at this point in the history
Signed-off-by: Tomas Dvorak <[email protected]>
  • Loading branch information
Tomas2D committed Nov 12, 2024
1 parent 2cf5b20 commit f34fe23
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 14 deletions.
6 changes: 4 additions & 2 deletions examples/agents/elasticsearch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { OpenAIChatLLM } from "bee-agent-framework/adapters/openai/chat";
import { ElasticSearchTool } from "bee-agent-framework/tools/database/elasticsearch";
import { FrameworkError } from "bee-agent-framework/errors";
import { UnconstrainedMemory } from "bee-agent-framework/memory/unconstrainedMemory";
import { createConsoleReader } from "../helpers/io.js";

const llm = new OpenAIChatLLM();

Expand All @@ -22,12 +23,13 @@ const agent = new BeeAgent({
tools: [elasticSearchTool],
});

const question = "what is the average ticket price of all flights from Cape Town to Venice";
const reader = createConsoleReader();
const prompt = await reader.prompt();

try {
const response = await agent
.run(
{ prompt: `${question}` },
{ prompt },
{
execution: {
maxRetriesPerStep: 5,
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@
"zod-to-json-schema": "^3.23.3"
},
"peerDependencies": {
"@elastic/elasticsearch": "^8.15.1",
"@elastic/elasticsearch": "^8.0.0",
"@googleapis/customsearch": "^3.2.0",
"@grpc/grpc-js": "^1.11.3",
"@grpc/proto-loader": "^0.7.13",
Expand All @@ -189,7 +189,7 @@
"devDependencies": {
"@commitlint/cli": "^19.5.0",
"@commitlint/config-conventional": "^19.5.0",
"@elastic/elasticsearch": "^8.15.1",
"@elastic/elasticsearch": "^8.0.0",
"@eslint/js": "^9.13.0",
"@eslint/markdown": "^6.2.1",
"@googleapis/customsearch": "^3.2.0",
Expand Down
7 changes: 3 additions & 4 deletions src/tools/database/elasticsearch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import { ValidationError } from "ajv";
import { AnyToolSchemaLike } from "@/internals/helpers/schema.js";
import { parseBrokenJson } from "@/internals/helpers/schema.js";
import { Client, ClientOptions } from "@elastic/elasticsearch";
import {
import type {
CatIndicesResponse,
IndicesGetMappingResponse,
SearchRequest,
Expand All @@ -55,8 +55,7 @@ export const ElasticSearchAction = {

export class ElasticSearchTool extends Tool<
JSONToolOutput<ElasticSearchToolResult>,
ElasticSearchToolOptions,
BaseToolRunOptions
ElasticSearchToolOptions
> {
name = "ElasticSearchTool";

Expand Down Expand Up @@ -144,7 +143,7 @@ export class ElasticSearchTool extends Tool<
await client.info();
return client;
} catch (error) {
throw new ToolError(`Unable to connect to ElasticSearch: ${error}`, [], {
throw new ToolError(`Unable to connect to ElasticSearch.`, [error], {
isRetryable: false,
isFatal: true,
});
Expand Down
1 change: 1 addition & 0 deletions tests/examples/examples.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ const exclude: string[] = [
!hasEnv("COHERE_API_KEY") && ["examples/llms/providers/langchain.ts"],
!hasEnv("CODE_INTERPRETER_URL") && ["examples/tools/custom/python.ts"],
["examples/llms/providers/bam.ts", "examples/llms/providers/bam_verbose.ts"],
!hasEnv("ELASTICSEARCH_NODE") && ["examples/agents/elasticsearch.ts"],
]
.filter(isTruthy)
.flat(); // list of examples that are excluded
Expand Down
12 changes: 6 additions & 6 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -327,13 +327,13 @@ __metadata:
languageName: node
linkType: hard

"@elastic/elasticsearch@npm:^8.15.1":
version: 8.15.1
resolution: "@elastic/elasticsearch@npm:8.15.1"
"@elastic/elasticsearch@npm:^8.0.0":
version: 8.15.2
resolution: "@elastic/elasticsearch@npm:8.15.2"
dependencies:
"@elastic/transport": "npm:^8.8.1"
tslib: "npm:^2.4.0"
checksum: 10c0/6fed56487e0bd5c2e8a54e794cd1ebe58e0ff40319b4b8d10ef3cb45534a572fd4d6d5aff5ca63707aaf4be7abbc073ba5bf414cea129f86facc5b1c576cb815
checksum: 10c0/c37775d17b14c640204c28be5113f8db6361f30b41df05bad997e49a2f3436433d5ca5748ae172cd4c774c7ae182e38790ec735eee2afa607fa1b0449048c2a0
languageName: node
linkType: hard

Expand Down Expand Up @@ -3257,7 +3257,7 @@ __metadata:
"@commitlint/config-conventional": "npm:^19.5.0"
"@connectrpc/connect": "npm:^1.6.1"
"@connectrpc/connect-node": "npm:^1.6.1"
"@elastic/elasticsearch": "npm:^8.15.1"
"@elastic/elasticsearch": "npm:^8.0.0"
"@eslint/js": "npm:^9.13.0"
"@eslint/markdown": "npm:^6.2.1"
"@googleapis/customsearch": "npm:^3.2.0"
Expand Down Expand Up @@ -3347,7 +3347,7 @@ __metadata:
zod: "npm:^3.23.8"
zod-to-json-schema: "npm:^3.23.3"
peerDependencies:
"@elastic/elasticsearch": ^8.15.1
"@elastic/elasticsearch": ^8.0.0
"@googleapis/customsearch": ^3.2.0
"@grpc/grpc-js": ^1.11.3
"@grpc/proto-loader": ^0.7.13
Expand Down

0 comments on commit f34fe23

Please sign in to comment.