Skip to content

Commit 89b685b

Browse files
clean up
1 parent 3c8c3bf commit 89b685b

File tree

8 files changed

+63
-94
lines changed

8 files changed

+63
-94
lines changed

agent/src/index.ts

-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import { SlackClientInterface } from "@elizaos/client-slack";
1111
import { TelegramClientInterface } from "@elizaos/client-telegram";
1212
import { TwitterClientInterface } from "@elizaos/client-twitter";
1313
// import { ReclaimAdapter } from "@elizaos/plugin-reclaim";
14-
import { DirectClient } from "@elizaos/client-direct";
1514
import { PrimusAdapter } from "@elizaos/plugin-primus";
1615

1716
import {
@@ -102,7 +101,6 @@ import net from "net";
102101
import path from "path";
103102
import { fileURLToPath } from "url";
104103
import yargs from "yargs";
105-
import {dominosPlugin} from "@elizaos/plugin-dominos";
106104

107105
const __filename = fileURLToPath(import.meta.url); // get the resolved path to the file
108106
const __dirname = path.dirname(__filename); // get the name of the directory

packages/core/src/generation.ts

-28
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,13 @@ import {
4141
ModelClass,
4242
ModelProviderName,
4343
ServiceType,
44-
SearchResponse,
4544
ActionResponse,
4645
IVerifiableInferenceAdapter,
4746
VerifiableInferenceOptions,
4847
VerifiableInferenceResult,
4948
//VerifiableInferenceProvider,
5049
TelemetrySettings,
5150
TokenizerType,
52-
IWebSearchService,
53-
SearchOptions,
5451
} from "./types.ts";
5552
import { fal } from "@fal-ai/client";
5653

@@ -1725,31 +1722,6 @@ export const generateCaption = async (
17251722
};
17261723
};
17271724

1728-
export const generateWebSearch = async (
1729-
data: {
1730-
query: string
1731-
options?: SearchOptions
1732-
},
1733-
runtime: IAgentRuntime
1734-
): Promise<SearchResponse> => {
1735-
try {
1736-
const { query, options } = data;
1737-
const webSearchService =
1738-
runtime.getService<IWebSearchService>(
1739-
ServiceType.WEB_SEARCH
1740-
);
1741-
1742-
if (!webSearchService) {
1743-
throw new Error("Web search service not found");
1744-
}
1745-
1746-
const response = await webSearchService.search(query, runtime, options);
1747-
return response;
1748-
1749-
} catch (error) {
1750-
elizaLogger.error("Error:", error);
1751-
}
1752-
};
17531725
/**
17541726
* Configuration options for generating objects with a model.
17551727
*/

packages/core/src/types.ts

-40
Original file line numberDiff line numberDiff line change
@@ -1328,23 +1328,6 @@ export interface IPdfService extends Service {
13281328
convertPdfToText(pdfBuffer: Buffer): Promise<string>;
13291329
}
13301330

