### Development Installation Source: https://github.com/holasoymalva/deepseek-cli/blob/main/README.md Clone the repository, install dependencies, build, and link for local development. ```bash git clone https://github.com/your-username/deepseek-cli.git cd deepseek-cli npm install npm run build npm link ``` -------------------------------- ### Setup Command: deepseek setup Source: https://github.com/holasoymalva/deepseek-cli/blob/main/README.md Run the setup command to install and configure the local Ollama environment. It checks if Ollama is installed, starts the Ollama service if needed, downloads the specified DeepSeek model, and verifies everything is working. ```bash deepseek setup ``` -------------------------------- ### Test Installation with DeepSeek Chat Source: https://github.com/holasoymalva/deepseek-cli/blob/main/LOCAL-SETUP.md Verifies the local setup by sending a prompt to the CLI. ```bash deepseek chat "Write a hello world function in Python" ``` -------------------------------- ### Launch DeepSeek CLI Source: https://github.com/holasoymalva/deepseek-cli/blob/main/README.md Start the DeepSeek CLI interactive session. Used after completing local or cloud setup. ```bash deepseek ``` -------------------------------- ### Start Ollama Service Source: https://github.com/holasoymalva/deepseek-cli/blob/main/LOCAL-SETUP.md Starts the Ollama server in the foreground. ```bash ollama serve ``` -------------------------------- ### List and Install Missing Models Source: https://github.com/holasoymalva/deepseek-cli/blob/main/LOCAL-SETUP.md Commands to check installed models and pull a missing one. ```bash # List installed models ollama list # Install missing model ollama pull deepseek-coder:6.7b ``` -------------------------------- ### Project Setup - Microservices with Node.js and Docker Compose Source: https://github.com/holasoymalva/deepseek-cli/blob/main/README.md Ask the CLI to generate a microservices architecture using Node.js and Docker Compose. ```text > Generate a microservices architecture using Node.js and Docker Compose. ``` -------------------------------- ### Build and Package Source: https://github.com/holasoymalva/deepseek-cli/blob/main/README.md Build the project and create a distributable package. ```bash npm run build npm run package ``` -------------------------------- ### Project Setup - Django with Docker, PostgreSQL, Redis Source: https://github.com/holasoymalva/deepseek-cli/blob/main/README.md Prompt the CLI to set up a Django project with Docker, PostgreSQL, and Redis. ```text > Set up a Django project with Docker, PostgreSQL, and Redis. ``` -------------------------------- ### Install DeepSeek CLI globally via npm Source: https://github.com/holasoymalva/deepseek-cli/blob/main/README.md Install the run-deepseek-cli package globally using npm. Required for both local and cloud setups. ```bash npm install -g run-deepseek-cli ``` -------------------------------- ### Start a New Project with DeepSeek CLI Source: https://github.com/holasoymalva/deepseek-cli/blob/main/README.md Run the CLI in a new project directory and prompt it to create a FastAPI web application with user authentication and PostgreSQL. ```sh cd new-project/ deepseek > Create a FastAPI web application with user authentication and a PostgreSQL database ``` -------------------------------- ### CLI: deepseek setup Source: https://github.com/holasoymalva/deepseek-cli/blob/main/_autodocs/index.md Local Ollama environment setup. Checks installation, starts Ollama, and pulls the model. ```APIDOC ## CLI: deepseek setup ### Description Local Ollama environment setup. Checks installation, starts Ollama, and pulls the model. ### Command `deepseek setup` ### Options - `-k, --api-key ` - Cloud API key - `-m, --model ` - Model override - `-l, --local` - Force local mode - `--ollama-host ` - Ollama host override - `--help` - Show help - `--version` - Show version ``` -------------------------------- ### Install DeepSeek Models with Ollama Source: https://github.com/holasoymalva/deepseek-cli/blob/main/LOCAL-SETUP.md Pull commands for three DeepSeek Coder models with size and RAM requirements. Choose based on system capabilities. ```bash # Choose one based on your system: ollama pull deepseek-coder:1.3b # Lightweight (1GB) ollama pull deepseek-coder:6.7b # Recommended (4GB) ollama pull deepseek-coder:33b # Most capable (19GB) ``` -------------------------------- ### Start Ollama Service (Foreground and Background) Source: https://github.com/holasoymalva/deepseek-cli/blob/main/LOCAL-SETUP.md Commands to start Ollama in the foreground or as a background process using nohup. ```bash # Start Ollama service ollama serve # Or run in background nohup ollama serve > /dev/null 2>&1 & ``` -------------------------------- ### Repository Context: Analyze entire repository with --include-all Source: https://github.com/holasoymalva/deepseek-cli/blob/main/README.md Use the --include-all flag to analyze the entire repository and include relevant context. The example shows a prompt to suggest improvements for the overall code architecture. ```bash # Analyze entire repository deepseek --include-all > Suggest improvements for the overall code architecture ``` -------------------------------- ### Install deepseek-cli with sudo for Permission Errors Source: https://github.com/holasoymalva/deepseek-cli/blob/main/README.md Installs run-deepseek-cli globally with sudo to resolve permission errors, or use a Node version manager like nvm as an alternative. ```bash sudo npm install -g run-deepseek-cli # Or use a Node version manager like nvm ``` -------------------------------- ### Explore and Understand Code - Design Patterns Source: https://github.com/holasoymalva/deepseek-cli/blob/main/README.md Ask the CLI which design patterns are used in the codebase. ```text > What design patterns are used in this codebase? ``` -------------------------------- ### Explore and Understand Code - Architecture Source: https://github.com/holasoymalva/deepseek-cli/blob/main/README.md Ask the CLI to explain the architecture of the application and identify main components. ```text > Explain the architecture of this application and identify the main components. ``` -------------------------------- ### Basic setupCommand call Source: https://github.com/holasoymalva/deepseek-cli/blob/main/_autodocs/api-reference/commands.md Example of calling setupCommand with the default configuration. In local mode, it checks Ollama, starts it if needed, and pulls the model. ```TypeScript import { getConfig } from './config'; import { setupCommand } from './commands/setup'; // Local mode: checks Ollama, starts it if needed, pulls the model. await setupCommand(getConfig()); ``` -------------------------------- ### Start Ollama service and pull DeepSeek Coder models Source: https://github.com/holasoymalva/deepseek-cli/blob/main/README.md Start the Ollama service and pull a DeepSeek Coder model. Choose from recommended 6.7b (4GB), lightweight 1.3b (1GB), or most capable 33b (19GB). ```bash # Start Ollama service ollama serve # Install DeepSeek Coder model (choose one) ollama pull deepseek-coder:6.7b # Recommended (4GB) ollama pull deepseek-coder:1.3b # Lightweight (1GB) ollama pull deepseek-coder:33b # Most capable (19GB) ``` -------------------------------- ### Project Setup - React TypeScript with Redux and Material-UI Source: https://github.com/holasoymalva/deepseek-cli/blob/main/README.md Ask the CLI to create a React TypeScript project with Redux Toolkit and Material-UI. ```text > Create a React TypeScript project with Redux Toolkit and Material-UI. ``` -------------------------------- ### Install Ollama on macOS, Linux, and Windows Source: https://github.com/holasoymalva/deepseek-cli/blob/main/README.md Install Ollama for local AI models. macOS uses Homebrew, Linux uses a curl script, and Windows requires downloading from the Ollama website. ```bash # macOS brew install ollama # Linux curl -fsSL https://ollama.ai/install.sh | sh # Windows: Download from https://ollama.ai ``` -------------------------------- ### Configure DeepSeek API access for cloud setup Source: https://github.com/holasoymalva/deepseek-cli/blob/main/README.md Set environment variables for API key and local usage flag. Required for cloud setup; get API key from DeepSeek Platform. ```bash export DEEPSEEK_API_KEY="your_api_key_here" export DEEPSEEK_USE_LOCAL=false ``` -------------------------------- ### Automated Installation Script (macOS/Linux) Source: https://github.com/holasoymalva/deepseek-cli/blob/main/LOCAL-SETUP.md One-line command to install DeepSeek CLI locally using the provided script. Requires curl and bash. ```bash curl -fsSL https://raw.githubusercontent.com/holasoymalva/deepseek-cli/main/install-local.sh | bash ``` -------------------------------- ### Repository Context: Include specific files/directories with --include Source: https://github.com/holasoymalva/deepseek-cli/blob/main/README.md Use the --include flag to specify particular files or directories for context. The example shows including src/, tests/, and README.md with a prompt to update documentation. ```bash # Include specific files/directories deepseek --include src/ tests/ README.md > Update the documentation to reflect recent API changes ``` -------------------------------- ### Integration Workflows: Analyze git diff, generate API docs, create migrations Source: https://github.com/holasoymalva/deepseek-cli/blob/main/README.md Use interactive mode for integration workflows. The examples show prompts to analyze a git diff and write a commit message, generate API documentation from an OpenAPI spec, and create database migration scripts from model changes. ```text > Analyze the git diff and write a commit message > Generate API documentation from this OpenAPI spec > Create database migration scripts from these model changes ``` -------------------------------- ### Code Review and Quality - Unit Tests Source: https://github.com/holasoymalva/deepseek-cli/blob/main/README.md Ask the CLI to add unit tests for all functions in a file. ```text > Add unit tests for all functions in this file. ``` -------------------------------- ### Run with Docker Source: https://github.com/holasoymalva/deepseek-cli/blob/main/README.md Run the CLI in a Docker container, mounting the current directory and setting the API key. ```bash docker run -it -v $(pwd):/workspace -e DEEPSEEK_API_KEY=your_key deepseek/cli ``` -------------------------------- ### Code Templates: Generate common patterns Source: https://github.com/holasoymalva/deepseek-cli/blob/main/README.md Use interactive mode to generate common code patterns and boilerplate. The examples show prompts for a React component template, a Python class with docstrings and type hints, and a GitHub Actions workflow for CI/CD. ```text > Generate a React component template with props validation > Create a Python class with proper docstrings and type hints > Set up a GitHub Actions workflow for CI/CD ``` -------------------------------- ### setupCommand(config: Config): Promise Source: https://github.com/holasoymalva/deepseek-cli/blob/main/_autodocs/api-reference/commands.md Sets up the DeepSeek CLI for local mode by checking Ollama installation, starting it if needed, and pulling the configured model. Prints step-by-step diagnostics and returns early on each guard failure without exiting the process. ```APIDOC ## setupCommand(config: Config): Promise ### Description Sets up the DeepSeek CLI for local mode by checking Ollama installation, starting it if needed, and pulling the configured model. Prints step-by-step diagnostics and returns early on each guard failure without exiting the process. ### Method setupCommand ### Endpoint src/commands/setup.ts ### Parameters #### Parameters - **config** (Config) - Required - Runtime configuration. Used for `useLocal`, `model`, and `ollamaHost`. ### Return Type `Promise` ### Behavior (local mode only) 1. `!config.useLocal` → prints "Setup is only needed for local mode." and returns immediately. 2. `checkOllamaInstalled()` (private, `which ollama` via `executeBash`) → if missing, prints install instructions for macOS/Linux/Windows and returns. 3. `api.checkOllamaConnection()` → if unreachable, attempts `executeBash('ollama serve &')` and waits 3 seconds; on failure prints manual-start instructions and returns. 4. `api.listOllamaModels()` → if `config.model` is absent, runs `executeBash('ollama pull ' + config.model)` under an `ora` spinner; on failure prints `ollama pull` retry instructions and returns. 5. Prints completion banner. ### Example — basic call ```ts import { getConfig } from './config'; import { setupCommand } from './commands/setup'; // Local mode: checks Ollama, starts it if needed, pulls the model. await setupCommand(getConfig()); ``` ### Example — non-trivial call ```ts import { getConfig } from './config'; import { setupCommand } from './commands/setup'; // Target a specific model on a custom host const config = { ...getConfig(), model: 'deepseek-coder:33b', ollamaHost: 'http://localhost:11434', }; await setupCommand(config); ``` ``` -------------------------------- ### Work with Existing Code using DeepSeek CLI Source: https://github.com/holasoymalva/deepseek-cli/blob/main/README.md Clone an existing repository, navigate into it, and ask the CLI to analyze the codebase for performance optimizations. ```sh git clone https://github.com/your-repo/existing-project cd existing-project deepseek > Analyze this codebase and suggest performance optimizations ``` -------------------------------- ### Explore and Understand Code - Security Vulnerabilities Source: https://github.com/holasoymalva/deepseek-cli/blob/main/README.md Ask the CLI to find potential security vulnerabilities in the code. ```text > Find potential security vulnerabilities in this code. ``` -------------------------------- ### Code Review and Quality - Algorithm Optimization Source: https://github.com/holasoymalva/deepseek-cli/blob/main/README.md Prompt the CLI to optimize an algorithm for better time complexity. ```text > Optimize this algorithm for better time complexity. ``` -------------------------------- ### setupCommand function implementation Source: https://github.com/holasoymalva/deepseek-cli/blob/main/_autodocs/api-reference/commands.md Exported async function that performs setup for local mode. It prints a banner, checks if local mode is enabled, and then runs the Ollama installation/start/pull workflow. Returns early on guard failures without exiting the process. ```TypeScript export async function setupCommand(config: Config): Promise { console.log(chalk.cyan('\n🔧 DeepSeek CLI Setup\n')); if (!config.useLocal) { console.log(chalk.yellow('Setup is only needed for local mode.')); console.log(chalk.gray('For cloud mode, just set your DEEPSEEK_API_KEY.')); return; } const api = new DeepSeekAPI(config); // Check if Ollama is installed console.log(chalk.gray('Checking Ollama installation...')); const ollamaInstalled = await checkOllamaInstalled(); // ... install / start / pull model workflow (see below) ... } ``` -------------------------------- ### Check Node.js Version and Update deepseek-cli Source: https://github.com/holasoymalva/deepseek-cli/blob/main/README.md Checks the installed Node.js version (should be 18+) and updates the deepseek-cli package globally via npm. ```bash node --version # Should be 18+ npm update -g deepseek-cli ``` -------------------------------- ### Code Generation and Refactoring - SOLID Principles Source: https://github.com/holasoymalva/deepseek-cli/blob/main/README.md Ask the CLI to refactor a class to follow SOLID principles. ```text > Refactor this class to follow SOLID principles. ``` -------------------------------- ### Single Prompt Chat Source: https://github.com/holasoymalva/deepseek-cli/blob/main/LOCAL-SETUP.md Sends a one-off prompt to DeepSeek CLI. ```bash deepseek chat "Explain how async/await works in JavaScript" ``` -------------------------------- ### Non-trivial setupCommand call with custom model and host Source: https://github.com/holasoymalva/deepseek-cli/blob/main/_autodocs/api-reference/commands.md Example of calling setupCommand with a specific model and custom Ollama host by overriding the default configuration. ```TypeScript import { getConfig } from './config'; import { setupCommand } from './commands/setup'; // Target a specific model on a custom host const config = { ...getConfig(), model: 'deepseek-coder:33b', ollamaHost: 'http://localhost:11434', }; await setupCommand(config); ``` -------------------------------- ### Switch to Local Mode (Default) Source: https://github.com/holasoymalva/deepseek-cli/blob/main/LOCAL-SETUP.md Sets the environment variable to use local mode and runs DeepSeek. ```bash export DEEPSEEK_USE_LOCAL=true deepseek ``` -------------------------------- ### Example - verifying a model is installed with listOllamaModels() Source: https://github.com/holasoymalva/deepseek-cli/blob/main/_autodocs/api-reference/api.md Shows how to list installed models and check if the configured model is present. If missing, prints an install command using 'ollama pull'. ```TypeScript import { getConfig } from './config'; import { DeepSeekAPI } from './api'; const api = new DeepSeekAPI(getConfig()); const models = await api.listOllamaModels(); if (models.includes(config.model)) { console.log(`Model ${config.model} is installed`); } else { console.log(`Install it with: ollama pull ${config.model}`); } ``` -------------------------------- ### Migration and Modernization - React Hooks Source: https://github.com/holasoymalva/deepseek-cli/blob/main/README.md Ask the CLI to migrate a React class component to hooks. ```text > Help me migrate this React class component to hooks. ``` -------------------------------- ### Create .env Configuration File Source: https://github.com/holasoymalva/deepseek-cli/blob/main/LOCAL-SETUP.md Environment variables to enable local mode, set the model, and specify the Ollama host. Default is local mode. ```bash # Local mode (default) DEEPSEEK_USE_LOCAL=true DEEPSEEK_MODEL=deepseek-coder:6.7b OLLAMA_HOST=http://localhost:11434 ``` -------------------------------- ### Check Ollama Accessibility and Use Custom Host Source: https://github.com/holasoymalva/deepseek-cli/blob/main/LOCAL-SETUP.md Commands to verify Ollama is reachable and to specify a custom host for DeepSeek. ```bash # Check if Ollama is accessible curl http://localhost:11434/api/tags # Use custom host deepseek --ollama-host http://192.168.1.100:11434 ``` -------------------------------- ### Code Generation and Refactoring - Error Handling Source: https://github.com/holasoymalva/deepseek-cli/blob/main/README.md Prompt the CLI to add comprehensive error handling to a module. ```text > Add comprehensive error handling to this module. ``` -------------------------------- ### Migration and Modernization - Python 2.7 to 3.10 Source: https://github.com/holasoymalva/deepseek-cli/blob/main/README.md Prompt the CLI to convert Python 2.7 code to Python 3.10 with type hints. ```text > Convert this Python 2.7 code to Python 3.10 with type hints. ``` -------------------------------- ### Code Review and Quality - Pull Request Review Source: https://github.com/holasoymalva/deepseek-cli/blob/main/README.md Prompt the CLI to review a pull request and suggest improvements. ```text > Review this pull request and suggest improvements. ``` -------------------------------- ### Programmatic usage example Source: https://github.com/holasoymalva/deepseek-cli/blob/main/_autodocs/api-reference/index.md Replicates the bin behavior by constructing CLI and calling run() directly. Sets process.argv to simulate the 'chat' command with the argument 'Explain async/await'. Useful when embedding the CLI in another Node.js process instead of invoking the binary. ```TypeScript import { CLI } from './cli'; process.argv = ['node', 'deepseek', 'chat', 'Explain async/await']; const cli = new CLI(); await cli.run(); ``` -------------------------------- ### Code Generation and Refactoring - REST API Source: https://github.com/holasoymalva/deepseek-cli/blob/main/README.md Prompt the CLI to implement a REST API for user management with CRUD operations. ```text > Implement a REST API for user management with CRUD operations. ``` -------------------------------- ### Force Local Mode with Model Selection Source: https://github.com/holasoymalva/deepseek-cli/blob/main/LOCAL-SETUP.md Uses the --local flag and specifies a model directly. ```bash deepseek --local --model deepseek-coder:1.3b ``` -------------------------------- ### BibTeX Citation for DeepSeek CLI and DeepSeek-Coder Source: https://github.com/holasoymalva/deepseek-cli/blob/main/README.md BibTeX entries for citing the DeepSeek CLI tool and the DeepSeek-Coder paper in research or projects. ```bibtex @misc{deepseek-cli, title={DeepSeek CLI: Command-Line AI Coding Assistant}, author={Your Name}, year={2025}, url={https://github.com/your-username/deepseek-cli} } @misc{deepseek-coder, author={Daya Guo, Qihao Zhu, Dejian Yang, Zhenda Xie, Kai Dong, Wentao Zhang, Guanting Chen, Xiao Bi, Y. Wu, Y.K. Li, Fuli Luo, Yingfei Xiong, Wenfeng Liang}, title={DeepSeek-Coder: When the Large Language Model Meets Programming -- The Rise of Code Intelligence}, journal={CoRR}, volume={abs/2401.14196}, year={2024}, url={https://arxiv.org/abs/2401.14196} } ``` -------------------------------- ### Migration and Modernization - Express.js Async/Await Source: https://github.com/holasoymalva/deepseek-cli/blob/main/README.md Ask the CLI to upgrade an Express.js app to use async/await instead of callbacks. ```text > Upgrade this Express.js app to use async/await instead of callbacks. ``` -------------------------------- ### Create .env configuration file Source: https://github.com/holasoymalva/deepseek-cli/blob/main/README.md Create a `.env` file in your project root to configure DeepSeek CLI. Local mode is the default with `DEEPSEEK_USE_LOCAL=true` and `DEEPSEEK_MODEL=deepseek-coder:6.7b`. Cloud mode is optional and commented out; uncomment and set `DEEPSEEK_USE_LOCAL=false` and provide your `DEEPSEEK_API_KEY`. ```bash # Local mode (default) DEEPSEEK_USE_LOCAL=true DEEPSEEK_MODEL=deepseek-coder:6.7b OLLAMA_HOST=http://localhost:11434 # Cloud mode (optional) # DEEPSEEK_USE_LOCAL=false # DEEPSEEK_API_KEY=your_api_key_here ``` -------------------------------- ### Code Completion and Generation - JavaScript to TypeScript Source: https://github.com/holasoymalva/deepseek-cli/blob/main/README.md Prompt the CLI to convert a JavaScript function to TypeScript with proper type annotations. ```sh deepseek > Convert this JavaScript function to TypeScript with proper type annotations ``` -------------------------------- ### Code Completion and Generation - Binary Search Source: https://github.com/holasoymalva/deepseek-cli/blob/main/README.md Prompt the CLI to write a Python function implementing binary search with proper error handling. ```sh deepseek > Write a Python function to implement binary search with proper error handling ``` -------------------------------- ### Basic call example for chatCommand Source: https://github.com/holasoymalva/deepseek-cli/blob/main/_autodocs/api-reference/commands.md Shows a minimal invocation: load config via getConfig() and await chatCommand with a prompt. Assumes config is already resolved and the model is reachable. ```TypeScript import { getConfig } from './config'; import { chatCommand } from './commands/chat'; const config = getConfig(); await chatCommand('Write a JavaScript debounce function', config); ``` -------------------------------- ### interactiveCommand Source: https://github.com/holasoymalva/deepseek-cli/blob/main/_autodocs/index.md Starts an interactive REPL session. ```APIDOC ## interactiveCommand ### Description Starts an interactive REPL session. ### Signature `interactiveCommand(config: Config): Promise` ### Parameters - `config` (Config) - Required - The configuration object. ### Returns - `Promise` - Resolves when the session ends. ``` -------------------------------- ### Programmatic configuration with all sources Source: https://github.com/holasoymalva/deepseek-cli/blob/main/_autodocs/configuration.md Shows how to load configuration from environment variables, override the model programmatically, and run the CLI with flags that override env values inside buildConfig. The example uses DEEPSEEK_USE_LOCAL=true and DEEPSEEK_MODEL=deepseek-coder:6.7b from env, then mutates the model to 'deepseek-coder:1.3b', and finally runs the CLI with --local flag. ```TypeScript import { getConfig } from './config'; import { CLI } from './cli'; // 1) env: DEEPSEEK_USE_LOCAL=true, DEEPSEEK_MODEL=deepseek-coder:6.7b (defaults apply) const fromEnv = getConfig(); // 2) programmatic override (equivalent to CLI flags — buildConfig is private, // mutate the object yourself or pass to DeepSeekAPI directly) const fromEnv.model = 'deepseek-coder:1.3b'; // 3) CLI path: flags override env inside buildConfig process.argv = ['node', 'deepseek', '--local', 'chat', 'hi']; const cli = new CLI(); await cli.run(); ``` -------------------------------- ### Basic call to interactiveCommand Source: https://github.com/holasoymalva/deepseek-cli/blob/main/_autodocs/api-reference/commands.md Imports getConfig and interactiveCommand, creates a config, and starts the REPL. The call blocks on stdin until the user types 'exit'. ```TypeScript import { getConfig } from './config'; import { interactiveCommand } from './commands/interactive'; const config = getConfig(); // Blocks on stdin; typing "exit" ends the session. await interactiveCommand(config); ``` -------------------------------- ### run(): Promise Source: https://github.com/holasoymalva/deepseek-cli/blob/main/_autodocs/api-reference/cli.md Parses process.argv and dispatches to the appropriate command based on arguments. Handles chat, setup, interactive mode, and help/version flags. ```APIDOC ## run(): Promise ### Description Parses `process.argv` and dispatches to the appropriate command based on the arguments. Handles chat, setup, interactive mode, and help/version flags. ### Method run() ### Endpoint N/A (programmatic method) ### Parameters None. ### Return type `Promise` — resolves when commander finishes parsing and the dispatched action settles, or when the process exits via `process.exit(1)` inside `chatCommand`/`interactiveCommand` error paths. ### Behavior Parses `process.argv`. Depending on the arguments, one of the following runs: - `deepseek chat ""` → `chatCommand(prompt, config)` - `deepseek setup` → `setupCommand(config)` - `deepseek` (no args) → prints the welcome banner and runs `interactiveCommand(config)` - `deepseek --help` / `--version` → commander handles them ### Example — programmatic invocation ```ts import { CLI } from './cli'; // Simulate: deepseek chat "hello" process.argv = ['node', 'deepseek', 'chat', 'Write a factorial in Rust']; const cli = new CLI(); await cli.run(); ``` ### Example — error handling ```ts import { CLI } from './cli'; // Simulate cloud mode without a key: buildConfig throws during dispatch process.env.DEEPSEEK_USE_LOCAL = 'false'; process.env.DEEPSEEK_API_KEY = ''; process.argv = ['node', 'deepseek', 'chat', 'hi']; try { const cli = new CLI(); await cli.run(); } catch (error) { // "API key required for cloud mode. Set DEEPSEEK_API_KEY or use --api-key flag. ..." console.error(error instanceof Error ? error.message : error); process.exit(1); } ``` ``` -------------------------------- ### Usage example: completeWithOllama via DeepSeekAPI Source: https://github.com/holasoymalva/deepseek-cli/blob/main/_autodocs/endpoints.md TypeScript example showing how to use the DeepSeekAPI client in local mode. It imports getConfig and DeepSeekAPI, creates a config (which builds the Ollama endpoint), instantiates the API, and calls complete() with a prompt. The reply is returned as-is from data.message.content. ```ts import { getConfig } from './config'; import { DeepSeekAPI } from './api'; const config = getConfig(); // local mode → POST http://localhost:11434/api/chat const api = new DeepSeekAPI(config); const reply = await api.complete('Write a binary search in Python'); ``` -------------------------------- ### CLI: deepseek Source: https://github.com/holasoymalva/deepseek-cli/blob/main/_autodocs/index.md Interactive REPL mode (default action). Starts a chat session with the configured backend. ```APIDOC ## CLI: deepseek ### Description Interactive REPL mode (default action). Starts a chat session with the configured backend. ### Command `deepseek` ### Options - `-k, --api-key ` - Cloud API key - `-m, --model ` - Model override - `-l, --local` - Force local mode - `--ollama-host ` - Ollama host override - `--help` - Show help - `--version` - Show version ``` -------------------------------- ### Set DeepSeek API Key Environment Variable Source: https://github.com/holasoymalva/deepseek-cli/blob/main/README.md Exports the DEEPSEEK_API_KEY environment variable with your actual API key. Verify the variable is set using echo $DEEPSEEK_API_KEY. ```bash export DEEPSEEK_API_KEY="your_actual_api_key" # Verify with: echo $DEEPSEEK_API_KEY ``` -------------------------------- ### CLI construction and run example Source: https://github.com/holasoymalva/deepseek-cli/blob/main/_autodocs/api-reference/cli.md Shows how src/index.ts instantiates the CLI and runs it, catching errors and exiting with a non-zero code. Uses chalk for error coloring. ```TypeScript import { CLI } from './cli'; async function main() { const cli = new CLI(); await cli.run(); } main().catch((error) => { console.error(chalk.red('Error:'), error instanceof Error ? error.message : error); process.exit(1); }); ``` -------------------------------- ### Error handling example for chatCommand Source: https://github.com/holasoymalva/deepseek-cli/blob/main/_autodocs/api-reference/commands.md Demonstrates a failure scenario (Ollama not running) and warns that chatCommand exits the process with code 1 after printing 'Error: Cannot connect to Ollama at ...'. Do not rely on catching the rejection. ```TypeScript import { getConfig } from './config'; import { chatCommand } from './commands/chat'; // Local mode, but Ollama is not running const config = { ...getConfig(), apiUrl: 'http://localhost:11434/api/chat' }; // Do NOT rely on catching here: chatCommand exits the process (exit code 1) // after printing "Error: Cannot connect to Ollama at ...". await chatCommand('hello', config); ``` -------------------------------- ### Example — error handling with api.complete() Source: https://github.com/holasoymalva/deepseek-cli/blob/main/_autodocs/api-reference/api.md Wraps complete() in a try/catch. The error message is actionable, e.g. 'Cannot connect to Ollama at http://localhost:11434. Make sure Ollama is running: ollama serve And the model is installed: ollama pull deepseek-coder:6.7b'. ```TypeScript import { getConfig } from './config'; import { DeepSeekAPI } from './api'; const api = new DeepSeekAPI(getConfig()); try { const answer = await api.complete('Explain closures in JavaScript'); console.log(answer); } catch (error) { // Error messages are actionable, e.g.: // "Cannot connect to Ollama at http://localhost:11434. // Make sure Ollama is running: ollama serve // And the model is installed: ollama pull deepseek-coder:6.7b" console.error('Completion failed:', error instanceof Error ? error.message : error); } ``` -------------------------------- ### checkOllamaInstalled private helper Source: https://github.com/holasoymalva/deepseek-cli/blob/main/_autodocs/api-reference/commands.md Private async function that checks if Ollama is installed by running 'which ollama' via executeBash. Returns true if the command succeeds, false otherwise. ```TypeScript async function checkOllamaInstalled(): Promise { try { await executeBash('which ollama'); return true; } catch { return false; } } ``` -------------------------------- ### Example - basic call to checkOllamaConnection() Source: https://github.com/holasoymalva/deepseek-cli/blob/main/_autodocs/api-reference/api.md Shows how to instantiate DeepSeekAPI with getConfig() and call checkOllamaConnection(). Logs whether Ollama is reachable or suggests running 'ollama serve' when unreachable. ```TypeScript import { getConfig } from './config'; import { DeepSeekAPI } from './api'; const api = new DeepSeekAPI(getConfig()); if (await api.checkOllamaConnection()) { console.log('Ollama is reachable'); } else { console.log('Ollama is unreachable — run "ollama serve"'); } ``` -------------------------------- ### Error handling example Source: https://github.com/holasoymalva/deepseek-cli/blob/main/_autodocs/api-reference/cli.md Simulates cloud mode without an API key, causing buildConfig to throw during dispatch. Catches the error and logs the message before exiting. ```TypeScript import { CLI } from './cli'; // Simulate cloud mode without a key: buildConfig throws during dispatch process.env.DEEPSEEK_USE_LOCAL = 'false'; process.env.DEEPSEEK_API_KEY = ''; process.argv = ['node', 'deepseek', 'chat', 'hi']; try { const cli = new CLI(); await cli.run(); } catch (error) { // "API key required for cloud mode. Set DEEPSEEK_API_KEY or use --api-key flag. ..." console.error(error instanceof Error ? error.message : error); process.exit(1); } ``` -------------------------------- ### Example — construction of DeepSeekAPI Source: https://github.com/holasoymalva/deepseek-cli/blob/main/_autodocs/api-reference/api.md Creates a DeepSeekAPI instance using the resolved configuration from getConfig(). ```TypeScript import { getConfig } from './config'; import { DeepSeekAPI } from './api'; const api = new DeepSeekAPI(getConfig()); ``` -------------------------------- ### Basic call example — executeBash('which ollama') Source: https://github.com/holasoymalva/deepseek-cli/blob/main/_autodocs/api-reference/utils-exec.md Shows a basic invocation of executeBash. The returned promise resolves to trimmed stdout, e.g. '/usr/local/bin/ollama'. ```TypeScript import { executeBash } from './utils/exec'; const path = await executeBash('which ollama'); console.log(path); // trimmed stdout, e.g. '/usr/local/bin/ollama' ``` -------------------------------- ### listOllamaModels() implementation Source: https://github.com/holasoymalva/deepseek-cli/blob/main/_autodocs/api-reference/api.md Fetches the list of installed Ollama models from GET /api/tags and returns their names. Returns an empty array if the request fails or the response has no 'models' field. Never throws. ```TypeScript async listOllamaModels(): Promise { try { const response = await axios.get(`${this.config.ollamaHost}/api/tags`, { timeout: 5000 }); return response.data.models?.map((model: any) => model.name) || []; } catch { return []; } } ``` -------------------------------- ### Programmatic invocation example Source: https://github.com/holasoymalva/deepseek-cli/blob/main/_autodocs/api-reference/cli.md Simulates the CLI command 'deepseek chat "Write a factorial in Rust"' by setting process.argv and calling run(). ```TypeScript import { CLI } from './cli'; // Simulate: deepseek chat "hello" process.argv = ['node', 'deepseek', 'chat', 'Write a factorial in Rust']; const cli = new CLI(); await cli.run(); ``` -------------------------------- ### interactiveCommand implementation (src/commands/interactive.ts) Source: https://github.com/holasoymalva/deepseek-cli/blob/main/_autodocs/api-reference/commands.md Main exported function that starts an interactive REPL. If config.useLocal is true, it checks the Ollama connection and model availability, printing non-fatal diagnostics. The REPL loop (omitted here) handles 'exit' and prompts with 'deepseek-cli > '. ```TypeScript export async function interactiveCommand(config: Config): Promise { const api = new DeepSeekAPI(config); // Check Ollama connection if using local mode if (config.useLocal) { const isConnected = await api.checkOllamaConnection(); if (!isConnected) { console.log(chalk.red('⚠️ Cannot connect to Ollama at'), chalk.white(config.ollamaHost)); console.log(chalk.yellow('Make sure Ollama is running:'), chalk.white('ollama serve')); console.log(chalk.yellow('Install the model:'), chalk.white(`ollama pull ${config.model}`)); console.log(''); } else { console.log(chalk.green('✅ Connected to Ollama')); const models = await api.listOllamaModels(); if (!models.includes(config.model)) { console.log(chalk.yellow(`⚠️ Model '${config.model}' not found locally`)); console.log(chalk.yellow('Install it with:'), chalk.white(`ollama pull ${config.model}`)); } console.log(''); } } // ... readline loop (see below) ... } ``` -------------------------------- ### Example — basic call to api.complete() Source: https://github.com/holasoymalva/deepseek-cli/blob/main/_autodocs/api-reference/api.md Shows a basic async call to complete() that logs the assistant's answer. In local mode it uses stream:false, temperature 0.1, num_predict 4096, and a 120000 ms timeout; in cloud mode it uses temperature 0.1, max_tokens 4096, and a 30000 ms timeout. ```TypeScript import { getConfig } from './config'; import { DeepSeekAPI } from './api'; async function ask() { const api = new DeepSeekAPI(getConfig()); const answer = await api.complete('Write a Python binary search function'); console.log(answer); } ``` -------------------------------- ### GET {ollamaHost}/api/tags — connection check / model listing Source: https://github.com/holasoymalva/deepseek-cli/blob/main/_autodocs/endpoints.md Retrieves the list of models available on the local Ollama server. Used by checkOllamaConnection and listOllamaModels to verify connectivity and list installed models. ```APIDOC ## GET {ollamaHost}/api/tags ### Description Retrieves the list of models available on the local Ollama server. Used by checkOllamaConnection and listOllamaModels to verify connectivity and list installed models. ### Method GET ### Endpoint {ollamaHost}/api/tags ### Parameters None ### Response #### Success Response (200) - **models** (array) - List of model objects. #### Response Example ```json { "models": [ { "name": "deepseek-coder:6.7b" } ] } ``` ### Error Handling - **Connection failure**: Throws connection error message. - **Other**: Throws `Ollama API error: `. ``` -------------------------------- ### setupCommand Source: https://github.com/holasoymalva/deepseek-cli/blob/main/_autodocs/index.md Sets up the local Ollama environment. ```APIDOC ## setupCommand ### Description Sets up the local Ollama environment. ### Signature `setupCommand(config: Config): Promise` ### Parameters - `config` (Config) - Required - The configuration object. ### Returns - `Promise` - Resolves when setup completes. ``` -------------------------------- ### Basic call to getConfig() Source: https://github.com/holasoymalva/deepseek-cli/blob/main/_autodocs/api-reference/config.md Example showing default behavior when no environment variables are set. useLocal defaults to true, model defaults to 'deepseek-coder:6.7b', ollamaHost defaults to 'http://localhost:11434', and apiUrl becomes 'http://localhost:11434/api/chat' in local mode. ```TypeScript import { getConfig } from './config'; const config = getConfig(); console.log(config.useLocal); // true by default console.log(config.model); // 'deepseek-coder:6.7b' by default console.log(config.ollamaHost); // 'http://localhost:11434' by default console.log(config.apiUrl); // 'http://localhost:11434/api/chat' in local mode ``` -------------------------------- ### Error handling example — executeBash('ollama pull deepseek-coder:6.7b') Source: https://github.com/holasoymalva/deepseek-cli/blob/main/_autodocs/api-reference/utils-exec.md Demonstrates catching the error thrown by executeBash. The error message follows the format "Command failed: ollama pull deepseek-coder:6.7b\n...". ```TypeScript import { executeBash } from './utils/exec'; try { await executeBash('ollama pull deepseek-coder:6.7b'); } catch (error) { // error.message === "Command failed: ollama pull deepseek-coder:6.7b\n..." console.error(error instanceof Error ? error.message : error); } ``` -------------------------------- ### Catch and retry pattern for Ollama completion failures Source: https://github.com/holasoymalva/deepseek-cli/blob/main/_autodocs/errors.md Example error handling pattern for local (Ollama) completion failures. Catches errors from api.complete and checks for specific messages: 'Cannot connect to Ollama' (ECONNREFUSED), 'not found in Ollama' (404), or falls back to logging the raw error message. ```ts import { getConfig } from './config'; import { DeepSeekAPI } from './api'; const api = new DeepSeekAPI(getConfig()); try { await api.complete('hello'); } catch (error) { const message = error instanceof Error ? error.message : String(error); if (message.startsWith('Cannot connect to Ollama')) { console.log('Start Ollama: ollama serve, then retry'); } else if (message.includes('not found in Ollama')) { console.log('Model missing — run: ollama pull ' + getConfig().model); } else { console.error(message); } } ``` -------------------------------- ### Catch pattern for executeBash errors Source: https://github.com/holasoymalva/deepseek-cli/blob/main/_autodocs/errors.md Use this try/catch pattern to handle errors from the executeBash function. It checks if the error message starts with 'Command failed:' to identify command-level failures, where the error message embeds stderr/stdout details. This is useful for external consumers, as setupCommand handles these errors internally. ```TypeScript import { executeBash } from './utils/exec'; try { await executeBash('ollama pull deepseek-coder:6.7b'); } catch (error) { if (error instanceof Error && error.message.startsWith('Command failed:')) { // command-level failure; error.message embeds the stderr/stdout detail } } ``` -------------------------------- ### Cloud chat completion usage example Source: https://github.com/holasoymalva/deepseek-cli/blob/main/_autodocs/endpoints.md Configures the client for cloud mode and sends a chat completion request. Requires DEEPSEEK_USE_LOCAL=false and a valid DEEPSEEK_API_KEY; the reply is returned by complete(). ```TypeScript process.env.DEEPSEEK_USE_LOCAL = 'false'; process.env.DEEPSEEK_API_KEY = 'sk-...'; const config = getConfig(); // apiUrl === 'https://api.deepseek.com/chat/completions' const api = new DeepSeekAPI(config); const reply = await api.complete('Summarize this diff'); ``` -------------------------------- ### GET {ollamaHost}/api/tags Source: https://github.com/holasoymalva/deepseek-cli/blob/main/_autodocs/endpoints.md Inspects the local model registry by listing available models. Returns an array of model names or an empty array on failure. ```APIDOC ## GET {ollamaHost}/api/tags ### Description Inspects the local model registry by listing available models. ### Method GET ### Endpoint {ollamaHost}/api/tags ### Parameters No parameters. ### Request Example No request body. ### Response #### Success Response (200) - **data.models** (array) - Registry entries (optional; absence treated as `[]`) - **data.models[].name** (string) - Model tag, e.g. `deepseek-coder:6.7b` #### Response Example ```json { "data": { "models": [ { "name": "deepseek-coder:6.7b" } ] } } ``` ### Client Mapping - `checkOllamaConnection()` returns `response.status === 200` (any failure → `false`) - `listOllamaModels()` returns `data.models?.map(m => m.name) || []` (any failure → `[]`) ### Usage Example ```ts const api = new DeepSeekAPI(getConfig()); const running = await api.checkOllamaConnection(); // true / false const models = await api.listOllamaModels(); // string[] ``` ``` -------------------------------- ### Non-trivial option combination for cloud mode Source: https://github.com/holasoymalva/deepseek-cli/blob/main/_autodocs/api-reference/config.md Example showing cloud mode by setting DEEPSEEK_API_KEY, DEEPSEEK_USE_LOCAL='false', and DEEPSEEK_MODEL before calling getConfig(). getConfig() is read-only w.r.t. env; call sites that need overrides mutate the returned object. Output shows useLocal false, apiUrl 'https://api.deepseek.com/chat/completions', apiKey 'sk-123', and model 'deepseek-chat'. ```TypeScript // Cloud mode: set the key before calling. getConfig() is read-only w.r.t. env; // call sites that need overrides mutate the returned object. process.env.DEEPSEEK_API_KEY = 'sk-123'; process.env.DEEPSEEK_USE_LOCAL = 'false'; process.env.DEEPSEEK_MODEL = 'deepseek-chat'; const config = getConfig(); console.log(config.useLocal); // false console.log(config.apiUrl); // 'https://api.deepseek.com/chat/completions' console.log(config.apiKey); // 'sk-123' console.log(config.model); // 'deepseek-chat' ``` -------------------------------- ### Cloud mode validation error message Source: https://github.com/holasoymalva/deepseek-cli/blob/main/_autodocs/errors.md Exact error message shown when cloud mode is active without an API key. Triggered when config.useLocal is falsy and config.apiKey is falsy (empty string counts as falsy). Reached for any command (chat, setup, default action) when cloud mode is active without a key. ```text API key required for cloud mode. Set DEEPSEEK_API_KEY or use --api-key flag. Get your key at: https://platform.deepseek.com/api_keys Or use local mode with --local flag ``` -------------------------------- ### checkOllamaConnection(): Promise Source: https://github.com/holasoymalva/deepseek-cli/blob/main/_autodocs/api-reference/api.md Checks whether the Ollama server is reachable by sending a GET request to /api/tags. Returns true if the server responds with status 200 within 5 seconds, otherwise false. This method never throws an exception. ```APIDOC ## checkOllamaConnection(): Promise ### Description Checks whether the Ollama server is reachable by sending a GET request to /api/tags. Returns true if the server responds with status 200 within 5 seconds, otherwise false. This method never throws an exception. ### Method GET ### Endpoint `${config.ollamaHost}/api/tags` ### Parameters None. ### Return Type `Promise` — `true` when the Ollama server at `config.ollamaHost` answers `GET /api/tags` with status 200 within 5 seconds; `false` on any error (including connection refused, timeout, or non-200 status). Never throws. ### Example — basic call ```ts import { getConfig } from './config'; import { DeepSeekAPI } from './api'; const api = new DeepSeekAPI(getConfig()); if (await api.checkOllamaConnection()) { console.log('Ollama is reachable'); } else { console.log('Ollama is unreachable — run "ollama serve"'); } ``` ``` -------------------------------- ### listOllamaModels(): Promise Source: https://github.com/holasoymalva/deepseek-cli/blob/main/_autodocs/api-reference/api.md Retrieves the list of model names from the Ollama registry by calling GET /api/tags. Returns an array of model names, or an empty array if the request fails or no models are present. This method never throws an exception. ```APIDOC ## listOllamaModels(): Promise ### Description Retrieves the list of model names from the Ollama registry by calling GET /api/tags. Returns an array of model names, or an empty array if the request fails or no models are present. This method never throws an exception. ### Method GET ### Endpoint `${config.ollamaHost}/api/tags` ### Parameters None. ### Return Type `Promise` — the `name` of every model present in the Ollama registry at `config.ollamaHost` (from `GET /api/tags` → `data.models[].name`). Returns an empty array `[]` if the request fails or the response carries no `models` field. Never throws. ### Example — verifying a model is installed ```ts import { getConfig } from './config'; import { DeepSeekAPI } from './api'; const api = new DeepSeekAPI(getConfig()); const models = await api.listOllamaModels(); if (models.includes(config.model)) { console.log(`Model ${config.model} is installed`); } else { console.log(`Install it with: ollama pull ${config.model}`); } ``` ``` -------------------------------- ### checkOllamaConnection() implementation Source: https://github.com/holasoymalva/deepseek-cli/blob/main/_autodocs/api-reference/api.md Checks if the Ollama server at config.ollamaHost is reachable by sending a GET request to /api/tags with a 5-second timeout. Returns true only if the response status is 200; returns false on any error (connection refused, timeout, non-200 status). Never throws. ```TypeScript async checkOllamaConnection(): Promise { try { const response = await axios.get(`${this.config.ollamaHost}/api/tags`, { timeout: 5000 }); return response.status === 200; } catch { return false; } } ```