kbot refs

This commit is contained in:
Code 2025-02-11 21:41:05 +01:00
parent 080e42fc44
commit 4f82740202
3 changed files with 96 additions and 257 deletions

View File

@ -109,27 +109,27 @@ When creating content
- always add links - always add links
- when sending emails, always add 'Best regards, [Your Name]' - when sending emails, always add 'Best regards, [Your Name]'
``` ```
## Commands ## Commands
### Prompt ### Prompt
```kbot "create Astro minimal boilerplate, use starlight theme. Install dependencies via NPM tool"``` ```kbot "create Astro minimal boilerplate, use starlight theme. Install dependencies via NPM tool"```
### Fetch latest models ### Fetch latest models
```kbot fetch``` ```kbot fetch```
### Print examples ### Print examples
```kbot examples``` ```kbot examples```
### Print extended help ### Print extended help
```kbot help-md``` ```kbot help-md```
### Initialize folder ### Initialize folder
```kbot init``` ```kbot init```
# Command Line Parameters # Command Line Parameters
@ -206,4 +206,19 @@ osr-cli each --main='kbot \"read ${KEY} and translate to german, save in docs/la
```bash ```bash
npm i -g @plastichub/osr-cli-commons npm i -g @plastichub/osr-cli-commons
``` ```
### References
#### Huggingface
- https://huggingface.co/spaces/enzostvs/hub-api-playground
- https://www.npmjs.com/package/@gradio/client
- https://github.com/huggingface/text-generation-inference/blob/main/docs/openapi.json
- Img to 3D : https://huggingface.co/spaces/JeffreyXiang/TRELLIS
#### Providers
- https://www.llamaindex.ai/llamaparse (doc parsers)

View File

@ -1,209 +0,0 @@
# @plastichub/kbot
AI-powered command-line tool for code modifications and project management that supports multiple AI models and routers.
## Overview
Code-bot is a powerful CLI tool that helps developers automate code modifications, handle project management tasks, and integrate with various AI models for intelligent code and content assistance.
## Quick Start
### Installation Steps
KBot requires Node.js to run. It's recommended to use Node.js version 18 or higher.
1. Visit the official [Node.js website](https://nodejs.org/)
2. Download the LTS (Long Term Support) version for your operating system
3. Follow the installation wizard
4. Verify installation by opening a terminal and running:
```bash
node --version
npm --version
```
### API Keys
KBot supports both OpenRouter and OpenAI APIs. You'll need at least one of these set up.
#### OpenRouter API (Recommended)
1. Visit [OpenRouter](https://openrouter.ai/)
2. Sign up for an account
3. Navigate to the API Keys section
4. Create a new API key
#### OpenAI API (Optional)
1. Go to [OpenAI's platform](https://platform.openai.com/)
2. Create an account or sign in
3. Navigate to API keys section
4. Create a new secret key
### Installation using Node NPM package manager
```bash
npm install -g @plastichub/kbot
```
## Configuration
### API Keys Setup
Create configuration at `$HOME/.osr/.config.json` (or export OSR_CONFIG with path to config.json):
```json
{
"openrouter": {
"key": "your-openrouter-key"
},
"openai": {
"key": "your-openai-key"
},
"email": {
"newsletter": {
"host": "host.org",
"port": 465,
"debug": true,
"transactionLog": true,
"auth": {
"user": "foo@bar.com",
"pass": "pass"
}
}
},
"google": {
"cse": "custom search engine id",
"api_key": "google custom search api key"
},
"serpapi": {
"key": "your SerpAPI key (optional, used for web searches(places, google maps))"
},
"deepseek": {
"key": "your SerpAPI key (optional, used for web searches(places, google maps))"
},
}
```
### Preferences Setup
Optionally, create `.kbot/preferences.md` in your project directory to customize AI interactions:
```markdown
## My Preferences
Gender : male
Location : New York, USA (eg: `send me all saunas next to me`)
Language : English
Occupation : software developer, Typescript
Age : 30+
## Contacts
My email address : example@email.com (eg: `send me latest hacker news`)
My wife's email address ("Anne") : example@email.com (eg: `send email to my wife, with latest local news')
## Content
When creating content
- always Markdown
- always add links
- when sending emails, always add 'Best regards, [Your Name]'
```
## Commands
### Prompt
```kbot "create Astro minimal boilerplate, use starlight theme. Install dependencies via NPM tool"```
### Fetch latest models
```kbot fetch```
### Print examples
```kbot examples```
### Print extended help
```kbot help-md```
### Initialize folder
```kbot init```
# Command Line Parameters
This document describes all available command line parameters.
## Core Parameters
| Parameter | Description | Default | Required |
|-----------|-------------|---------|----------|
| `path` | Target directory | `.` | No |
| `prompt` | The prompt. Supports file paths and environment variables | `./prompt.md` | No |
| `output` | Optional output path for modified files (Tool mode only) | - | No |
| `dst` | Optional destination path for the result, will substitute ${MODEL} and ${ROUTER} in the path. | - | No |
| `model` | AI model to use for processing | `anthropic/claude-3.5-sonnet` | No |
| `router` | Router to use: openai or openrouter | `openrouter` | No |
| `mode` | Chat completion mode: "completion" (without tools) or "tools" | `tools` | No |
## Advanced Parameters
| Parameter | Description | Default | Required |
|-----------|-------------|---------|----------|
| `each` | Target directory | `.` | No |
| `dry` | Dry run - only write out parameters without making API calls | `false` | No |
## File Selection & Tools
| Parameter | Description | Default | Required |
|-----------|-------------|---------|----------|
| `include` | Glob patterns to match files for processing. Supports multiple patterns, e.g. `--include=src/*.tsx,src/*.ts --include=package.json` | - | No |
| `disable` | Disable tools categories | `[]` | No |
| `disableTools` | List of specific tools to disable | `[]` | No |
## Configuration & Profiles
| Parameter | Description | Default | Required |
|-----------|-------------|---------|----------|
| `profile` | Path to profile for variables. Supports environment variables | `${POLYMECH-ROOT}/profile.json` | No |
| `env` | Environment (in profile) | `default` | No |
| `config` | Path to JSON configuration file (API keys). Supports environment variables | - | No |
| `preferences` | Path to preferences file (location, email, gender, etc). Supports environment variables | `./.kbot/preferences.md` | No |
## Debugging & Logging
| Parameter | Description | Default | Required |
|-----------|-------------|---------|----------|
| `logLevel` | Logging level for the application (0-4) | `2` | No |
| `logs` | Logging directory | `./.kbot` | No |
| `dump` | Create a script | - | No |
# Working on Larger Directories
Since LLMs (Large Language Models) and providers are limited to very small 'context windows', it's necessary to feed them with smaller chunks instead. This document explains how to process larger directories efficiently.
## Directory Processing Example
Here's an example of how to walk through files and process them:
```bash
osr-cli each --main='kbot \"read ${KEY} and translate to german, save in docs/language code/filename.md\" --include=\"${REL}\" --include=\".kbot/preferences.md\"' --list="./docs/*.md" --cwd=.
```
### Parameter Explanation
- `each`: Command to process multiple files iteratively
- `--main`: The main command (`kbot`) to execute for each file
- `--include=\"${REL}\"` instructs kbot to include the current selected path
- `--include=\".kbot/preferences.md\"` instructs kbot to include additional preferences about the task (eg: translation specifics)
- `--list`: Specifies the file pattern to match
- Supports include patterns (e.g., `"./docs/*.md"`)
- `--cwd`: Sets the current working directory for the command execution. Default is the current directory (`.`)
**Note** requires `@plastichub/osr-cli-commons` to be installed globally:
```bash
npm i -g @plastichub/osr-cli-commons
```

View File

@ -4,53 +4,86 @@ exports.createClient = void 0;
const openai_1 = require("openai"); const openai_1 = require("openai");
const index_1 = require("./index"); const index_1 = require("./index");
const config_1 = require("./config"); const config_1 = require("./config");
/**
* Default base URLs for different routers
*/
const ROUTER_BASE_URLS = {
openrouter: 'https://openrouter.ai/api/v1',
openai: '', // OpenAI uses default URL
deepseek: 'https://api.deepseek.com',
huggingface: 'https://api-inference.huggingface.co',
ollama: 'http://localhost:11434', // Ollama's default local API endpoint
fireworks: 'https://api.fireworks.ai/v1', // Fireworks API endpoint
};
/**
* Default models for different routers
*/
const DEFAULT_MODELS = {
openrouter: 'anthropic/claude-3.5-sonnet',
openai: 'gpt-4o',
deepseek: 'deepseek-chat',
huggingface: 'meta-llama/2',
ollama: 'leonard', // Default Ollama model
fireworks: 'llama-v2-70b-chat', // Default Fireworks model
};
/**
* Creates an OpenAI client instance based on the provided options.
* @param options - Configuration options for the client
* @returns OpenAI client instance or undefined if configuration is invalid
*/
const createClient = (options) => { const createClient = (options) => {
// Load configuration from file
const config = (0, config_1.loadConfig)(options); const config = (0, config_1.loadConfig)(options);
let apiKey = options.api_key;
if (!config) { if (!config) {
index_1.logger.error("Config not found in $HOME/.osr/config.json. " + index_1.logger.error("Config not found in $HOME/.osr/config.json. " +
"Optionally, export OSR_CONFIG with the path to the configuration file, "); "Optionally, export OSR_CONFIG with the path to the configuration file, ");
return undefined; return undefined;
} }
const router = options.router ?? "openrouter"; // Determine router to use (defaults to 'openzxWEOpenrouter')
let baseURL = options.baseURL; const router = (options.router ?? 'openzxWEOpenrouter');
if (!options.baseURL) { // Initialize AC<41> EI key and baseURL
let apiKey = options.api_key;
// Set API key based on router if not provided in options
if (!apiKey) {
switch (router) { switch (router) {
case "openrouter": case 'openrouter':
apiKey = apiKey || config?.openrouter?.key; apiKey = config?.openrouter?.key;
if (!options.baseURL) {
baseURL = "https://openrouter.ai/api/v1";
}
break; break;
case "openai": case 'openai':
apiKey = apiKey || config?.openai?.key; apiKey = config?.openai?.key;
break; break;
case "deepseek": case 'deepseek':
apiKey = apiKey || config?.deepseek?.key; apiKey = config?.deepseek?.key;
if (!options.baseURL) { break;
baseURL = "https://api.deepseek.com"; case 'huggingface':
} apiKey = config?.huggingface?.key;
break;
case 'ollama':
// Ollama doesn't require an API key when running locally
apiKey = 'ollama'; // Dummy key for Ollama
break;
case 'fireworks':
apiKey = config?.fireworks?.key;
break; break;
} }
} }
if (!apiKey) { // Validate API key (escept for Ollama)
if (!apiKey && router !== 'ollama') {
index_1.logger.error(`No ${router} key found. Please provide an "api_key", set it in the config, or pass it via JSON config.`); index_1.logger.error(`No ${router} key found. Please provide an "api_key", set it in the config, or pass it via JSON config.`);
return undefined; return undefined;
} }
if (router === "openrouter" && !options.model) { // Set default baseURL if not provided
options.model = "anthropic/claude-3.5-sonnet"; const baseURL = options.baseURL ?? ROUTER_BASE_URLS[router];
} // Set default model if not provided
if (router === "openai" && !options.model) { if (!options.model) {
options.model = "gpt-4o"; options.model = DEFAULT_MODELS[router];
}
if (router === "deepseek" && !options.model) {
options.model = "deepseek-chat";
} }
index_1.logger.info(`Creating client with ${router} router, model ${options.model}, and API key ${apiKey} at ${baseURL}`); index_1.logger.info(`Creating client with ${router} router, model ${options.model}, and API key ${apiKey} at ${baseURL}`);
// Create and return the OpenAI client instance
return new openai_1.OpenAI({ return new openai_1.OpenAI({
apiKey, apiKey,
baseURL, baseURL,
}); });
}; };
exports.createClient = createClient; exports.createClient = createClient;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY2xpZW50LmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsic3JjL2NsaWVudC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7QUFBQSxtQ0FBK0I7QUFDL0IsbUNBQWdDO0FBQ2hDLHFDQUFxQztBQUc5QixNQUFNLFlBQVksR0FBRyxDQUFDLE9BQXFCLEVBQUUsR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