@nomyx/assistant v2.5.0
@nomyx/assistant
A powerful and flexible AI assistant framework for your projects. This package provides both a library for programmatic use and a command-line interface, supporting multiple AI providers including OpenAI, Anthropic, Azure, Vertex AI, and OpenRouter.
Features
- Supports multiple AI providers (OpenAI, Anthropic, Azure, Vertex AI, OpenRouter)
- Can be used as a library in your JavaScript/TypeScript projects
- Provides a command-line interface for quick interactions
- Includes a semantic cache for improved performance
- Supports structured prompts and prompt registries
- Includes tools for code analysis and generation
- Provides context management and persistent state
Installation
npm install @nomyx/assistantUsage as a Library
Basic Usage
import { AIAssistant } from '@nomyx/assistant';
const assistant = new AIAssistant();
await assistant.initialize();
const response = await assistant.processRequest("What is the capital of France?");
console.log(response);Advanced Usage
import { AIAssistant, StructuredPrompt, PromptRegistry } from '@nomyx/assistant';
// Create a custom prompt
const customPrompt = new StructuredPrompt({
name: 'custom_greeting',
content: 'Hello, {{name}}! Welcome to {{place}}.',
parameters: {
name: { type: 'string', description: 'The name of the person to greet' },
place: { type: 'string', description: 'The place to welcome the person to' }
}
});
// Register the prompt
const promptRegistry = new PromptRegistry();
promptRegistry.registerPrompt(customPrompt);
// Create an assistant with custom options
const assistant = new AIAssistant({
promptRegistry,
maxRetries: 3,
timeoutMs: 30000,
providerName: 'openai'
});
await assistant.initialize();
// Use the custom prompt
const response = await assistant.processRequest('custom_greeting', { name: 'Alice', place: 'Wonderland' });
console.log(response);Usage as a Command-line Tool
After installation, you can use the ai command in your terminal:
Single Query Mode
ai "What is the capital of France?"Interactive Mode
aiThis will start an interactive session where you can type multiple queries.
Testing Providers
To test different AI providers:
ai --testConfiguration
The assistant can be configured to use different AI providers. Set the following environment variables to configure the provider:
AI_PROVIDER: The name of the AI provider to use (e.g., 'openai', 'anthropic', 'azure', 'vertex', 'openrouter')
Provider-specific Environment Variables
OpenAI
OPENAI_API_KEY: Your OpenAI API keyOPENAI_API_MODEL: The model to use (default: 'gpt-4')
Anthropic
ANTHROPIC_API_KEY: Your Anthropic API keyANTHROPIC_MODEL: The model to use
Azure
AZURE_SUBSCRIPTION_ID: Your Azure subscription IDAZURE_OPENAI_API_KEY: Your Azure OpenAI API keyAZURE_OPENAI_ENDPOINT: Your Azure OpenAI endpointAZURE_OPENAI_DEPLOYMENT_NAME: Your Azure OpenAI deployment name
Vertex AI
GOOGLE_PROJECT_ID: Your Google Cloud project IDGOOGLE_GEMINI_LOCATION: The location of your Gemini modelGOOGLE_GEMINI_MODEL: The Gemini model to useGOOGLE_APPLICATION_CREDENTIALS: Path to your Google Cloud credentials file
OpenRouter
OPENROUTER_API_KEY: Your OpenRouter API keyOPENROUTER_MODEL: The model to useOPENROUTER_HTTP_REFERER: The HTTP referer to use with OpenRouterOPENROUTER_X_TITLE: The X-Title to use with OpenRouter
Available Scripts
npm run build: Clean the dist directory and compile TypeScript filesnpm run clean: Remove the dist directorynpm test: Run testsnpm run test:watch: Run tests in watch modenpm run test:providers: Test different AI providers
API Reference
AIAssistant
The main class for interacting with the AI assistant.
Methods
initialize(): Initialize the assistantprocessRequest(query: string, options?: ProcessRequestOptions): Promise<string>: Process a request and return the AI's responsesetContext(context: any): Set the context for future requestsclearContext(): Clear the current context
StructuredPrompt
A class for creating structured prompts with parameters.
Constructor
new StructuredPrompt({
name: string,
content: string,
parameters: Record<string, ParameterDefinition>
})PromptRegistry
A class for registering and managing prompts.
Methods
registerPrompt(prompt: StructuredPrompt): Register a new promptgetPrompt(name: string): StructuredPrompt | undefined: Get a registered prompt by name
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
License
This project is licensed under the ISC License.
Support
If you encounter any problems or have any questions, please open an issue on the GitHub repository.
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago