Skip to content

Commit

Permalink
feature add price filtering and turbo build changes. change package d…
Browse files Browse the repository at this point in the history
…ependencies for adapter-postgres
  • Loading branch information
metakai1 committed Jan 11, 2025
1 parent 01904cb commit 7a702e2
Show file tree
Hide file tree
Showing 12 changed files with 2,432 additions and 59 deletions.
211 changes: 211 additions & 0 deletions agent/prompts/query_extraction_promptV3.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,211 @@
You are a real estate agent for virtual properties in a futuristic city metaverse.
Your job is to examine the recent conversation messages and extract key information about the user's property search request.

From the recent messages given below, analyze the most recent relevant message to generate:
1. A natural language search query
2. Any ordering preferences (largest, smallest, cheapest, etc.)
3. Whether the user is specifically looking for properties that are for sale
4. Maximum price limit if specified

Output your analysis as a JSON object with the following fields:
- searchQuery: A single line of text representing the search query
- orderByParameter: One of [largest, smallest, cheapest, mostExpensive, tallest, shortest, closestToOcean, closestToBay, rarity, none]
- salesOnly: true if the user is specifically looking for properties that are for sale/available to buy
- maxPrice: (optional) maximum price in ETH if specified by the user

IMPORTANT: Primarily Use the CURRENT_MESSAGE to generate the search query and ordering preferences.
If further context is needed, use RECENT_MESSAGES to infer the search query. Use message timestamps to determine the most recent messages.
for examples of multi part queries, see the #MULTI-PART QUERIES section below.

CURRENT_MESSAGE:
{{{thisMessage}}}

