Skip to content

Commit cedde92

Browse files
authored
Data fusion (#46)
* test: Enhance testing capabilities by adding coverage script and updating dependencies * chore: Update .gitignore and vitest configuration to include coverage settings and additional test files * refactor: move example to examples * feat: Implement SentientAI tests and mock services - Added unit tests for SentientAI to validate response handling. - Created mock services for LLM and weather tools to facilitate testing. - Cleaned up import paths in SentientAI.ts for consistency. * refactor: Simplify Agent and Workflow classes, introduce LLMService - Removed direct LLM instantiation from Agent, now using LLMService for LLM management. - Refactored Workflow to utilize LLMService for LLM calls. - Added unit tests for Agent to validate prompt generation and execution with tools. - Introduced LLMService to encapsulate LLM initialization logic. * feat: Enhance LLM functionality and add unit tests - Updated TogetherLLM to require an API key during instantiation, improving error handling. - Removed unnecessary console log from OpenAILLM's generate method. - Added unit tests for DummyLLM, OpenAILLM, and TogetherLLM to validate response generation and error scenarios. * chore: Update vitest configuration to include additional test directories and coverage files * refactor: add types.ts * refactor: Simplify Agent class and enhance SentientAI integration - Refactored the Agent class to implement IAgent and streamline the constructor. - Removed the previous prompt generation logic from the Agent class. - Updated SentientAI to initialize the Agent with a name, description, and a comprehensive set of tools. - Adjusted unit tests for the Agent to reflect the new structure and ensure proper functionality. * refactor: Update Workflow class and add unit tests - Introduced a new prompt generation template for tool selection. - Updated the constructor to accept tools and a prompt function. - Added unit tests for Workflow to validate tool execution and prompt generation with various scenarios. - Improved error handling in the execute method. * fix: Correct import path for callDify in depin_tool.ts * feat: Add docker-compose configuration for application deployment * refactor: Remove Agent class and integrate its functionality into SentientAI * test: Update vitest configuration and add server tests * refactor: Rename Workflow class to QueryOrchestrator and update related functionality * feat: Add templates file and unit tests for templates * refactor: Simplify QueryOrchestrator by moving templates to separate file * refactor: Enhance QueryOrchestrator to improve tool selection and processing logic - Removed unused ActionResult import and streamlined the process method. - Refactored tool selection logic to utilize a new extraction function for tool names from LLM responses. - Updated the selectTools method to return an array of selected tools based on user input. - Added unit tests for process and selectTools methods to validate tool execution and selection scenarios. - Improved error handling for cases with no tools selected. * refactor: Update finalResponseTemplate and toolSelectionTemplate for improved tool handling - Refactored finalResponseTemplate to support multiple tools and outputs, enhancing prompt generation. - Updated toolSelectionTemplate to return a list of selected tool names instead of a JSON object format. - Added a new test case for generating prompts with multiple tools in templates.test.ts. - Improved handling of Twitter accounts for multiple tools in the final response. * refactor: Update mockWeatherTools to use simplified tool selection format * refactor: Update PromptContext to support multiple tools and outputs * refactor: Enhance QueryOrchestrator process method to handle tool selection more effectively - Introduced proceedWithoutTools and proceedWithTools methods to streamline processing. - Updated unit tests to validate new behavior, including a test for processing input without tools. - Removed outdated test case that checked for "No tools selected" message, aligning with new logic. * refactor: Update APITool class to make twitterAccount optional and add unit tests - Modified APITool constructor to accept twitterAccount as an optional parameter, defaulting to an empty string. - Removed apiKey from the constructor, removing security risk where serialization of the class could include api key. - Added a new test suite for APITool to validate initialization, execution, and optional twitterAccount handling. - Ensured proper serialization to JSON without including apiKey. * test: Remove JSON serialization test for APITool * refactor: Update APITool to support generic input type and enhance execution logic - Modified APITool class to accept a generic type parameter for input parsing. - Implemented parseInput method in TestAPITool to handle specific input format. - Updated execute method to utilize parsed input, improving execution output. - Enhanced unit tests to validate new input handling and execution behavior. * refactor: Update APITool constructor to include baseUrl parameter * feat: Add extractContentFromTags utility and corresponding tests * refactor: Migrate weather API tools to new structure and update imports - Replaced references to the old weather API tools with the new Nubila API tools in multiple files. - Deleted the outdated weatherapi.ts file and created a new nubila.ts file to encapsulate the current and forecast weather tools. - Updated tests to mock the new Nubila API tools and ensure compatibility with the refactored structure. - Enhanced the CurrentWeatherAPITool to include improved input parsing and error handling. - Added new types for weather data to support the updated API response structure. * refactor: import extractContentFromTags utility into QueryOrchestrator * refactor: mock classes locally * refactor: Enhance Nubila weather tools with improved input handling and new data types - Updated CurrentWeatherAPITool and ForecastWeatherAPITool to utilize a new Coordinates class for input parsing. - Introduced WeatherForecast type to accommodate the updated API response structure. - Refactored input parsing logic to streamline extraction of latitude and longitude from user queries. - Enhanced error handling for API requests and input validation in both weather tools. - Updated unit tests to cover new functionality and ensure compatibility with the refactored structure. * refactor: Restructure weather API tools to use a base class and improve error messages - Introduced BaseWeatherAPITool class to encapsulate common functionality for CurrentWeatherAPITool and ForecastWeatherAPITool. - Updated error messages to include tool names for better clarity in logs. - Refactored fetchWeatherData and formatWeatherData methods to be protected and abstract where appropriate. - Adjusted unit tests to reflect changes in error message formatting and class structure. * feat: move NewsAPITool and add unit tests for news api * refactor: move dify tool, add unit tests * refactor: update import paths for Tool interface in ioId and tool files * test: add unit tests for LLMService * refactor: clean up LLMService initialization logic * refactor: update SentientAI remove agent from sentientai * test: add TypeScript ignore comments for private method mocking in workflow and weather tests * refactor: enhance tool with tool output information - Updated finalResponseTemplate and toolSelectionTemplate to include an output property for tools. - Refactored APITool constructor to accept an object for better clarity and maintainability. - Introduced new unit tests for templates to ensure correct prompt generation with and without Twitter accounts. - Improved error handling in NewsAPITool and added output descriptions for better context in tool usage. * refactor: overhaul finalResponseTemplate for enhanced user interaction - Updated finalResponseTemplate to provide a structured response format, including detailed analysis and response sections. - Improved clarity by replacing raw data outputs with tagged sections for user input, tools used, and tool outputs. - Enhanced the response generation process with a step-by-step analysis guide to ensure accurate and relevant answers. - Adjusted unit tests to validate the new response structure and ensure proper handling of tool outputs and Twitter accounts. * refactor: enhance DePINTool with LLMService integration and improved input parsing * refactor: integrate LLMService into weather tools for improved input parsing and response handling - Updated execute and parseInput methods to accept LLMService as a parameter for enhanced functionality. - Modified the input parsing logic to derive coordinates more effectively from user queries. - Adjusted unit tests to reflect changes in method signatures and ensure proper LLMService integration. - Changed response format in coordinate extraction to improve clarity and consistency. * feat: add DEPIN_API_KEY environment variable to vitest setup for enhanced testing capabilities * refactor: update QueryOrchestrator to enhance tool output handling and response parsing - Added output property to tools in QueryOrchestrator for better context. - Changed tool selection logic to extract tool names from the updated response format. - Modified proceedWithTools method to include LLMService in tool execution and improved output parsing. - Introduced a TestAPITool for unit testing, ensuring proper integration with the updated workflow. - Updated unit tests to validate new tool handling and response formats. * refactor: integrate LLMService into APITool for enhanced method functionality - Updated execute and parseInput methods in APITool to accept LLMService as a parameter, improving integration with language model services. - Added output property to Tool interface for better context in tool usage. - Adjusted related types and imports to ensure consistency across the codebase. * refactor: update mock data format in tests for improved response clarity * feat: integrate Anthropic SDK into LLM service - Added @anthropic-ai/sdk as a dependency in package.json and pnpm-lock.yaml. - Refactored LLM classes to replace OpenAILLM and TogetherLLM with AnthropicLLM for improved functionality. - Updated LLMService to initialize with AnthropicLLM, ensuring compatibility with new model configurations. - Modified tests to reflect the removal of OpenAILLM and TogetherLLM, focusing on AnthropicLLM integration. * refactor: move tools in one dir * chore: remove unused dependencies and API key checks - Removed Together AI and EmbedJS related dependencies from package.json - Deleted TOGETHER_API_KEY environment variable check in LLMService constructor * refactor: update AnthropicLLM constructor to accept model parameter - Modified AnthropicLLM class to use a more flexible constructor - Added explicit model parameter to improve configuration control - Simplified object assignment in constructor initialization * feat: add OpenAI LLM implementation to support multiple language models - Integrated OpenAI SDK as a dependency in package.json - Created OpenAILLM class implementing the LLM interface - Added support for configurable model, API key, and optional base URL - Improved type safety and error handling in LLM generation method * refactor: optimize Nubila weather tool parameters and coordinate extraction - Simplified weather tool field selection to focus on essential weather data - Extracted coordinate extraction template to a separate module - Improved coordinate parsing with a more concise LLM prompt template * feat: enhance LLMService with flexible provider configuration - Implemented support for multiple LLM providers (Anthropic, OpenAI, Deepseek) - Added configurable fast and main LLM providers with custom model selection - Updated LLMService constructor to accept provider parameters - Expanded test coverage for different LLM provider scenarios - Introduced DummyLLM as a fallback for unknown providers * refactor: update SentientAI and QueryOrchestrator with DePINScan tools and LLM configuration - Replaced DePINTool with DePINScanMetricsTool and DePINScanProjectsTool - Modified QueryOrchestrator to accept LLMService as a constructor parameter - Updated SentientAI to configure LLMService with OpenAI and Anthropic providers - Simplified test mocks for LLMService and weather tools * feat: add performance logging to LLM generation method * feat: add performance timing to Anthropic LLM generation method * feat: add DePINScan metrics and projects tools - Implemented DePINScanMetricsTool to fetch global decentralized physical infrastructure (DePIN) metrics - Created DePINScanProjectsTool to retrieve and analyze DePIN project information - Added supporting template for project data extraction - Included comprehensive test suite for both tools covering API interactions and error handling * refactor: improve final response template readability - Simplified template text by breaking long lines - Removed redundant instructions and comments - Cleaned up example output structure * feat: add L1DataTool for IoTeX blockchain metrics - Implemented L1DataTool to fetch comprehensive IoTeX L1 chain statistics - Added support for retrieving metrics like TVL, contracts, staked tokens, nodes, dapps, and cross-chain transactions - Created comprehensive test suite covering API interactions and error handling - Integrated L1DataTool into SentientAI's tool collection * chore: update Dockerfile and add .dockerignore for improved build process - Optimized Dockerfile to copy project files before running bun install - Added .dockerignore to exclude node_modules and npm-debug.log from Docker context * chore: update .env.template with new LLM and API keys - Added Deepseek and Anthropic API keys - Configured default fast and main LLM models - Included API V2 key for IoTeX L1 data - Maintained template structure for easy configuration * chore: update LLM provider configuration in SentientAI - Switched main LLM provider from Anthropic to Deepseek - Maintained existing configuration structure for LLMService
1 parent 7a1933c commit cedde92

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+2972
-1363
lines changed

.dockerignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules
2+
npm-debug.log

.env.template

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
11
OPENAI_API_KEY=your_openai_api_key
22
NUBILA_API_KEY=your_nubila_api_key
3-
NEWSAPI_API_KEY=your_newsapi_api_key
3+
NEWSAPI_API_KEY=your_newsapi_api_key
4+
5+
DEEPSEEK_API_KEY=your_deepseek_api_key
6+
ANTHROPIC_API_KEY=your_anthropic_api_key
7+
OPENAI_API_KEY=your_openai_api_key
8+
9+
FAST_LLM_MODEL=gpt-4o-mini
10+
LLM_MODEL=deepseek-chat
11+
12+
API_V2_KEY=your_api_v2_key # for iotex l1 data

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,6 @@ yarn-error.log*
3232
build/
3333
out/
3434
bun.lockb
35-
*.db
35+
*.db
36+
37+
/coverage/

Dockerfile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
FROM oven/bun:1.1.26
22
RUN apt update && apt install python3 python3-pip make g++ -y
33
WORKDIR /app
4-
COPY package.json package.json
5-
RUN bun install
64
COPY . .
5+
RUN bun install
76
EXPOSE 3000
87
ENTRYPOINT ["bun","run", "start"]
Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,9 @@ describe("Server", () => {
88
beforeEach(() => {
99
vi.mock("../src/SentientAI", () => ({
1010
SentientAI: vi.fn().mockImplementation(() => ({
11-
agent: new (class {
12-
async execute(_: string): Promise<string> {
13-
return "mocked response";
14-
}
15-
})(),
11+
async execute(_: string): Promise<string> {
12+
return "mocked response";
13+
},
1614
})),
1715
}));
1816
});

docker-compose.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
services:
2+
app:
3+
image: qs:main
4+
ports:
5+
- "8000:8000"
6+
environment:
7+
- PORT=8000
8+
restart: always

src/index.ts renamed to example/index.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
// src/index.ts (Example/test file)
2-
import { DummyLLM, OpenAILLM, LLM } from "./llm";
2+
import { DummyLLM, OpenAILLM, LLM } from "../src/llm";
33
import {
44
CurrentWeatherAPITool,
55
ForecastWeatherAPITool,
6-
} from "./tools/weatherapi";
7-
import { NewsAPITool } from "./tools/newsapi";
8-
import { Agent } from "./agent";
9-
import { Tool } from "./tools/tool";
6+
} from "../src/tools/nubila";
7+
import { NewsAPITool } from "../src/tools/newsapi";
8+
import { Agent } from "../src/agent";
9+
import { Tool } from "../src/tools/tool";
1010
import * as dotenv from "dotenv";
1111

1212
dotenv.config();

package.json

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,26 @@
66
"scripts": {
77
"start": "bun run server.ts",
88
"dev": "bun run --watch server.ts",
9-
"test": "vitest run"
9+
"test": "vitest run",
10+
"coverage": "vitest --coverage"
1011
},
1112
"keywords": [],
1213
"author": "",
1314
"license": "ISC",
1415
"dependencies": {
15-
"@llm-tools/embedjs": "^0.1.28",
16-
"@llm-tools/embedjs-libsql": "^0.1.28",
17-
"@llm-tools/embedjs-loader-web": "^0.1.28",
18-
"@llm-tools/embedjs-openai": "^0.1.28",
16+
"@anthropic-ai/sdk": "^0.36.2",
1917
"axios": "^1.7.9",
2018
"chalk": "^4.1.2",
2119
"dotenv": "^16.4.7",
2220
"ethers": "^6.13.5",
2321
"hono": "^4.6.16",
24-
"together-ai": "^0.11.1",
22+
"openai": "^4.80.1",
2523
"typescript": "^5.7.2"
2624
},
2725
"devDependencies": {
2826
"@types/axios": "^0.14.4",
2927
"@types/node": "^22.10.5",
28+
"@vitest/coverage-v8": "2.1.8",
3029
"prettier": "^3.4.2",
3130
"vitest": "^2.1.8"
3231
}

0 commit comments

Comments
 (0)