Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/bino-dev' into bino
Browse files Browse the repository at this point in the history
  • Loading branch information
nicky-ru committed Jan 10, 2025
2 parents 83169c8 + 74d467c commit 19a23b3
Show file tree
Hide file tree
Showing 12 changed files with 355 additions and 120 deletions.
22 changes: 11 additions & 11 deletions agent/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -331,16 +331,16 @@ function initializeDatabase(dataDir: string) {
max: 15,
});

// Test the connection
db.init()
.then(() => {
elizaLogger.success(
"Successfully connected to PostgreSQL database"
);
})
.catch((error) => {
elizaLogger.error("Failed to connect to PostgreSQL:", error);
});
// // Test the connection
// db.init()
// .then(() => {
// elizaLogger.success(
// "Successfully connected to PostgreSQL database"
// );
// })
// .catch((error) => {
// elizaLogger.error("Failed to connect to PostgreSQL:", error);
// });

return db;
} else {
Expand Down Expand Up @@ -554,7 +554,7 @@ async function startAgent(
db = initializeDatabase(dataDir) as IDatabaseAdapter &
IDatabaseCacheAdapter;

await db.init();
// await db.init();

const cache = initializeCache(
process.env.CACHE_STORE ?? CacheStore.DATABASE,
Expand Down
1 change: 1 addition & 0 deletions packages/plugin-depin/src/actions/depinProjects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export const depinProjects: Action = {
"PROJECT_DETAILS",
],
description: "Analyzes DePINScan projects",
suppressInitialMessage: true,
validate: async (_runtime: IAgentRuntime) => {
return true;
},
Expand Down
22 changes: 16 additions & 6 deletions packages/plugin-depin/src/actions/recentNews.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ import {
HandlerCallback,
} from "@elizaos/core";

import { askQuickSilver } from "../services/quicksilver";
import { adaptQSResponse, askQuickSilver } from "../services/quicksilver";
import { extractNewsQuery } from "../helpers/extractors";

export const recentNews: Action = {
name: "NEWS",
similes: [],
description: "Provide real time news",
suppressInitialMessage: true,
validate: async (_runtime: IAgentRuntime) => {
return true;
},
Expand All @@ -33,17 +35,26 @@ export const recentNews: Action = {
],
],
handler: async (
_runtime: IAgentRuntime,
runtime: IAgentRuntime,
message: Memory,
_state: State,
state: State,
_options: { [key: string]: unknown },
callback?: HandlerCallback
): Promise<boolean> => {
if (!state) {
state = (await runtime.composeState(message)) as State;
} else {
state = await runtime.updateRecentMessageState(state);
}

try {
const news = await askQuickSilver(message.content.text);
const query = await extractNewsQuery(state, runtime);
const news = await askQuickSilver(query);
const adaptedResponse = await adaptQSResponse(state, runtime, news);

if (callback) {
callback({
text: news,
text: adaptedResponse,
inReplyTo: message.id,
});
}
Expand All @@ -61,4 +72,3 @@ export const recentNews: Action = {
}
},
};

Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,15 @@ import {
HandlerCallback,
} from "@elizaos/core";

import { askQuickSilver } from "../services/quicksilver";
import { extractLocationQuestion } from "../services/map"
import { adaptQSResponse, askQuickSilver } from "../services/quicksilver";
import { extractLocationQuestion } from "../helpers/extractors";

export const currentWeather: Action = {
name: "CURRENT_WEATHER",
similes: [
"WEATHER",
"WEATHER_REPORT",
"WEATHER_UPDATE",
],
description: "Get the current weather for a given location",
export const weather: Action = {
name: "GET_WEATHER",
similes: ["WEATHER", "WEATHER_REPORT", "WEATHER_UPDATE"],
description:
"Get the current weather or weather forecast for a given location",
suppressInitialMessage: true,
validate: async (_runtime: IAgentRuntime) => {
return true;
},
Expand All @@ -31,7 +29,7 @@ export const currentWeather: Action = {
{
user: "assistant",
content: {
text: "The current weather in Tokyo is 20°C with clear skies.",
text: "Let me check the weather for you.",
action: "CURRENT_WEATHER",
},
},
Expand All @@ -46,7 +44,7 @@ export const currentWeather: Action = {
{
user: "assistant",
content: {
text: "In New York City, it's currently 15°C (feels like 13°C) with 65% humidity. Wind speed is 12 km/h and conditions are partly cloudy with a UV index of 3.",
text: "Let me check the current weather conditions for you.",
action: "CURRENT_WEATHER",
},
},
Expand All @@ -61,7 +59,7 @@ export const currentWeather: Action = {
{
user: "assistant",
content: {
text: "London is experiencing light rain with a temperature of 12°C (feels like 10°C). The pressure is 1015 hPa with 78% humidity and wind speeds of 15 km/h.",
text: "I'll check the weather in London for you.",
action: "CURRENT_WEATHER",
},
},
Expand All @@ -76,7 +74,7 @@ export const currentWeather: Action = {
{
user: "assistant",
content: {
text: "Dubai is hot at 35°C (feels like 38°C) with clear skies. Humidity is at 45%, UV index is 8, and there's a light breeze at 8 km/h.",
text: "Let me look up the current weather conditions in Dubai.",
action: "CURRENT_WEATHER",
},
},
Expand All @@ -91,7 +89,7 @@ export const currentWeather: Action = {
{
user: "assistant",
content: {
text: "In Moscow, the current temperature is -5°C with a range of -8°C to -3°C today. Light snowfall conditions with 85% humidity and wind speed at 20 km/h.",
text: "I'll check today's temperature range in Moscow for you.",
action: "CURRENT_WEATHER",
},
},
Expand All @@ -106,11 +104,26 @@ export const currentWeather: Action = {
{
user: "assistant",
content: {
text: "Sydney's current temperature is 26°C (feels like 28°C), ranging from 22°C to 29°C. Clear sky conditions with 60% humidity, UV index of 9, and coastal winds at 15 km/h.",
text: "Let me get you a detailed weather report for Sydney.",
action: "CURRENT_WEATHER",
},
},
],
[
{
user: "user",
content: {
text: "What's the weather in Tokyo for the next 3 days?",
},
},
{
user: "assistant",
content: {
text: "I'll check the weather forecast for Tokyo over the next 3 days.",
action: "WEATHER",
},
},
],
],
handler: async (
runtime: IAgentRuntime,
Expand All @@ -126,10 +139,7 @@ export const currentWeather: Action = {
}

try {
const location = await extractLocationQuestion(
state,
runtime
);
const location = await extractLocationQuestion(state, runtime);
if (!location) {
if (callback) {
callback({
Expand All @@ -141,9 +151,15 @@ export const currentWeather: Action = {
}

const weather = await askQuickSilver(location);
const adaptedResponse = await adaptQSResponse(
state,
runtime,
weather
);

if (callback) {
callback({
text: weather,
text: adaptedResponse,
inReplyTo: message.id,
});
}
Expand All @@ -161,4 +177,3 @@ export const currentWeather: Action = {
}
},
};

74 changes: 74 additions & 0 deletions packages/plugin-depin/src/helpers/extractors.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import {
IAgentRuntime,
State,
ModelClass,
composeContext,
generateText,
elizaLogger,
} from "@elizaos/core";

import {
locationExtractionTemplate,
newsExtractionTemplate,
} from "../template";
import { parseTagContent } from "./parsers";

const NUM_RECENT_MESSAGES = 7;

export async function extractLocationQuestion(
state: State,
runtime: IAgentRuntime
): Promise<string> {
const locationExtractionContext = composeContext({
state: {
...state,
recentMessages: getLastMessages(state, NUM_RECENT_MESSAGES),
},
template:
// @ts-ignore
runtime.character.templates?.locationExtractionTemplate ||
locationExtractionTemplate,
});
const location = await generateText({
runtime,
context: locationExtractionContext,
modelClass: ModelClass.SMALL,
});

const parsedLocation = parseTagContent(location, "extracted_location");

elizaLogger.log("Extracted location is: ", parsedLocation);

return parsedLocation;
}

export async function extractNewsQuery(
state: State,
runtime: IAgentRuntime
): Promise<string> {
const newsExtractionContext = composeContext({
state: {
...state,
recentMessages: getLastMessages(state, NUM_RECENT_MESSAGES),
},
template:
// @ts-ignore
runtime.character.templates?.newsExtractionTemplate ||
newsExtractionTemplate,
});
const newsQuery = await generateText({
runtime,
context: newsExtractionContext,
modelClass: ModelClass.SMALL,
});

const parsedNewsQuery = parseTagContent(newsQuery, "extracted_query");

elizaLogger.log("Extracted news query is: ", parsedNewsQuery);

return parsedNewsQuery;
}

function getLastMessages(state: State, numMessages: number): string {
return state.recentMessages.split("\n").slice(-numMessages, -1).join("\n");
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function parseTagContent(text: string, tag: string) {
export function parseTagContent(text: string, tag: string) {
const pattern = new RegExp(`<${tag}>\\s*([\\s\\S]*?)\\s*<\\/${tag}>`);
const match = text?.match(pattern);
if (match && match[1].trim()) {
Expand All @@ -7,6 +7,3 @@ function parseTagContent(text: string, tag: string) {
return null;
}

export function parseLocation(text: string) {
return parseTagContent(text, "extracted_location");
}
4 changes: 2 additions & 2 deletions packages/plugin-depin/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ import type { Plugin } from "@elizaos/core";

import { depinDataProvider } from "./providers/depinData";
import { depinProjects } from "./actions/depinProjects";
import { currentWeather } from "./actions/currentWeather";
import { weather } from "./actions/weather";
import { recentNews } from "./actions/recentNews";
export const depinPlugin: Plugin = {
name: "depin",
description: "DePIN plugin",
providers: [depinDataProvider],
evaluators: [],
services: [],
actions: [depinProjects, currentWeather, recentNews],
actions: [depinProjects, weather, recentNews],
};

export default depinPlugin;
35 changes: 0 additions & 35 deletions packages/plugin-depin/src/services/map.ts

This file was deleted.

Loading

0 comments on commit 19a23b3

Please sign in to comment.