RECENT_MESSAGES:
{{#each recentMessagesData}}
- {{this.createdAt}}: {{{this.content.text}}}
{{/each}}

#EXAMPLES of valid responses:
For "Show me properties under 5 ETH":
{
"searchQuery": "Show me properties under 5 ETH",
"orderByParameter": "cheapest",
"salesOnly": true,
"maxPrice": 5
}

For "Find Space Mind properties less than 2 ETH":
{
"searchQuery": "Find Space Mind properties less than 2 ETH",
"orderByParameter": "cheapest",
"salesOnly": true,
"maxPrice": 2
}

For "Show me the largest plots in Space Mind":
{
"searchQuery": "Which Space Mind properties are largest?",
"orderByParameter": "largest",
"salesOnly": false
}

For "What's available to buy in Flashing Lights?":
{
"searchQuery": "Which Flashing Lights properties are for sale?",
"orderByParameter": "none",
"salesOnly": true
}

For "Find the cheapest property near the ocean":
{
"searchQuery": "Which properties are close to the ocean?",
"orderByParameter": "cheapest",
"salesOnly": true
}
For "Which Space Mind property is closest to the Ocean?":
{
"searchQuery": "Which Space Mind property is closest to the Ocean?",
"orderByParameter": "closestToOcean",
"salesOnly": false
}
For "Which SM property is closest to the Ocean?":
{
"searchQuery": "Which Space Mind property is closest to the Ocean?",
"orderByParameter": "closestToOcean",
"salesOnly": false
}
For "Which properties in Tranquility Gardens are at least Macro in size?":
{
"searchQuery": "Which properties in Tranquility Gardens are at least Macro in size?",
"orderByParameter": "largest",
"salesOnly": false
}
For "Which buildings in Nexus are industrial are for sale?":
{
"searchQuery": "Which buildings in Nexus are industrial?",
"orderByParameter": "none",
"salesOnly": true
}
For "Which plots in TG/LM are at least Micro in size?":
{
"searchQuery": "Which plots in TG/LM are at least Micro in size?",
"orderByParameter": "largest",
"salesOnly": false
}
For "what rare plots in LM are for sale?":
{
"searchQuery": "what rare plots in LM are for sale?",
"orderByParameter": "rarest",
"salesOnly": true
}

#MULTI-PART QUERIES:
You may have to infer a search query from RECENT_MESSAGES. The user may ask follow up questions to an existing query.
In such cases, you will need to check the RECENT_MESSAGES and parse the time stamp to figure out the information that the user is asking for.

#MULTI-PART QUERIES EXAMPLES:
For "CURRENT_MESSAGE: any under 3 ETH?
RECENT_MESSAGES: show me large plots in Space Mind"
{
"searchQuery": "Show me large plots in Space Mind under 3 ETH",
"orderByParameter": "cheapest",
"salesOnly": true,
"maxPrice": 3
}
For "CURRENT_MESSAGE: which are for sale under 0.7ETH?
RECENT_MESSAGES: what are properties in Space Mind near the ocean?"
{
"searchQuery": "Which Space Mind properties near the ocean are for sale?",
"orderByParameter": "none",
"salesOnly": true
"maxPrice": 0.7
}
For "CURRENT_MESSAGE: show me the small ones
RECENT_MESSAGES: what properties are available in North Star?"
{
"searchQuery": "What small properties are available in North Star?",
"orderByParameter": "smallest",
"salesOnly": false
}
For "CURRENT_MESSAGE: which ones are cheapest?
RECENT_MESSAGES: which ones are near the bay
(next recent timestamp) what's available in Space Mind?"
{
"searchQuery": "What are the cheapest Space Mind properties near the bay?",
"orderByParameter": "cheapest",
"salesOnly": false
}

For "CURRENT_MESSAGE: what are there any under 2 ETH?
RECENT_MESSAGES: show me the large plots
(older timestamp) what's for sale in North Star?"
{
"searchQuery": "What large plots are for sale in North Star under 2 ETH?",
"orderByParameter": "cheapest",
"salesOnly": true
"maxPrice": 2
}
# MULTI-PART QUERIES should reset to the most recent message if the user starts a new search topic.
For "CURRENT_MESSAGE: what are some good buys in Flashing Lights
RECENT_MESSAGES: which ones are close to the bay
(next recent timestamp) what are some large properties in Space Mind"
{
"searchQuery": "what are some good buys in Flashing Lights",
"orderByParameter": "cheapest",
"salesOnly": true
}
For "CURRENT_MESSAGE: what's for sale in Little Meow?
RECENT_MESSAGES: which ones are for sale?
(next recent timestamp) show me large properties in Nexus"
{
"searchQuery": "what's for sale in Little Meow?",
"orderByParameter": "none",
"salesOnly": true
}
For "CURRENT_MESSAGE: show me all properties for sale under 2.5 ETH
RECENT_MESSAGES: show me all properties for sale in space mind"
{
"searchQuery": "show me all properties for sale",
"orderByParameter": "none",
"salesOnly": true
"maxPrice": 2.5
}
#GUIDELINES for Analysis:
If you are unsure of what search query to generate, default to using the CURRENT_MESSAGE to infer the search query.

1. Order Parameter Detection:
- "largest", "biggest" -> largest
- "smallest", "tiniest" -> smallest
- "cheapest", "lowest price" -> cheapest
- "most expensive", "highest price" -> mostExpensive
- "tallest", "highest" -> tallest
- "shortest", "lowest" -> shortest
- "closest to ocean", "nearest to ocean" -> closestToOcean
- "closest to bay", "nearest to bay" -> closestToBay
- "rare", "rarest" -> rarest
- If no ordering mentioned -> none

2. Sales Only Detection (true if):
- User mentions "buy", "purchase", "for sale", "available", "price", "cost", "what's available"
- User asks about "listings" or "market"
- User specifically asks about prices or availability

3. Price Detection:
- Look for numbers followed by "ETH"
- Common patterns: "under X ETH", "less than XETH", "below X ETH", "cheaper than X ETH"
- When price is mentioned, set salesOnly to true and maxPrice to the detected price

#For reference, here are COMMON ABBREVIATIONS, NEIGHBORHOODS, AND ZONING TYPES:
**1. Property Attributes**
- `Nexus`
- `Flashing Lights` (FL)
- `Space Mind` (SM)
- `North Star` (NS)
- `District ZERO` (DZ)
- `Tranquility Gardens` (TG)
- `Little Meow` (LM)
- `Haven Heights` (HH)
- **Zoning Types**: `Legendary, Mixed Use, Industrial, Residential, Commercial`
- **Plot Sizes**: `Nano, Micro, Macro, Mid, Mega, Mammoth, Giga`
- **Building Types**: `Lowrise, Highrise, Tall, Megatall`

11 changes: 10 additions & 1 deletion packages/core/src/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@ import {
type UUID,
} from "./types.ts";

const MAX_MESSAGE_LENGTH = 500; // Maximum length for each message

function truncateMessage(message: string): string {
if (message.length <= MAX_MESSAGE_LENGTH) {
return message;
}
return message.substring(0, MAX_MESSAGE_LENGTH) + "... [truncated]";
}

/**
* Get details for a list of actors.
*/
Expand Down Expand Up @@ -68,7 +77,7 @@ export const formatMessages = ({
.reverse()
.filter((message: Memory) => message.userId)
.map((message: Memory) => {
const messageContent = (message.content as Content).text;
const messageContent = truncateMessage((message.content as Content).text || "");
const messageAction = (message.content as Content).action;
const formattedName =
actors.find((actor: Actor) => actor.id === message.userId)
Expand Down
25 changes: 15 additions & 10 deletions packages/plugin-unreal-dev/package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
{
"name": "@ai16z/plugin-unreal-dev",
"version": "0.1.0",
"private": true,
"main": "dist/index.js",
"private": false,
"type": "module",
"types": "dist/index.d.ts",
"scripts": {
"dev": "pnpm run build:watch",
"build": "tsc",
"build:watch": "concurrently \"pnpm --filter @ai16z/plugin-unreal dev\" \"tsc -w\"",
"build": "tsup --format esm --dts",
"dev": "tsup --format esm --dts --watch",
"test": "jest",
"start": "NODE_OPTIONS='--loader ts-node/esm' ts-node src/index.ts"
},
Expand All @@ -16,16 +17,20 @@
"@ai16z/plugin-unreal": "workspace:*",
"dotenv": "^16.3.1",
"ioredis": "^5.3.2",
"pg": "^8.11.3"
},
"devDependencies": {
"pg": "^8.11.3",
"@types/jest": "^29.5.11",
"@types/node": "^22.10.5",
"@types/pg": "^8.10.9",
"concurrently": "^8.2.2",
"@types/node": "^20.11.5",
"jest": "^29.7.0",
"ts-jest": "^29.1.1",
"ts-node": "^10.9.2",
"typescript": "^5.6.3"
},
"devDependencies": {
"@types/pg": "^8.10.9",
"concurrently": "^8.2.2",
"tsup": "8.3.5"
},
"buildDependencies": {
"@ai16z/adapter-postgres": "workspace:*"
}
}
10 changes: 10 additions & 0 deletions packages/plugin-unreal-dev/tsup.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { defineConfig } from 'tsup';

export default defineConfig({
entry: ['src/index.ts'],
clean: true,
dts: true,
format: ['esm'],
sourcemap: true,
target: 'esnext',
});
14 changes: 0 additions & 14 deletions packages/plugin-unreal/src/code2prompt.config.json

This file was deleted.

6 changes: 3 additions & 3 deletions packages/plugin-unreal/src/database/land_database_adapter.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { IDatabaseAdapter } from "@ai16z/eliza";
import { elizaLogger, UUID } from "@ai16z/eliza";
import PostgresDatabaseAdapter from "@ai16z/adapter-postgres";
import { PostgresDatabaseAdapter } from "@ai16z/adapter-postgres";
import {
LandPlotMemory,
LandSearchParams,
Expand Down Expand Up @@ -152,7 +152,7 @@ export class LandDatabaseAdapter {
}

try {
const { rows } = await (this.dbAdapter as PostgresDatabaseAdapter).query(sql, values);
const { rows } = await (this.dbAdapter as InstanceType<typeof PostgresDatabaseAdapter>).query(sql, values);
return rows.map(row => ({
...row,
content: typeof row.content === 'string' ? JSON.parse(row.content) : row.content
Expand Down Expand Up @@ -309,7 +309,7 @@ export class LandDatabaseAdapter {
sql += ` LIMIT 4444`; // Add a reasonable limit

try {
const { rows } = await (this.dbAdapter as PostgresDatabaseAdapter).query(sql, values);
const { rows } = await (this.dbAdapter as InstanceType<typeof PostgresDatabaseAdapter>).query(sql, values);
return rows.map(row => ({
...row,
content: typeof row.content === 'string' ? JSON.parse(row.content) : row.content
Expand Down
Loading

0 comments on commit 7a702e2

Please sign in to comment.