Skip to content

Commit

Permalink
Merge branch 'develop' into feature/twitter-messages-image-outbound
Browse files Browse the repository at this point in the history
  • Loading branch information
tcm390 authored Feb 1, 2025
2 parents cc4f5e9 + ce8cb38 commit e91176d
Show file tree
Hide file tree
Showing 17 changed files with 750 additions and 34 deletions.
2 changes: 0 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,6 @@ WORKDIR /app
# Copy built artifacts and production dependencies from the builder stage
COPY --from=builder /app/package.json ./
COPY --from=builder /app/pnpm-workspace.yaml ./
COPY --from=builder /app/eslint.config.mjs ./
COPY --from=builder /app/.eslintrc.json ./
COPY --from=builder /app/.npmrc ./
COPY --from=builder /app/turbo.json ./
COPY --from=builder /app/node_modules ./node_modules
Expand Down
1 change: 0 additions & 1 deletion agent/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ import { holdstationPlugin } from "@elizaos/plugin-holdstation";
import { nvidiaNimPlugin } from "@elizaos/plugin-nvidia-nim";
import { zxPlugin } from "@elizaos/plugin-0x";
import { hyperbolicPlugin } from "@elizaos/plugin-hyperbolic";
import { litPlugin } from "@elizaos/plugin-lit";
import Database from "better-sqlite3";
import fs from "fs";
import net from "net";
Expand Down
125 changes: 125 additions & 0 deletions packages/plugin-bittensor/__tests__/actions/sn34.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
import { describe, expect, it, vi, beforeEach } from 'vitest';
import { analyzeImage, analysisHistory } from '../../src/actions/sn34';
import { elizaLogger } from '@elizaos/core';

vi.mock('@elizaos/core', () => ({
elizaLogger: {
info: vi.fn(),
error: vi.fn(),
debug: vi.fn(),
}
}));

describe('sn34', () => {
let mockRuntime;
let mockMessage;
let mockState;
let mockCallback;

beforeEach(() => {
mockRuntime = {
character: {
settings: {
secrets: {
BITMIND: 'test-api-key'
}
}
}
};

mockMessage = {
content: {
text: 'analyze this image: https://example.com/image.jpg'
}
};

mockState = {};
mockCallback = vi.fn();

// Reset all mocks
vi.clearAllMocks();
});

describe('analyzeImage', () => {
describe('validation', () => {
it('should validate when image URL is present', async () => {
const result = await analyzeImage.validate(mockRuntime, mockMessage);
expect(result).toBe(true);
expect(elizaLogger.info).toHaveBeenCalledWith('🔍 BitMind: Validating analysis request...');
});

it('should fail validation when no image URL is present', async () => {
mockMessage.content.text = 'analyze this image';
const result = await analyzeImage.validate(mockRuntime, mockMessage);
expect(result).toBe(false);
expect(elizaLogger.error).toHaveBeenCalledWith('❌ BitMind: No image URL found in request');
});

it('should fail validation when API credentials are missing', async () => {
mockRuntime.character.settings.secrets.BITMIND = undefined;
const result = await analyzeImage.validate(mockRuntime, mockMessage);
expect(result).toBe(false);
expect(elizaLogger.error).toHaveBeenCalledWith('❌ BitMind: API credentials not configured');
});
});

describe('action properties', () => {
it('should have correct action properties', () => {
expect(analyzeImage.name).toBe('DETECT_IMAGE');
expect(analyzeImage.similes).toEqual([
'ANALYZE_IMAGE',
'VERIFY_IMAGE',
'BITMIND_DETECTION',
'AI_DETECTION',
'REAL_OR_FAKE'
]);
expect(analyzeImage.examples).toBeDefined();
expect(Array.isArray(analyzeImage.examples)).toBe(true);
});

it('should have valid examples', () => {
analyzeImage.examples.forEach(example => {
expect(Array.isArray(example)).toBe(true);
example.forEach(interaction => {
expect(interaction).toHaveProperty('user');
expect(interaction).toHaveProperty('content');
});
});
});
});
});

describe('analysisHistory', () => {
describe('validation', () => {
it('should validate successfully', async () => {
const result = await analysisHistory.validate(mockRuntime);
expect(result).toBe(true);
});
});

describe('action properties', () => {
it('should have correct action properties', () => {
expect(analysisHistory.name).toBe('IMAGE_REPORT');
expect(analysisHistory.similes).toEqual([
'SHOW_DETECTIONS',
'IMAGE_HISTORY',
'PAST_ANALYSES',
'DETECTION_HISTORY'
]);
expect(analysisHistory.description).toBe('Display history of AI image analysis results');
expect(analysisHistory.examples).toBeDefined();
expect(Array.isArray(analysisHistory.examples)).toBe(true);
});

it('should have valid examples', () => {
analysisHistory.examples.forEach(example => {
expect(Array.isArray(example)).toBe(true);
example.forEach(interaction => {
expect(interaction).toHaveProperty('user');
expect(interaction).toHaveProperty('content');
});
});
});
});
});
});
113 changes: 113 additions & 0 deletions packages/plugin-bittensor/__tests__/evaluators/fact.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
import { describe, expect, it, vi, beforeEach } from 'vitest';
import { factEvaluator } from '../../src/evaluators/fact';
import { composeContext, generateObjectArray, MemoryManager } from '@elizaos/core';

