Skip to content

Commit

Permalink
Merge pull request #34 from daydreamsai/chains
Browse files Browse the repository at this point in the history
feat: add evm, sol, strk
  • Loading branch information
ponderingdemocritus authored Jan 23, 2025
2 parents 143ce6b + 254a395 commit 9e386a0
Show file tree
Hide file tree
Showing 18 changed files with 1,207 additions and 573 deletions.
21 changes: 11 additions & 10 deletions examples/example-basic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@
*/

import { LLMClient } from "../packages/core/src/core/llm-client";
import {
executeStarknetTransaction,
fetchGraphQL,
} from "../packages/core/src/core/providers";
import { fetchGraphQL } from "../packages/core/src/core/providers";
import { StarknetChain } from "../packages/core/src/core/chains/starknet";

import { ChainOfThought } from "../packages/core/src/core/chain-of-thought";
import { ETERNUM_CONTEXT, PROVIDER_GUIDE } from "./eternum-context";
Expand All @@ -20,6 +18,7 @@ import chalk from "chalk";

import { ChromaVectorDB } from "../packages/core/src/core/vector-db";
import { z } from "zod";
import { env } from "../packages/core/src/core/env";

/**
* Helper function to get user input from CLI
Expand Down Expand Up @@ -47,6 +46,12 @@ async function main() {
const memory = new ChromaVectorDB("agent_memory");
await memory.purge(); // Clear previous session data

const starknetChain = new StarknetChain({
rpcUrl: env.STARKNET_RPC_URL,
address: env.STARKNET_ADDRESS,
privateKey: env.STARKNET_PRIVATE_KEY,
});

// Load initial context documents
await memory.storeDocument({
title: "Game Rules",
Expand All @@ -73,12 +78,8 @@ async function main() {
dreams.registerOutput({
name: "EXECUTE_TRANSACTION",
handler: async (data: any) => {
const result = await executeStarknetTransaction(data.payload);
return `Transaction executed successfully: ${JSON.stringify(
result,
null,
2
)}`;
const result = await starknetChain.write(data.payload);
return `Transaction: ${JSON.stringify(result, null, 2)}`;
},
schema: z
.object({
Expand Down
16 changes: 10 additions & 6 deletions examples/example-goal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,10 @@ import chalk from "chalk";

import { ChromaVectorDB } from "../packages/core/src/core/vector-db";
import { GoalStatus, LogLevel } from "../packages/core/src/types";
import {
executeStarknetTransaction,
fetchGraphQL,
} from "../packages/core/src/core/providers";

import { fetchGraphQL } from "../packages/core/src/core/providers";
import { StarknetChain } from "../packages/core/src/core/chains/starknet";
import { z } from "zod";
import { env } from "../packages/core/src/core/env";

/**
* Helper function to get user input from CLI
Expand Down Expand Up @@ -60,6 +58,12 @@ async function main() {
model: "deepseek/deepseek-r1", // High performance model
});

const starknetChain = new StarknetChain({
rpcUrl: env.STARKNET_RPC_URL,
address: env.STARKNET_ADDRESS,
privateKey: env.STARKNET_PRIVATE_KEY,
});

const memory = new ChromaVectorDB("agent_memory");
await memory.purge(); // Clear previous session data

Expand Down Expand Up @@ -96,7 +100,7 @@ async function main() {
dreams.registerOutput({
name: "EXECUTE_TRANSACTION",
handler: async (data: any) => {
const result = await executeStarknetTransaction(data.payload);
const result = await starknetChain.write(data.payload);
return `Transaction executed successfully: ${JSON.stringify(
result,
null,
Expand Down
65 changes: 39 additions & 26 deletions examples/example-twitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { Consciousness } from "../packages/core/src/core/consciousness";
import { z } from "zod";

async function main() {
const loglevel = LogLevel.DEBUG;
const loglevel = LogLevel.INFO;
// Initialize core dependencies
const vectorDb = new ChromaVectorDB("twitter_agent", {
chromaUrl: "http://localhost:8000",
Expand All @@ -33,9 +33,8 @@ async function main() {
const roomManager = new RoomManager(vectorDb);

const llmClient = new LLMClient({
model: "openai/gpt-4-turbo-preview", // Using OpenAI's GPT-4 Turbo
temperature: 0.7, // Slightly more creative
maxTokens: 4096, // Increased context window
model: "anthropic/claude-3-5-sonnet-latest", // Using a known supported model
temperature: 0.3,
});

// Initialize processor with default character personality
Expand Down Expand Up @@ -71,8 +70,9 @@ async function main() {
});

// Register input handler for Twitter mentions
core.subscribeToInputSource({
core.registerIOHandler({
name: "twitter_mentions",
role: "input",
handler: async () => {
console.log(chalk.blue("🔍 Checking Twitter mentions..."));
// Create a static mentions input handler
Expand All @@ -86,7 +86,7 @@ async function main() {

return mentions;
},
response: z.object({
schema: z.object({
type: z.string(),
content: z.string(),
metadata: z.record(z.any()),
Expand All @@ -95,8 +95,9 @@ async function main() {
});

// Register input handler for autonomous thoughts
core.subscribeToInputSource({
core.registerIOHandler({
name: "consciousness_thoughts",
role: "input",
handler: async () => {
console.log(chalk.blue("🧠 Generating thoughts..."));
const thought = await consciousness.start();
Expand All @@ -108,7 +109,7 @@ async function main() {

return thought;
},
response: z.object({
schema: z.object({
type: z.string(),
content: z.string(),
metadata: z.record(z.any()),
Expand All @@ -117,35 +118,47 @@ async function main() {
});

// Register output handler for posting thoughts to Twitter
core.registerOutput({
core.registerIOHandler({
name: "twitter_thought",
role: "output",
handler: async (data: unknown) => {
const thoughtData = data as { content: string };

return twitter.createTweetOutput().handler({
content: thoughtData.content,
});
},
schema: z.object({
content: z
.string()
.regex(/^[\x20-\x7E]*$/, "No emojis or non-ASCII characters allowed"),
}),
schema: z
.object({
content: z
.string()
.regex(/^[\x20-\x7E]*$/, "No emojis or non-ASCII characters allowed"),
})
.describe(
"This is the content of the tweet you are posting. It should be a string of text that is 280 characters or less. Use this to post a tweet on the timeline."
),
});

// Register output handler for Twitter replies
core.registerOutput({
core.registerIOHandler({
name: "twitter_reply",
role: "output",
handler: async (data: unknown) => {
const tweetData = data as { content: string; inReplyTo: string };

return twitter.createTweetOutput().handler(tweetData);
},
schema: z.object({
content: z.string(),
inReplyTo: z
.string()
.optional()
.describe("The tweet ID to reply to, if any"),
}),
schema: z
.object({
content: z.string(),
inReplyTo: z
.string()
.optional()
.describe("The tweet ID to reply to, if any"),
})
.describe(
"If you have been tagged or mentioned in the tweet, use this. This is for replying to tweets."
),
});

// Start monitoring
Expand All @@ -158,10 +171,10 @@ async function main() {

// Clean up resources
await consciousness.stop();
core.unsubscribeFromInputSource("twitter_mentions");
core.unsubscribeFromInputSource("consciousness_thoughts");
core.removeOutputHandler("twitter_reply");
core.removeOutputHandler("twitter_thought");
core.removeIOHandler("twitter_mentions");
core.removeIOHandler("consciousness_thoughts");
core.removeIOHandler("twitter_reply");
core.removeIOHandler("twitter_thought");

console.log(chalk.green("✅ Shutdown complete"));
process.exit(0);
Expand Down
3 changes: 3 additions & 0 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,14 @@
"@ai-sdk/togetherai": "^0.1.1",
"@ai-sdk/xai": "^1.1.1",
"@openrouter/ai-sdk-provider": "^0.0.6",
"@solana/web3.js": "^1.98.0",
"agent-twitter-client": "^0.0.16",
"ai": "^4.1.0",
"ajv": "^8.17.1",
"bs58": "^6.0.0",
"chromadb": "^1.9.4",
"chromadb-default-embed": "^2.13.2",
"ethers": "^6.13.5",
"openai": "^4.76.0",
"starknet": "^6.11.0",
"tsup": "^8.3.5",
Expand Down
Loading

0 comments on commit 9e386a0

Please sign in to comment.