Skip to content

Commit

Permalink
Data fusion (#46)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
nicky-ru authored Jan 28, 2025
1 parent 7a1933c commit cedde92
Show file tree
Hide file tree
Showing 46 changed files with 2,972 additions and 1,363 deletions.
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
npm-debug.log
11 changes: 10 additions & 1 deletion .env.template
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
OPENAI_API_KEY=your_openai_api_key
NUBILA_API_KEY=your_nubila_api_key
NEWSAPI_API_KEY=your_newsapi_api_key
NEWSAPI_API_KEY=your_newsapi_api_key

DEEPSEEK_API_KEY=your_deepseek_api_key
ANTHROPIC_API_KEY=your_anthropic_api_key
OPENAI_API_KEY=your_openai_api_key

FAST_LLM_MODEL=gpt-4o-mini
LLM_MODEL=deepseek-chat

API_V2_KEY=your_api_v2_key # for iotex l1 data
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,6 @@ yarn-error.log*
build/
out/
bun.lockb
*.db
*.db

/coverage/
3 changes: 1 addition & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
FROM oven/bun:1.1.26
RUN apt update && apt install python3 python3-pip make g++ -y
WORKDIR /app
COPY package.json package.json
RUN bun install
COPY . .
RUN bun install
EXPOSE 3000
ENTRYPOINT ["bun","run", "start"]
8 changes: 3 additions & 5 deletions tests/server.test.ts → __tests__/server.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,9 @@ describe("Server", () => {
beforeEach(() => {
vi.mock("../src/SentientAI", () => ({
SentientAI: vi.fn().mockImplementation(() => ({
agent: new (class {
async execute(_: string): Promise<string> {
return "mocked response";
}
})(),
async execute(_: string): Promise<string> {
return "mocked response";
},
})),
}));
});
Expand Down
8 changes: 8 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
services:
app:
image: qs:main
ports:
- "8000:8000"
environment:
- PORT=8000
restart: always
10 changes: 5 additions & 5 deletions src/index.ts → example/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// src/index.ts (Example/test file)
import { DummyLLM, OpenAILLM, LLM } from "./llm";
import { DummyLLM, OpenAILLM, LLM } from "../src/llm";
import {
CurrentWeatherAPITool,
ForecastWeatherAPITool,
} from "./tools/weatherapi";
import { NewsAPITool } from "./tools/newsapi";
import { Agent } from "./agent";
import { Tool } from "./tools/tool";
} from "../src/tools/nubila";
import { NewsAPITool } from "../src/tools/newsapi";
import { Agent } from "../src/agent";
import { Tool } from "../src/tools/tool";
import * as dotenv from "dotenv";

dotenv.config();
Expand Down
11 changes: 5 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,26 @@
"scripts": {
"start": "bun run server.ts",
"dev": "bun run --watch server.ts",
"test": "vitest run"
"test": "vitest run",
"coverage": "vitest --coverage"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"@llm-tools/embedjs": "^0.1.28",
"@llm-tools/embedjs-libsql": "^0.1.28",
"@llm-tools/embedjs-loader-web": "^0.1.28",
"@llm-tools/embedjs-openai": "^0.1.28",
"@anthropic-ai/sdk": "^0.36.2",
"axios": "^1.7.9",
"chalk": "^4.1.2",
"dotenv": "^16.4.7",
"ethers": "^6.13.5",
"hono": "^4.6.16",
"together-ai": "^0.11.1",
"openai": "^4.80.1",
"typescript": "^5.7.2"
},
"devDependencies": {
"@types/axios": "^0.14.4",
"@types/node": "^22.10.5",
"@vitest/coverage-v8": "2.1.8",
"prettier": "^3.4.2",
"vitest": "^2.1.8"
}
Expand Down
Loading

0 comments on commit cedde92

Please sign in to comment.