vi.mock('@elizaos/core', () => ({
composeContext: vi.fn(),
generateObjectArray: vi.fn(),
MemoryManager: vi.fn().mockImplementation((config: any) => ({
getMemoriesByEvaluator: vi.fn().mockResolvedValue([]),
addMemory: vi.fn().mockResolvedValue(true),
addEmbeddingToMemory: vi.fn().mockResolvedValue({
id: 'test-memory-id',
content: {
text: 'Test memory content'
}
}),
createMemory: vi.fn().mockResolvedValue({
id: 'test-memory-id',
content: {
text: 'Test memory content'
}
})
})),
ModelClass: {
SMALL: 'small'
}
}));

describe('factEvaluator', () => {
let mockRuntime;
let mockMessage;

beforeEach(() => {
mockRuntime = {
character: {
settings: {}
},
messageManager: {
countMemories: vi.fn().mockResolvedValue(5)
},
composeState: vi.fn().mockResolvedValue({
agentId: 'test-agent',
roomId: 'test-room'
}),
getConversationLength: vi.fn().mockReturnValue(10)
};

mockMessage = {
content: {
text: 'I live in New York and work as a software engineer.'
},
roomId: 'test-room'
};

// Reset all mocks
vi.clearAllMocks();
});

describe('validation', () => {
it('should validate successfully', async () => {
const result = await factEvaluator.validate(mockRuntime, mockMessage);
expect(result).toBe(true);
expect(mockRuntime.messageManager.countMemories).toHaveBeenCalledWith('test-room');
expect(mockRuntime.getConversationLength).toHaveBeenCalled();
});
});

describe('evaluator properties', () => {
it('should have correct evaluator properties', () => {
expect(factEvaluator.name).toBe('GET_FACTS');
expect(factEvaluator.similes).toContain('GET_CLAIMS');
expect(factEvaluator.description).toBeDefined();
expect(factEvaluator.description).toContain('Extract factual information');
expect(factEvaluator.examples).toBeDefined();
expect(Array.isArray(factEvaluator.examples)).toBe(true);
});

it('should have valid examples', () => {
factEvaluator.examples.forEach(example => {
expect(example).toBeDefined();
// Will add more specific example validations based on the example structure
});
});
});

describe('fact extraction', () => {
it('should handle fact extraction', async () => {
const mockFacts = [
{
claim: 'User lives in New York',
type: 'fact',
in_bio: false,
already_known: false
},
{
claim: 'User works as a software engineer',
type: 'fact',
in_bio: false,
already_known: false
}
];

vi.mocked(composeContext).mockReturnValue('mock-context');
vi.mocked(generateObjectArray).mockResolvedValue(mockFacts);

const result = await factEvaluator.handler(mockRuntime, mockMessage);

expect(composeContext).toHaveBeenCalled();
expect(generateObjectArray).toHaveBeenCalled();
expect(result).toBeDefined();
});
});
});
1 change: 1 addition & 0 deletions packages/plugin-bittensor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"scripts": {
"build": "tsup --format esm --dts",
"dev": "tsup --format esm --dts --watch",
"test": "vitest run",
"lint": "biome lint .",
"format": "biome format . --write",
"check": "biome check --apply ."
Expand Down
8 changes: 8 additions & 0 deletions packages/plugin-bittensor/vitest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { defineConfig } from 'vitest/config';

export default defineConfig({
test: {
globals: true,
environment: 'node',
},
});
Loading

0 comments on commit e91176d

Please sign in to comment.