1331-
export interface IWebSearchService extends Service {
1332-
search(
1333-
query: string,
1334-
runtime: IAgentRuntime,
1335-
options?: SearchOptions,
1336-
): Promise<SearchResponse>;
1337-
}
1338-
1339-
export interface SearchOptions {
1340-
limit?: number;
1341-
type?: "news" | "general";
1342-
includeAnswer?: boolean;
1343-
searchDepth?: "basic" | "advanced";
1344-
includeImages?: boolean;
1345-
days?: number; // 1 means current day, 2 means last 2 days
1346-
}
1347-
13481331
export interface IAwsS3Service extends Service {
13491332
uploadFile(
13501333
imagePath: string,
@@ -1411,28 +1394,6 @@ export interface ITeeLogService extends Service {
14111394
): Promise<boolean>;
14121395
}
14131396

1414-
export type SearchImage = {
1415-
url: string;
1416-
description?: string;
1417-
};
1418-
1419-
export type SearchResult = {
1420-
title: string;
1421-
url: string;
1422-
content: string;
1423-
rawContent?: string;
1424-
score: number;
1425-
publishedDate?: string;
1426-
};
1427-
1428-
export type SearchResponse = {
1429-
answer?: string;
1430-
query: string;
1431-
responseTime: number;
1432-
images: SearchImage[];
1433-
results: SearchResult[];
1434-
};
1435-
14361397
export enum ServiceType {
14371398
IMAGE_DESCRIPTION = "image_description",
14381399
TRANSCRIPTION = "transcription",
@@ -1448,7 +1409,6 @@ export enum ServiceType {
14481409
IRYS = "irys",
14491410
TEE_LOG = "tee_log",
14501411
GOPLUS_SECURITY = "goplus_security",
1451-
WEB_SEARCH = "web_search",
14521412
}
14531413

14541414
export enum LoggingLevel {

packages/plugin-node/src/services/index.ts

-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import { PdfService } from "./pdf.ts";
66
import { SpeechService } from "./speech.ts";
77
import { TranscriptionService } from "./transcription.ts";
88
import { VideoService } from "./video.ts";
9-
import { WebSearchService } from "./webSearch.ts";
109

1110
export {
1211
AwsS3Service,
@@ -17,5 +16,4 @@ export {
1716
SpeechService,
1817
TranscriptionService,
1918
VideoService,
20-
WebSearchService
2119
};

packages/plugin-web-search/src/actions.ts packages/plugin-web-search/src/actions/webSearch.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
import { elizaLogger } from "@elizaos/core";
21
import {
32
Action,
43
HandlerCallback,
54
IAgentRuntime,
65
Memory,
76
State,
7+
elizaLogger
88
} from "@elizaos/core";
9-
import { generateWebSearch } from "@elizaos/core";
10-
import { SearchResult } from "@elizaos/core";
119
import { encodingForModel, TiktokenModel } from "js-tiktoken";
10+
import { WebSearchService } from "../services/webSearchService";
11+
import { SearchResult } from "../types";
1212

1313
const DEFAULT_MAX_WEB_SEARCH_TOKENS = 4000;
1414
const DEFAULT_MODEL_ENCODING = "gpt-3.5-turbo";
@@ -67,10 +67,10 @@ export const webSearch: Action = {
6767
const webSearchPrompt = message.content.text;
6868
elizaLogger.log("web search prompt received:", webSearchPrompt);
6969

70-
elizaLogger.log("Generating image with prompt:", webSearchPrompt);
71-
const searchResponse = await generateWebSearch(
70+
const webSearchService = new WebSearchService();
71+
await webSearchService.initialize(runtime);
72+
const searchResponse = await webSearchService.search(
7273
webSearchPrompt,
73-
runtime
7474
);
7575

7676
if (searchResponse && searchResponse.results.length) {
+5-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
1-
import { webSearch } from "./actions";
1+
import { webSearch } from "./actions/webSearch";
22
import { Plugin } from "@elizaos/core";
3+
import { WebSearchService } from "./services/webSearchService";
34

45
export const webSearchPlugin: Plugin = {
56
name: "webSearch",
6-
description: "Search web",
7+
description: "Search the web and get news",
78
actions: [webSearch],
89
evaluators: [],
910
providers: [],
11+
services: [new WebSearchService()],
12+
clients: [],
1013
};
1114

1215
export default webSearchPlugin;

packages/plugin-node/src/services/webSearch.ts packages/plugin-web-search/src/services/webSearchService.ts

+12-14
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,33 @@
11
import {
22
Service,
3-
IWebSearchService,
4-
ServiceType,
53
IAgentRuntime,
6-
SearchResponse,
7-
SearchOptions,
84
} from "@elizaos/core";
95
import { tavily } from "@tavily/core";
6+
import { IWebSearchService, SearchOptions, SearchResponse } from "../types";
7+
8+
export type TavilyClient = ReturnType<typeof tavily>; // declaring manually because orginal package does not export its types
109

1110
export class WebSearchService extends Service implements IWebSearchService {
12-
static serviceType: ServiceType = ServiceType.WEB_SEARCH;
11+
public tavilyClient: TavilyClient
1312

14-
async initialize(_runtime: IAgentRuntime): Promise<void> {}
13+
async initialize(_runtime: IAgentRuntime): Promise<void> {
14+
const apiKey = _runtime.getSetting("TAVILY_API_KEY") as string;
15+
if (!apiKey) {
16+
throw new Error("TAVILY_API_KEY is not set");
17+
}
18+
this.tavilyClient = tavily({ apiKey });
19+
}
1520

1621
getInstance(): IWebSearchService {
1722
return WebSearchService.getInstance();
1823
}
1924

2025
async search(
2126
query: string,
22-
runtime: IAgentRuntime,
2327
options?: SearchOptions,
2428
): Promise<SearchResponse> {
2529
try {
26-
const apiKey = runtime.getSetting("TAVILY_API_KEY") as string;
27-
if (!apiKey) {
28-
throw new Error("TAVILY_API_KEY is not set");
29-
}
30-
31-
const tvly = tavily({ apiKey });
32-
const response = await tvly.search(query, {
30+
const response = await this.tavilyClient.search(query, {
3331
includeAnswer: options?.includeAnswer || true,
3432
maxResults: options?.limit || 3,
3533
topic: options?.type || "general",
+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import { Service } from "@elizaos/core";
2+
3+
export interface IWebSearchService extends Service {
4+
search(
5+
query: string,
6+
options?: SearchOptions,
7+
): Promise<SearchResponse>;
8+
}
9+
10+
export type SearchResult = {
11+
title: string;
12+
url: string;
13+
content: string;
14+
rawContent?: string;
15+
score: number;
16+
publishedDate?: string;
17+
};
18+
19+
export type SearchImage = {
20+
url: string;
21+
description?: string;
22+
};
23+
24+
25+
export type SearchResponse = {
26+
answer?: string;
27+
query: string;
28+
responseTime: number;
29+
images: SearchImage[];
30+
results: SearchResult[];
31+
};
32+
33+
export interface SearchOptions {
34+
limit?: number;
35+
type?: "news" | "general";
36+
includeAnswer?: boolean;
37+
searchDepth?: "basic" | "advanced";
38+
includeImages?: boolean;
39+
days?: number; // 1 means current day, 2 means last 2 days
40+
}

0 commit comments

Comments
 (0)