Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: change plugin-web-search to use google.serper.dev #2113

Draft
wants to merge 37 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
4fdb74f
SRISE
indowebdeveloper Jan 10, 2025
6e0d433
XX
indowebdeveloper Jan 10, 2025
0243dfb
Merge branch 'elizaOS:main' into SRISE
indowebdeveloper Jan 11, 2025
a3b1fe1
OKE BRO
indowebdeveloper Jan 12, 2025
3de80d6
Add 0G to the blockchain sector
tomguluson92 Jan 12, 2025
88b1d5f
adding news as its new post source
indowebdeveloper Jan 13, 2025
ca682b3
chainCatcher
indowebdeveloper Jan 13, 2025
3029b6c
goplus capability
indowebdeveloper Jan 13, 2025
e557c08
Merge remote-tracking branch 'upstream/main' into SRISE
indowebdeveloper Jan 14, 2025
975a258
chaincacther API
indowebdeveloper Jan 14, 2025
15287ce
dot bug
indowebdeveloper Jan 14, 2025
f1db0cf
some dot bug
indowebdeveloper Jan 14, 2025
ba0cb49
huhuhu
indowebdeveloper Jan 14, 2025
2d3e953
okok
indowebdeveloper Jan 14, 2025
4fdfd2c
fix attempt media is missing
indowebdeveloper Jan 14, 2025
1dac358
goplus check token only
indowebdeveloper Jan 15, 2025
9e05a59
Merge remote-tracking branch 'upstream/develop' into SRISE
indowebdeveloper Jan 15, 2025
6a14224
DEBUG post
indowebdeveloper Jan 15, 2025
feadcc7
supabase schema
indowebdeveloper Jan 15, 2025
077a829
package.json duplicates fix
indowebdeveloper Jan 15, 2025
7189c8a
dirty fix for json tweet
indowebdeveloper Jan 15, 2025
a9dbc63
prompt optimization
indowebdeveloper Jan 15, 2025
d3e4f50
debug
indowebdeveloper Jan 15, 2025
ed99a14
XX debug
indowebdeveloper Jan 15, 2025
72d50f0
put cache and memory to the news
indowebdeveloper Jan 17, 2025
a511465
trimTweetLength additional fix if the text contains ugly json
indowebdeveloper Jan 17, 2025
ff3396f
add embedding to news
indowebdeveloper Jan 17, 2025
0b11101
add embedding
indowebdeveloper Jan 17, 2025
4260319
realtime knowledge using RAG
indowebdeveloper Jan 17, 2025
90948a2
disable birdeye
indowebdeveloper Jan 17, 2025
6c5dd45
replace goplus with neocortex
indowebdeveloper Jan 17, 2025
98195fe
Merge pull request #2204 from tomguluson92/main
tcm390 Jan 19, 2025
658e5d9
Merge remote-tracking branch 'upstream/main' into SRISE
indowebdeveloper Jan 21, 2025
fa28855
heleh
indowebdeveloper Jan 21, 2025
77910be
Merge remote-tracking branch 'upstream/develop' into SRISE
indowebdeveloper Jan 21, 2025
1e14c28
merging
indowebdeveloper Jan 21, 2025
77d51cd
adding knowledge
indowebdeveloper Jan 21, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 16 additions & 15 deletions agent/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { PostgresDatabaseAdapter } from "@elizaos/adapter-postgres";
import { RedisClient } from "@elizaos/adapter-redis";
import { SqliteDatabaseAdapter } from "@elizaos/adapter-sqlite";
import { AutoClientInterface } from "@elizaos/client-auto";
import { DiscordClientInterface } from "@elizaos/client-discord";
Expand All @@ -10,31 +11,32 @@ import { TwitterClientInterface } from "@elizaos/client-twitter";
import {
AgentRuntime,
CacheManager,
CacheStore,
Character,
Client,
Clients,
DbCacheAdapter,
defaultCharacter,
elizaLogger,
FsCacheAdapter,
IAgentRuntime,
ICacheManager,
IDatabaseAdapter,
IDatabaseCacheAdapter,
ModelProviderName,
settings,
stringToUuid,
validateCharacterConfig,
CacheStore,
Client,
ICacheManager,
parseBooleanFromText,
validateCharacterConfig
} from "@elizaos/core";
import { RedisClient } from "@elizaos/adapter-redis";
import { zgPlugin } from "@elizaos/plugin-0g";
import { bootstrapPlugin } from "@elizaos/plugin-bootstrap";
import createGoatPlugin from "@elizaos/plugin-goat";
// import { intifacePlugin } from "@elizaos/plugin-intiface";
import { DirectClient } from "@elizaos/client-direct";
import { ThreeDGenerationPlugin } from "@elizaos/plugin-3d-generation";
import { abstractPlugin } from "@elizaos/plugin-abstract";
import { aptosPlugin } from "@elizaos/plugin-aptos";
import { avalanchePlugin } from "@elizaos/plugin-avalanche";
import {
advancedTradePlugin,
coinbaseCommercePlugin,
Expand All @@ -44,32 +46,31 @@ import {
webhookPlugin,
} from "@elizaos/plugin-coinbase";
import { confluxPlugin } from "@elizaos/plugin-conflux";
import { cronosZkEVMPlugin } from "@elizaos/plugin-cronoszkevm";
import { echoChamberPlugin } from "@elizaos/plugin-echochambers";
import { evmPlugin } from "@elizaos/plugin-evm";
import { storyPlugin } from "@elizaos/plugin-story";
import { flowPlugin } from "@elizaos/plugin-flow";
import { fuelPlugin } from "@elizaos/plugin-fuel";
import { imageGenerationPlugin } from "@elizaos/plugin-image-generation";
import { ThreeDGenerationPlugin } from "@elizaos/plugin-3d-generation";
import { multiversxPlugin } from "@elizaos/plugin-multiversx";
import { nearPlugin } from "@elizaos/plugin-near";
import { nftGenerationPlugin } from "@elizaos/plugin-nft-generation";
import { createNodePlugin } from "@elizaos/plugin-node";
import { solanaPlugin } from "@elizaos/plugin-solana";
import { storyPlugin } from "@elizaos/plugin-story";
import { suiPlugin } from "@elizaos/plugin-sui";
import { TEEMode, teePlugin } from "@elizaos/plugin-tee";
import { tonPlugin } from "@elizaos/plugin-ton";
import { zksyncEraPlugin } from "@elizaos/plugin-zksync-era";
import { cronosZkEVMPlugin } from "@elizaos/plugin-cronoszkevm";
import { abstractPlugin } from "@elizaos/plugin-abstract";
import { avalanchePlugin } from "@elizaos/plugin-avalanche";
import { webSearchPlugin } from "@elizaos/plugin-web-search";
import { echoChamberPlugin } from "@elizaos/plugin-echochambers";
import { zksyncEraPlugin } from "@elizaos/plugin-zksync-era";
import Database from "better-sqlite3";
import fs from "fs";
import net from "net";
import path from "path";
import { fileURLToPath } from "url";
import yargs from "yargs";
import net from "net";

//import {mainCharacter as defaultCharacter} from "../mainCharacter";

const __filename = fileURLToPath(import.meta.url); // get the resolved path to the file
const __dirname = path.dirname(__filename); // get the name of the directory
Expand Down Expand Up @@ -529,7 +530,7 @@ export async function createAgent(
? confluxPlugin
: null,
nodePlugin,
getSecret(character, "TAVILY_API_KEY") ? webSearchPlugin : null,
getSecret(character, "TAVILY_API_KEY") || getSecret(character, "SERPER_API_KEY") ? webSearchPlugin : null,
getSecret(character, "SOLANA_PUBLIC_KEY") ||
(getSecret(character, "WALLET_PUBLIC_KEY") &&
!getSecret(character, "WALLET_PUBLIC_KEY")?.startsWith("0x"))
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@
"turbo": "2.3.3",
"typedoc": "0.26.11",
"typescript": "5.6.3",
"viem": "2.21.58",
"vite": "5.4.11",
"vitest": "2.1.5",
"viem": "2.21.58"
"vitest": "2.1.5"
},
"pnpm": {
"overrides": {
Expand All @@ -59,6 +59,7 @@
"@deepgram/sdk": "^3.9.0",
"@vitest/eslint-plugin": "1.0.1",
"amqplib": "0.10.5",
"axios": "^1.7.9",
"csv-parse": "5.6.0",
"ollama-ai-provider": "0.16.1",
"optional": "0.1.4",
Expand Down
13 changes: 7 additions & 6 deletions packages/client-twitter/src/interactions.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import { SearchMode, Tweet } from "agent-twitter-client";
import {
composeContext,
Content,
elizaLogger,
generateMessageResponse,
generateShouldRespond,
messageCompletionFooter,
shouldRespondFooter,
Content,
getEmbeddingZeroVector,
HandlerCallback,
IAgentRuntime,
Memory,
messageCompletionFooter,
ModelClass,
shouldRespondFooter,
State,
stringToUuid,
elizaLogger,
getEmbeddingZeroVector,
} from "@elizaos/core";
import { SearchMode, Tweet } from "agent-twitter-client";
import { ClientBase } from "./base";
import { buildConversationThread, sendTweet, wait } from "./utils.ts";

Expand Down Expand Up @@ -397,6 +397,7 @@ export class TwitterInteractionClient {

// Promise<"RESPOND" | "IGNORE" | "STOP" | null> {
if (shouldRespond !== "RESPOND") {
console.log("NOTR",shouldRespond);
elizaLogger.log("Not responding to message");
return { text: "Response Decision:", action: shouldRespond };
}
Expand Down
91 changes: 81 additions & 10 deletions packages/core/src/generation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,46 +2,48 @@ import { createAnthropic } from "@ai-sdk/anthropic";
import { createGoogleGenerativeAI } from "@ai-sdk/google";
import { createGroq } from "@ai-sdk/groq";
import { createOpenAI } from "@ai-sdk/openai";
import { RecursiveCharacterTextSplitter } from "langchain/text_splitter";
import { fal } from "@fal-ai/client";
import { AutoTokenizer } from "@huggingface/transformers";
import { tavily } from "@tavily/core";
import {
generateObject as aiGenerateObject,
generateText as aiGenerateText,
StepResult as AIStepResult,
CoreTool,
GenerateObjectResult,
StepResult as AIStepResult,
} from "ai";
import { Buffer } from "buffer";
import https from 'https';
import { encodingForModel, TiktokenModel } from "js-tiktoken";
import { RecursiveCharacterTextSplitter } from "langchain/text_splitter";
import { createOllama } from "ollama-ai-provider";
import OpenAI from "openai";
import { encodingForModel, TiktokenModel } from "js-tiktoken";
import { AutoTokenizer } from "@huggingface/transformers";
import Together from "together-ai";
import { ZodSchema } from "zod";
import { elizaLogger } from "./index.ts";
import { getModel, models } from "./models.ts";
import {
parseActionResponseFromText,
parseBooleanFromText,
parseJsonArrayFromText,
parseJSONObjectFromText,
parseShouldRespondFromText,
parseActionResponseFromText,
} from "./parsing.ts";
import settings from "./settings.ts";
import {
ActionResponse,
Content,
IAgentRuntime,
IImageDescriptionService,
ITextGenerationService,
ModelClass,
ModelProviderName,
ServiceType,
SearchResponse,
ActionResponse,
SerperSearchResponse,
ServiceType,
TelemetrySettings,
TokenizerType,
} from "./types.ts";
import { fal } from "@fal-ai/client";
import { tavily } from "@tavily/core";

type Tool = CoreTool<any, any>;
type StepResult = AIStepResult<any>;
Expand Down Expand Up @@ -1501,12 +1503,81 @@ export const generateWebSearch = async (
includeAnswer: true,
maxResults: 3, // 5 (default)
topic: "general", // "general"(default) "news"
searchDepth: "basic", // "basic"(default) "advanced"
searchDepth: "advanced", // "basic"(default) "advanced"
includeImages: false, // false (default) true
});
console.log(`TVLY RES`,response);
return response;
} catch (error) {
elizaLogger.error("Error:", error);
}
};
export const generateSerperSearch = async (
query: string,
runtime: IAgentRuntime
): Promise<SerperSearchResponse> => {
try {
const apiKey = runtime.getSetting("SERPER_API_KEY") as string;
if (!apiKey) {
throw new Error("SERPER_API_KEY is not set");
}
//const cleanedQuery = query.replace(/@\S+/g, '');
//console.log(`CLEANED QUERY`,cleanedQuery)
const data = JSON.stringify({
q: query
});

const options = {
hostname: 'google.serper.dev',
port: 443,
path: '/search',
method: 'POST',
headers: {
'X-API-KEY': apiKey,
'Content-Type': 'application/json',
'Content-Length': Buffer.byteLength(data),
}
};

const sendRequest = (): Promise<SerperSearchResponse> => {
return new Promise((resolve, reject) => {
const req = https.request(options, (res) => {
let body = '';

res.on('data', (chunk) => {
body += chunk;
});

res.on('end', () => {
if (res.statusCode && res.statusCode >= 200 && res.statusCode < 300) {
try {
const parsedData = JSON.parse(body) as SerperSearchResponse;
resolve(parsedData);
} catch (err) {
reject(new Error(`Failed to parse response: ${err}`));
}
} else {
reject(new Error(`Request failed with status code: ${res.statusCode}`));
}
});
});

req.on('error', (err) => {
reject(err);
});

// Write data to the request body
req.write(data);
req.end();
});
};

const response = await sendRequest();
console.log(`TVLY RES`, response);
return response;
} catch (error) {
elizaLogger.error("Error:", error);
throw error; // Re-throw the error for the caller to handle.
}
};
/**
Expand Down
50 changes: 50 additions & 0 deletions packages/core/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1282,6 +1282,56 @@ export type SearchResponse = {
results: SearchResult[];
};

export type SerperSearchParameters = {
q: string;
type: string;
engine: string;
};

export type SerperAnswerBox = {
snippet: string;
snippetHighlighted: string[];
title: string;
link: string;
};

export type SerperSiteLink = {
title: string;
link: string;
};

export type SerperOrganicResult = {
title: string;
link: string;
snippet: string;
sitelinks?: SerperSiteLink[];
position: number;
attributes?: Record<string, string>;
rating?: number;
ratingCount?: number;
};

export type SerperPeopleAlsoAsk = {
question: string;
snippet: string;
title: string;
link: string;
};

export type SerperRelatedSearch = {
query: string;
};

export type SerperSearchResponse = {
searchParameters: SerperSearchParameters;
answerBox?: SerperAnswerBox;
organic: SerperOrganicResult[];
peopleAlsoAsk: SerperPeopleAlsoAsk[];
relatedSearches: SerperRelatedSearch[];
credits: number;
};


export enum ServiceType {
IMAGE_DESCRIPTION = "image_description",
TRANSCRIPTION = "transcription",
Expand Down
2 changes: 2 additions & 0 deletions packages/plugin-coinbase/src/plugins/trades.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Network,From Amount,Source Asset,To Amount,Target Asset,Status,Transaction URL

1 change: 1 addition & 0 deletions packages/plugin-web-search/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
],
"dependencies": {
"@elizaos/core": "workspace:*",
"axios": "^1.7.9",
"tsup": "8.3.5"
},
"scripts": {
Expand Down
Loading
Loading