### Example: Set Commit Language to Simplified Chinese Source: https://github.com/johnnyz93/oai-compatible-copilot/blob/main/_autodocs/configuration.md Example of how to set the commit language to Simplified Chinese in the configuration. ```json { "oaicopilot.commitLanguage": "Chinese (Simplified)" } ``` -------------------------------- ### Clone and Install Project Dependencies Source: https://github.com/johnnyz93/oai-compatible-copilot/blob/main/CONTRIBUTING.md Clone the repository, navigate to the project directory, install dependencies, and compile the project. Press F5 to launch an Extension Development Host. ```bash git clone https://github.com/JohnnyZ93/oai-compatible-copilot cd oai-compatible-copilot npm install npm run compile ``` -------------------------------- ### Example: Set Read File Lines Limit Source: https://github.com/johnnyz93/oai-compatible-copilot/blob/main/_autodocs/configuration.md Example of limiting the `read_file` tool to a maximum of 100 lines per call. ```json { "oaicopilot.readFileLines": 100 } ``` -------------------------------- ### Generate Model Display Name Examples Source: https://github.com/johnnyz93/oai-compatible-copilot/blob/main/_autodocs/api-reference/modelinfo.md Examples demonstrating how human-readable display names are generated for model configurations, considering ID, configId, and provider. ```string "gpt-4" ``` ```string "gpt-4::thinking" ``` ```string "claude-3-5-sonnet (anthropic)" ``` -------------------------------- ### Example: Set Custom Commit Message Prompt Source: https://github.com/johnnyz93/oai-compatible-copilot/blob/main/_autodocs/configuration.md Example of setting a custom prompt for generating commit messages, specifying a detailed format. ```json { "oaicopilot.commitMessagePrompt": "Generate a detailed commit message describing the changes. Follow conventional commits format (feat:, fix:, etc.)" } ``` -------------------------------- ### Model Matching Logic Example Flow Source: https://github.com/johnnyz93/oai-compatible-copilot/blob/main/_autodocs/api-reference/modelinfo.md Illustrates the step-by-step process for matching a user-selected model ID with an available configuration, prioritizing exact matches. ```text User selects: "gpt-4::thinking" ↓ Parsed as: { baseId: "gpt-4", configId: "thinking" } ↓ Search for: { id: "gpt-4", configId: "thinking" } ↓ Use that configuration (including temperature, thinking settings, etc.) ``` -------------------------------- ### Model Family Configuration Example Source: https://github.com/johnnyz93/oai-compatible-copilot/blob/main/_autodocs/api-reference/modelinfo.md Example of a JSON configuration for a model, specifying its ID, family, and ownership, which influences special prompt treatment and optimization. ```json { "id": "gpt-4", "family": "gpt", "owned_by": "openai" } ``` -------------------------------- ### Tool Call Handling in Streaming Responses Source: https://github.com/johnnyz93/oai-compatible-copilot/blob/main/_autodocs/api-reference/anthropicapi.md Demonstrates how tool use blocks stream JSON arguments incrementally in Anthropic API responses. This example shows the sequence of events for a tool call, including start, delta, and stop. ```text content_block_start: { type: "tool_use", id: "toolu_123", name: "read_file" } content_block_delta: { type: "input_json_delta", partial_json: "{\"pa" } content_block_delta: { type: "input_json_delta", partial_json: "th": ...}" } content_block_stop: {} ``` -------------------------------- ### Example Git Diff Output Source: https://github.com/johnnyz93/oai-compatible-copilot/blob/main/_autodocs/api-reference/gitcommit.md An example of the unified diff string format returned by the getGitDiff function, showing changes to a file. ```diff diff --git a/src/main.ts b/src/main.ts index 1234567..abcdefg 100644 --- a/src/main.ts +++ b/src/main.ts @@ -10,6 +10,12 @@ function main() { console.log("Starting..."); + const config = loadConfig(); + + if (!config.valid) { + throw new Error("Invalid config"); + } + doWork(); } ``` -------------------------------- ### Gemini API Configuration Example Source: https://github.com/johnnyz93/oai-compatible-copilot/blob/main/_autodocs/api-reference/geminiapi.md A sample JSON configuration for the Gemini API, specifying model details, API mode, and generation settings including thinking support. ```json { "id": "gemini-2.0-flash", "owned_by": "gemini", "baseUrl": "https://generativelanguage.googleapis.com", "apiMode": "gemini", "max_tokens": 4096, "temperature": 1.0, "vision": true, "extra": { "generationConfig": { "thinkingConfig": { "includeThoughts": true } } } } ``` -------------------------------- ### Example Model Configuration for Commit Generation Source: https://github.com/johnnyz93/oai-compatible-copilot/blob/main/_autodocs/api-reference/gitcommit.md Configure models for commit generation by setting `useForCommitGeneration` to true. Ensure the model is not in Gemini API mode, as it's not supported. ```json { "oaicopilot.models": [ { "id": "gpt-4", "owned_by": "openai", "useForCommitGeneration": true }, { "id": "claude-3-5-sonnet", "owned_by": "anthropic", "apiMode": "anthropic", "useForCommitGeneration": true } ] } ``` -------------------------------- ### Common npm Scripts for Development Source: https://github.com/johnnyz93/oai-compatible-copilot/blob/main/CONTRIBUTING.md These scripts are commonly used for building, watching, linting, and formatting the project. Ensure Node.js 22 is installed. ```bash npm run compile ``` ```bash npm run watch ``` ```bash npm run lint ``` ```bash npm run format ``` -------------------------------- ### Gemini convertMessages Example Output Source: https://github.com/johnnyz93/oai-compatible-copilot/blob/main/_autodocs/api-reference/geminiapi.md Provides an example of the output from the convertMessages method, showing a user message with text and inline image data, followed by a model message with text and a function call. ```typescript [ { role: "user", parts: [ { text: "What's in this image?" }, { inlineData: { mimeType: "image/png", data: "iVBORw0KGgo..." } } ] }, { role: "model", parts: [ { text: "I can see a cat in the image." }, { functionCall: { name: "read_file", args: { path: "/file.txt" } } } ] } ] ``` -------------------------------- ### Configure Language Models Source: https://github.com/johnnyz93/oai-compatible-copilot/blob/main/_autodocs/configuration.md Define configurations for various language models, including their IDs, API endpoints, context lengths, and generation parameters. This example shows configurations for models from ModelScope, Anthropic, and Gemini. ```json { "oaicopilot.models": [ { "id": "Qwen/Qwen3-Coder-480B", "owned_by": "modelscope", "baseUrl": "https://api-inference.modelscope.cn/v1", "context_length": 256000, "max_tokens": 8192, "temperature": 0, "top_p": 1, "vision": false }, { "id": "claude-3-5-sonnet-20241022", "owned_by": "anthropic", "baseUrl": "https://api.anthropic.com", "apiMode": "anthropic", "max_tokens": 4096, "temperature": 1.0, "vision": true, "cache_control": true }, { "id": "gemini-2.0-flash", "owned_by": "gemini", "baseUrl": "https://generativelanguage.googleapis.com", "apiMode": "gemini", "max_tokens": 4096, "vision": true } ] } ``` -------------------------------- ### Initialize Tokenizer Manager Source: https://github.com/johnnyz93/oai-compatible-copilot/blob/main/_autodocs/api-reference/utilities.md Initializes the TokenizerManager with the extension path. This is a required setup step before using other TokenizerManager methods. It supports OpenAI GPT models and provides fallback estimation for others. ```typescript TokenizerManager.initialize(extensionPath: string): void ``` -------------------------------- ### Example Anthropic API Output Source: https://github.com/johnnyz93/oai-compatible-copilot/blob/main/_autodocs/api-reference/anthropicapi.md An example of the expected output format from the Anthropic API, demonstrating text and thinking blocks within user and assistant messages, including cache control. ```typescript [ { role: "user", content: [ { type: "text", text: "Hello!", cache_control: { type: "ephemeral" } } ] }, { role: "assistant", content: [ { type: "thinking", thinking: "Let me respond..." }, { type: "text", text: "Hi there!" } ] } ] ``` -------------------------------- ### Set Debug Logging Level Source: https://github.com/johnnyz93/oai-compatible-copilot/blob/main/_autodocs/configuration.md Configure the debug logging level for the extension. Logs are stored in `~/.copilot/oaicopilot/logs/` and are automatically deleted after 7 days. This example enables detailed debug logging. ```json { "oaicopilot.logLevel": "debug" } ``` -------------------------------- ### Configuration Flow Diagram Source: https://github.com/johnnyz93/oai-compatible-copilot/blob/main/_autodocs/INDEX.md Illustrates the sequence of events from package.json settings to user model selection and request execution. ```text Package.json contributes settings ↓ extension.ts reads from vscode.workspace.getConfiguration() ↓ normalizeUserModels() validates and normalizes oaicopilot.models[] ↓ prepareLanguageModelChatInformation() formats for Copilot ↓ User selects model in Copilot Chat ↓ provider.provideLanguageModelChatResponse() executes request ↓ API-specific implementation handles communication ``` -------------------------------- ### Prepare Request Headers Source: https://github.com/johnnyz93/oai-compatible-copilot/blob/main/_autodocs/api-reference/openaiapi.md Demonstrates how to prepare request headers using `CommonApi.prepareHeaders` for the OpenAI API, including authorization, content type, user agent, and custom headers. ```APIDOC ## Prepare Request Headers Headers are prepared by `CommonApi.prepareHeaders()`: ```typescript static prepareHeaders( apiKey: string, apiMode: HFApiMode, customHeaders?: Record ): Record ``` For `openai` mode: ```javascript { "Authorization": "Bearer {apiKey}", "Content-Type": "application/json", "User-Agent": "VSCode-OAI-Compatible/{version}", ...customHeaders } ``` ``` -------------------------------- ### Run Build, Test, and Lint Commands Source: https://github.com/johnnyz93/oai-compatible-copilot/blob/main/AGENTS.md Execute these npm scripts for common development tasks like compiling, watching, linting, formatting, testing, packaging, and downloading API types. ```bash npm run compile # Build TypeScript ``` ```bash npm run watch # Build in watch mode ``` ```bash npm run lint # Run ESLint ``` ```bash npm run format # Format with Prettier ``` ```bash npm run test # Run tests (compile + vscode-test) ``` ```bash npm run build # Package extension to .vsix ``` ```bash npm run download-api # Download VS Code proposed API types (required after vscode.d.ts updates) ``` -------------------------------- ### Get Configured Reasoning Effort Source: https://github.com/johnnyz93/oai-compatible-copilot/blob/main/_autodocs/EXPORTS.md Retrieves the configured reasoning effort, with an optional fallback value. ```typescript export function getConfiguredReasoningEffort( options: vscode.ProvideLanguageModelChatResponseOptions | undefined, fallback?: ReasoningEffortPickerValue ): ReasoningEffortPickerValue ``` -------------------------------- ### Configure Multi-Provider Models Source: https://github.com/johnnyz93/oai-compatible-copilot/blob/main/_autodocs/api-reference/modelinfo.md Set up multiple models from different providers within a single configuration. This requires setting individual API keys for each provider. ```json { "oaicopilot.models": [ { "id": "gpt-4", "owned_by": "openai" }, { "id": "claude-3-5-sonnet", "owned_by": "anthropic" } ] } ``` -------------------------------- ### Enable Thinking (Zai/Qwen) Source: https://github.com/johnnyz93/oai-compatible-copilot/blob/main/_autodocs/api-reference/modelinfo.md Configure `thinking: { "type": "enabled" }` for Zai/Qwen models to enable their thinking capabilities. ```json { "id": "glm-4.6", "owned_by": "zai", "thinking": { "type": "enabled" } } ``` -------------------------------- ### Get Git Diff Utility Source: https://github.com/johnnyz93/oai-compatible-copilot/blob/main/_autodocs/api-reference/gitcommit.md Retrieves the unified diff of staged and unstaged changes for a given repository path. Executes the 'git diff' command. ```typescript export async function getGitDiff(repoPath: string): Promise ``` -------------------------------- ### Configure Ollama Local Instance Source: https://github.com/johnnyz93/oai-compatible-copilot/blob/main/_autodocs/api-reference/ollamaapi.md Set up the API to connect to a local Ollama instance by specifying the base URL and API mode. An API key can be any string or omitted for local instances without authentication. ```json { "id": "llama2", "owned_by": "ollama", "baseUrl": "http://localhost:11434", "apiMode": "ollama" } ``` -------------------------------- ### Custom Commit Message Prompt Source: https://github.com/johnnyz93/oai-compatible-copilot/blob/main/_autodocs/api-reference/gitcommit.md Define a custom system prompt to guide the commit message generation. This allows for specific formatting rules and instructions. ```typescript "oaicopilot.commitMessagePrompt": string ``` ```json { "oaicopilot.commitMessagePrompt": "You are a git commit message generator. Follow these rules:\n1. Use imperative mood ('add' not 'added')\n2. Start with a verb\n3. Keep first line under 50 chars\n4. Add detailed description if needed\n5. Reference issues like 'Fixes #123'" } ``` -------------------------------- ### Anthropic API Configuration Source: https://github.com/johnnyz93/oai-compatible-copilot/blob/main/_autodocs/api-reference/anthropicapi.md Example JSON configuration for an Anthropic API endpoint, specifying model ID, base URL, API mode, token limits, and other parameters. ```json { "id": "claude-3-5-sonnet-20241022", "owned_by": "anthropic", "baseUrl": "https://api.anthropic.com", "apiMode": "anthropic", "max_tokens": 4096, "temperature": 1.0, "cache_control": true, "vision": true, "headers": { "anthropic-beta": "prompt-caching-2024-07-16" } } ``` -------------------------------- ### Open Configuration Panel Source: https://github.com/johnnyz93/oai-compatible-copilot/blob/main/_autodocs/EXPORTS.md Provides functionality to open the configuration panel for the extension. Requires the extension URI and secret storage. ```typescript export class ConfigViewPanel { static openPanel(extensionUri: vscode.Uri, secrets: vscode.SecretStorage): void; } ``` -------------------------------- ### Generate Commit Message for Refactoring Source: https://github.com/johnnyz93/oai-compatible-copilot/blob/main/_autodocs/api-reference/gitcommit.md Example of generating a commit message for a refactoring task. The Git diff indicates changes related to extracting validation logic into a new module. ```git diff --git a/src/utils.ts ... (extracting validation logic) diff --git a/src/validator.ts ... (new validation module) ``` ```text Refactor: extract validation logic into separate module Extracts validation utilities from utils.ts into a dedicated validator.ts module for better organization and testability. ``` -------------------------------- ### Generate Commit Message for Bug Fix Source: https://github.com/johnnyz93/oai-compatible-copilot/blob/main/_autodocs/api-reference/gitcommit.md Example of generating a commit message for a bug fix. The diff highlights a change in src/parser.ts where an error is now thrown instead of returning null. ```git diff --git a/src/parser.ts b/src/parser.ts @@ -120,7 +120,7 @@ function parseJSON(input: string): object { try { return JSON.parse(input); } catch (error) { - return null; // BUG: Returns null instead of throwing + throw new Error(`JSON parse failed: ${(error as Error).message}`); } } ``` ```text Fix: properly throw error instead of silently returning null on JSON parse failure ``` -------------------------------- ### System Prompt for Commit Message Generation Source: https://github.com/johnnyz93/oai-compatible-copilot/blob/main/_autodocs/api-reference/gitcommit.md This system prompt guides the AI to generate informative git commit messages in a conventional format, skipping preambles and removing backticks. ```text You are a helpful assistant that generates informative git commit messages based on git diffs output. Skip preamble and remove all backticks surrounding the commit message. Based on the provided git diff, generate a conventional format commit message. ``` -------------------------------- ### OpenaiApi Constructor Source: https://github.com/johnnyz93/oai-compatible-copilot/blob/main/_autodocs/api-reference/openaiapi.md Initializes a new instance of the OpenaiApi class. ```APIDOC ## OpenaiApi Constructor ### Description Initializes a new instance of the OpenaiApi class. ### Parameters #### Path Parameters - **modelId** (string) - Required - The model ID for logging purposes ``` -------------------------------- ### ConfigViewPanel Class Source: https://github.com/johnnyz93/oai-compatible-copilot/blob/main/_autodocs/EXPORTS.md Manages the opening and display of the configuration UI panel. ```APIDOC ## ConfigViewPanel ### Description Manages the opening and display of the configuration UI panel. ### Methods - `static openPanel(extensionUri: vscode.Uri, secrets: vscode.SecretStorage)`: Opens the configuration panel. ``` -------------------------------- ### Generate Commit Message for Feature Source: https://github.com/johnnyz93/oai-compatible-copilot/blob/main/_autodocs/api-reference/gitcommit.md Example of generating a commit message for a new feature based on a Git diff. The diff shows changes to the src/auth.ts file, including added logging. ```git diff --git a/src/auth.ts b/src/auth.ts index abc..def 100644 --- a/src/auth.ts +++ b/src/auth.ts @@ -45,6 +45,8 @@ export function authenticate(credentials: Credentials): boolean { const hash = sha256(credentials.password); const stored = database.getPasswordHash(credentials.username); + logger.info(`Login attempt for user: ${credentials.username}`); + return hash === stored; } ``` ```text Add logging for authentication attempts ``` -------------------------------- ### Prepare Headers for Ollama API Source: https://github.com/johnnyz93/oai-compatible-copilot/blob/main/_autodocs/api-reference/ollamaapi.md Construct the necessary headers for the `ollama` API mode, including Authorization, Content-Type, and User-Agent. A default API key is used if none is set. ```javascript { "Authorization": "Bearer {apiKey}", // Even if apiKey is "ollama" "Content-Type": "application/json", "User-Agent": "VSCode-OAI-Compatible/{version}", ...customHeaders } ``` -------------------------------- ### Configure Local Ollama Instance Source: https://github.com/johnnyz93/oai-compatible-copilot/blob/main/_autodocs/api-reference/ollamaapi.md Use this configuration for connecting to a local Ollama server. Adjust `id` and `baseUrl` as needed. The `keep_alive` setting controls how long the model stays loaded in memory. ```json { "id": "mistral:7b", "owned_by": "ollama", "baseUrl": "http://localhost:11434", "apiMode": "ollama", "max_tokens": 2048, "temperature": 0.7, "extra": { "keep_alive": "30m" } } ``` -------------------------------- ### Gemini API Vision Support Request Source: https://github.com/johnnyz93/oai-compatible-copilot/blob/main/_autodocs/api-reference/geminiapi.md Example of how to structure a request to the Gemini API for vision support, embedding images as inline data with specified MIME types and base64 encoded data. ```typescript { role: "user", parts: [ { text: "Analyze this image" }, { inlineData: { mimeType: "image/jpeg", data: "base64_encoded_data" } } ] } ``` -------------------------------- ### Initialize Logger Source: https://github.com/johnnyz93/oai-compatible-copilot/blob/main/_autodocs/api-reference/utilities.md Initializes the logger, configuring the log level and ensuring the log directory exists. This is typically called during extension activation. ```typescript logger.init(): void ``` -------------------------------- ### Model and Configuration Interfaces and Functions Source: https://github.com/johnnyz93/oai-compatible-copilot/blob/main/_autodocs/EXPORTS.md Interfaces and functions for parsing model IDs, normalizing user models, getting model provider IDs, creating retry configurations, executing functions with retries, and safely parsing JSON objects. ```typescript export interface ParsedModelId { baseId: string; configId?: string; } export function parseModelId(modelId: string): ParsedModelId export function normalizeUserModels(models: unknown): HFModelItem[]; export function getModelProviderId(model: unknown): string export function createRetryConfig(): RetryConfig export async function executeWithRetry( fn: () => Promise, config: RetryConfig ): Promise export function tryParseJSONObject(json: string): { ok: true; value: Record } | { ok: false; error: Error } ``` -------------------------------- ### Initialize OpenAI API Client Source: https://github.com/johnnyz93/oai-compatible-copilot/blob/main/_autodocs/api-reference/gitcommit.md Instantiate the OpenAI API client for model interactions. Configure request parameters like model ID, messages, temperature, max tokens, and streaming. ```typescript const openaiApi = new OpenaiApi(modelId); const requestBody = { model: modelId, messages: convertedMessages, temperature: 0, max_tokens: 500, stream: true }; // Send to /chat/completions endpoint ``` -------------------------------- ### Initialize Anthropic API Client Source: https://github.com/johnnyz93/oai-compatible-copilot/blob/main/_autodocs/api-reference/gitcommit.md Instantiate the Anthropic API client. Configure the request body with model ID, messages, max tokens, system prompt, and streaming. ```typescript const anthropicApi = new AnthropicApi(modelId); const requestBody = { model: modelId, messages: convertedMessages, max_tokens: 500, system: systemPrompt, stream: true }; // Send to /v1/messages endpoint ``` -------------------------------- ### Get Model Provider ID Source: https://github.com/johnnyz93/oai-compatible-copilot/blob/main/_autodocs/api-reference/utilities.md Extracts the provider ID from a model object by checking a predefined list of potential field names ('owned_by', 'provide', 'provider', 'ownedBy', 'owner', 'vendor'). Returns an empty string if no provider ID is found. ```typescript export function getModelProviderId(model: unknown): string ``` ```typescript getModelProviderId({ id: "gpt-4", owned_by: "openai" }) // "openai" getModelProviderId({ id: "claude", provide: "anthropic" }) // "anthropic" getModelProviderId({ id: "model" }) // "" ``` -------------------------------- ### File Organization Structure Source: https://github.com/johnnyz93/oai-compatible-copilot/blob/main/_autodocs/INDEX.md This snippet displays the directory and file structure of the OAI Compatible Copilot extension. It helps understand the project's organization and the location of different modules. ```tree src/ ├── extension.ts # Entry point, command registration ├── provider.ts # Main LanguageModelChatProvider ├── types.ts # Type definitions ├── utils.ts # Utility functions ├── modelConfiguration.ts # Model config helpers ├── provideModel.ts # Model information preparation ├── provideToken.ts # Token counting ├── commonApi.ts # Abstract base class ├── logger.ts # Logging system ├── statusBar.ts # Status bar updates ├── versionManager.ts # Version tracking ├── openai/ │ ├── openaiApi.ts # OpenAI Chat Completions │ ├── openaiResponsesApi.ts # OpenAI Responses API │ └── openaiTypes.ts # OpenAI type definitions ├── anthropic/ │ ├── anthropicApi.ts # Anthropic Messages API │ └── anthropicTypes.ts # Anthropic type definitions ├── gemini/ │ ├── geminiApi.ts # Gemini API │ └── geminiTypes.ts # Gemini type definitions ├── ollama/ │ ├── ollamaApi.ts # Ollama API │ └── ollamaTypes.ts # Ollama type definitions ├── gitCommit/ │ ├── commitMessageGenerator.ts # Commit generation logic │ └── gitUtils.ts # Git utilities ├── tokenizer/ │ ├── tokenizerManager.ts # Token counting │ └── imageUtils.ts # Image handling ├── views/ │ └── configView.ts # Configuration UI panel └── test/ └── modelConfiguration.test.ts # Unit tests ``` -------------------------------- ### oaicopilot.generateGitCommitMessage Source: https://github.com/johnnyz93/oai-compatible-copilot/blob/main/_autodocs/api-reference/gitcommit.md Main command to generate a commit message for repository changes. It finds repositories with uncommitted changes, prompts for selection if multiple exist, gets the git diff, sends it to the configured model, and inserts the generated message into the commit input. ```APIDOC ## oaicopilot.generateGitCommitMessage ### Description Main command to generate commit message for repository changes. ### Method Signature ```typescript export async function generateCommitMsg(secrets: vscode.SecretStorage, scm?: vscode.SourceControl): Promise ``` ### Parameters #### Path Parameters - **secrets** (vscode.SecretStorage) - Required - VS Code secret storage for API keys - **scm** (vscode.SourceControl | undefined) - Optional - Optional source control (specified repository) ### Invocation - From Source Control panel button (wand icon) - From Command Palette: "Generate Commit Message with OAICopilot" ### Behavior 1. Finds repositories with uncommitted changes 2. If multiple repos, prompts user to select 3. Gets git diff from selected repository 4. Sends diff to configured model 5. Inserts generated message in commit input ``` -------------------------------- ### GeminiApi Implementation Source: https://github.com/johnnyz93/oai-compatible-copilot/blob/main/_autodocs/SUMMARY.txt Details the GeminiApi implementation, including Gemini-specific message formats, helper functions for URL building and model path normalization, and support for vision and tools. ```APIDOC ## GeminiApi ### Description Implementation of the CommonApi for interacting with Google Gemini API. ### Features - **Gemini-specific Message Format**: Adapts messages to Gemini's format. - **Helper Functions**: Includes `buildGeminiGenerateContentUrl`, `normalizeGeminiModelPath`, and `stripUnsupportedGeminiSchemaKeys`. - **Vision Support**: Supports image inputs for multimodal capabilities. - **Tool Support**: Enables the use of tools with the Gemini API. - **Thinking Support**: Facilitates thinking processes in generated content. ### Configuration Examples Provides examples of how to configure and use the Gemini API. ``` -------------------------------- ### Configure Extended Reasoning (OpenRouter) Source: https://github.com/johnnyz93/oai-compatible-copilot/blob/main/_autodocs/api-reference/modelinfo.md Set `reasoning: { "effort": "high", "max_tokens": 8000 }` for OpenRouter models to enable high-effort reasoning with a specified token limit. ```json { "id": "r1-distill", "owned_by": "openrouter", "reasoning": { "effort": "high", "max_tokens": 8000 } } ``` -------------------------------- ### Define Model Variants with Different Configurations Source: https://github.com/johnnyz93/oai-compatible-copilot/blob/main/_autodocs/api-reference/modelinfo.md Configure the same model with different settings by assigning unique `configId` values. This allows for distinct behaviors like fast vs. thorough responses. ```json { "oaicopilot.models": [ { "id": "glm-4.6", "configId": "fast", "owned_by": "zai", "temperature": 0, "thinking": { "type": "disabled" } }, { "id": "glm-4.6", "configId": "thorough", "owned_by": "zai", "temperature": 1.0, "thinking": { "type": "enabled" }, "thinking_budget": 4000 } ] } ``` -------------------------------- ### Configure OpenAI Responses for Thinking Block Source: https://github.com/johnnyz93/oai-compatible-copilot/blob/main/README.md Enable Copilot to show a 'Thinking' block by setting 'apiMode' to 'openai-responses' and specifying the reasoning summary mode in the 'extra' field. This requires provider and model support. ```json { "id": "gpt-4o-mini", "owned_by": "openai", "baseUrl": "https://api.openai.com/v1", "apiMode": "openai-responses", "reasoning_effort": "high", "extra": { "reasoning": { "summary": "detailed" } } } ``` -------------------------------- ### Extension Activation Functions Source: https://github.com/johnnyz93/oai-compatible-copilot/blob/main/_autodocs/EXPORTS.md These functions are the entry points for activating and deactivating the extension. They are registered in `package.json#main`. ```typescript export function activate(context: vscode.ExtensionContext): void export function deactivate(): void ``` -------------------------------- ### Configure Vision-Capable Ollama Model Source: https://github.com/johnnyz93/oai-compatible-copilot/blob/main/_autodocs/api-reference/ollamaapi.md Set up a configuration for a vision-capable model. Ensure the `vision` parameter is set to `true`. The `keep_alive` setting can be adjusted based on usage patterns. ```json { "id": "llava:34b", "owned_by": "ollama", "baseUrl": "http://localhost:11434", "apiMode": "ollama", "vision": true, "max_tokens": 4096, "extra": { "keep_alive": "1h" } } ``` -------------------------------- ### Prepare Headers for Gemini API Source: https://github.com/johnnyz93/oai-compatible-copilot/blob/main/_autodocs/api-reference/geminiapi.md Construct the necessary headers for requests to the Gemini API. Ensure to include the API key, content type, and a user agent. ```javascript { "x-goog-api-key": "{apiKey}", "Content-Type": "application/json", "User-Agent": "VSCode-OAI-Compatible/{version}", ...customHeaders } ``` -------------------------------- ### Enable Raw Prompt Mode Source: https://github.com/johnnyz93/oai-compatible-copilot/blob/main/_autodocs/api-reference/ollamaapi.md Bypass Ollama's system prompt templating by setting `raw` to `true` in the `extra` configuration. This allows messages to be used as-is. ```json { "extra": { "raw": true // Disable prompt template, use messages as-is } } ``` -------------------------------- ### createReasoningEffortConfigurationSchema Source: https://github.com/johnnyz93/oai-compatible-copilot/blob/main/_autodocs/api-reference/modelinfo.md Creates a configuration schema that can be used to generate a reasoning effort picker for models, allowing users to select a desired reasoning budget. ```APIDOC ## createReasoningEffortConfigurationSchema ### Description Creates a configuration schema for models with reasoning effort picker. ### Signature ```typescript export function createReasoningEffortConfigurationSchema( defaultValue: ReasoningEffortPickerValue ): { properties: { reasoningEffort: {...} } } ``` ### Parameters - **defaultValue** (`ReasoningEffortPickerValue`) - Required - Default reasoning effort level. ### Returns - `{ properties: { reasoningEffort: {...} } }` - Schema object for VS Code configuration picker. ### Values - `"minimal"` - Smallest reasoning budget - `"low"` - Low reasoning budget - `"medium"` - Balanced (default) - `"high"` - High reasoning budget - `"xhigh"` - Very high reasoning budget - `"max"` - Maximum reasoning budget ### Example ```typescript const schema = createReasoningEffortConfigurationSchema("high"); // Schema can be attached to model for Copilot reasoning effort picker ``` ``` -------------------------------- ### Prepare Language Model Chat Information Source: https://github.com/johnnyz93/oai-compatible-copilot/blob/main/_autodocs/EXPORTS.md Asynchronously prepares information for language model chat. Requires options, a cancellation token, and secret storage. ```typescript export async function prepareLanguageModelChatInformation( options: { silent: boolean }, token: CancellationToken, secrets: vscode.SecretStorage ): Promise ``` -------------------------------- ### OllamaApi Implementation Source: https://github.com/johnnyz93/oai-compatible-copilot/blob/main/_autodocs/SUMMARY.txt Documentation for the OllamaApi implementation, covering message conversion, request preparation, streaming response processing, and support for local/remote instances and vision. ```APIDOC ## OllamaApi ### Description Implementation of the CommonApi for interacting with Ollama API. ### Features - **Message Conversion**: Converts messages to Ollama's format. - **Request Preparation**: Prepares requests for Ollama endpoints. - **Streaming Response Processing**: Handles streaming responses from Ollama. - **Local and Remote Instance Support**: Connects to both local and remote Ollama instances. - **Model Parameters**: Manages model parameters, including `keep_alive`. - **Vision Support**: Supports vision capabilities. - **Tool Support**: Enables tool usage with Ollama models. ``` -------------------------------- ### Initialize Status Bar Source: https://github.com/johnnyz93/oai-compatible-copilot/blob/main/_autodocs/EXPORTS.md Handles the initialization and updating of the status bar in the VS Code extension. Requires the extension context and a StatusBarItem. ```typescript export function initStatusBar(context: vscode.ExtensionContext): vscode.StatusBarItem ``` ```typescript export function updateContextStatusBar( messages: readonly LanguageModelChatRequestMessage[], tools: readonly vscode.LanguageModelTool[], model: vscode.LanguageModelChatInformation, statusBarItem: vscode.StatusBarItem, modelConfig: { includeReasoningInRequest: boolean } ): void ``` -------------------------------- ### GeminiApi Constructor Source: https://github.com/johnnyz93/oai-compatible-copilot/blob/main/_autodocs/api-reference/geminiapi.md Initializes the GeminiApi with a model ID for logging purposes. ```APIDOC ## constructor(modelId: string) ### Description Initializes the GeminiApi with a model ID. ### Parameters #### Path Parameters - **modelId** (string) - Required - The model ID for logging purposes ``` -------------------------------- ### Configure Remote Ollama Instance with Authentication Source: https://github.com/johnnyz93/oai-compatible-copilot/blob/main/_autodocs/api-reference/ollamaapi.md Configure access to a remote Ollama instance, including authentication. Replace `your-token` with your actual API token. `max_tokens` and `temperature` can be tuned for different response characteristics. ```json { "id": "llama2:13b", "owned_by": "ollama-remote", "baseUrl": "https://ollama.example.com", "apiMode": "ollama", "max_tokens": 4096, "temperature": 0.5, "headers": { "Authorization": "Bearer your-token" } } ``` -------------------------------- ### Configure OAICopilot Settings Source: https://github.com/johnnyz93/oai-compatible-copilot/blob/main/README.md Configure the base URL and models for the OAI Compatible Provider in VS Code settings. Ensure your API key is valid and models are correctly specified. ```json "oaicopilot.baseUrl": "https://api-inference.modelscope.cn/v1", "oaicopilot.models": [ { "id": "Qwen/Qwen3-Coder-480B-A35B-Instruct", "owned_by": "modelscope", "context_length": 256000, "max_tokens": 8192, "temperature": 0, "top_p": 1 } ] ``` -------------------------------- ### Tool Support Source: https://github.com/johnnyz93/oai-compatible-copilot/blob/main/_autodocs/api-reference/openaiapi.md Details the conversion of VS Code tools to OpenAI format, including function definitions and tool call modes. ```APIDOC ## Tool Support Tools are converted from VS Code format to OpenAI format: ```typescript tools: [ { type: "function", function: { name: "read_file", description: "Read a file from disk", parameters: { type: "object", properties: { path: { type: "string", description: "File path" } }, required: ["path"] } } } ] ``` **Tool Call Mode**: - Default: `"auto"` - model decides whether to call tools - Required: `{ type: "function", function: { name: "tool_name" } }` - model must call specific tool ``` -------------------------------- ### prepareRequestBody Method Source: https://github.com/johnnyz93/oai-compatible-copilot/blob/main/_autodocs/api-reference/commonapi.md Constructs the request body for the specific API, applying model configuration and VS Code options. This is an abstract method that must be implemented by subclasses. ```APIDOC ## prepareRequestBody ### Description Constructs the request body for the specific API, applying model configuration and VS Code options. ### Method Signature ```typescript abstract prepareRequestBody( rb: TRequestBody, um: HFModelItem | undefined, options?: ProvideLanguageModelChatResponseOptions ): TRequestBody ``` ### Parameters #### Path Parameters - **rb** (TRequestBody) - Required - Initial request body - **um** (HFModelItem | undefined) - Required - Model configuration from settings - **options** (ProvideLanguageModelChatResponseOptions | undefined) - Optional - Request options from VS Code ### Returns Finalized request body ready to send to the API. ``` -------------------------------- ### Initialize Logger Source: https://github.com/johnnyz93/oai-compatible-copilot/blob/main/_autodocs/EXPORTS.md Defines the interface for the logging utility. Use this to initialize and manage application logs. ```typescript export const logger: { init(): void; reloadConfig(): void; debug(tag: string, data: Record): void; info(tag: string, data: Record): void; warn(tag: string, data: Record): void; error(tag: string, data: Record): void; sanitizeHeaders(headers: Record): Record; sanitizeData(data: Record): Record; } ``` -------------------------------- ### OpenaiApi Implementation Source: https://github.com/johnnyz93/oai-compatible-copilot/blob/main/_autodocs/SUMMARY.txt Details the OpenaiApi implementation, covering message conversion to OpenAI format, request body preparation, streaming response processing, and support for vision and tools. ```APIDOC ## OpenaiApi ### Description Implementation of the CommonApi for interacting with OpenAI's API. ### Features - **Message Conversion**: Handles conversion to OpenAI's message format. - **Request Body Preparation**: Prepares request bodies according to OpenAI specifications. - **Streaming Response Processing**: Manages streaming responses from the OpenAI API. - **Vision Support**: Includes support for vision-based inputs. - **Tool Support**: Enables the use of tools with the OpenAI API. - **Reasoning & Thinking Support**: Facilitates reasoning and thinking capabilities. ### API Compatibility Matrix Provides a matrix detailing compatibility with various OpenAI API versions and features. ``` -------------------------------- ### Initialize Ollama API Client Source: https://github.com/johnnyz93/oai-compatible-copilot/blob/main/_autodocs/api-reference/gitcommit.md Instantiate the Ollama API client. Configure the request body with model ID, messages, and streaming. This can be used for local or remote Ollama instances. ```typescript const ollamaApi = new OllamaApi(modelId); const requestBody = { model: modelId, messages: convertedMessages, stream: true }; // Send to /api/chat endpoint (local or remote) ``` -------------------------------- ### Configure Multiple API Modes Source: https://github.com/johnnyz93/oai-compatible-copilot/blob/main/README.md Use this configuration to set up different API modes for various models. The `apiMode` parameter specifies the protocol for each model, defaulting to 'openai' if not provided. ```json "oaicopilot.models": [ { "id": "GLM-4.6", "owned_by": "modelscope", }, { "id": "llama3.2", "owned_by": "ollama", "baseUrl": "http://localhost:11434", "apiMode": "ollama" }, { "id": "claude-3-5-sonnet-20241022", "owned_by": "anthropic", "baseUrl": "https://api.anthropic.com", "apiMode": "anthropic" } ] ``` -------------------------------- ### Instantiate HuggingFaceChatModelProvider Source: https://github.com/johnnyz93/oai-compatible-copilot/blob/main/_autodocs/api-reference/provider.md Demonstrates how to create an instance of the HuggingFaceChatModelProvider. Requires VS Code's SecretStorage and StatusBarItem. ```typescript export class HuggingFaceChatModelProvider implements LanguageModelChatProvider { constructor(secrets: vscode.SecretStorage, statusBarItem: vscode.StatusBarItem) } ``` -------------------------------- ### Initialize OpenAI Responses API Client Source: https://github.com/johnnyz93/oai-compatible-copilot/blob/main/_autodocs/api-reference/gitcommit.md Instantiate the OpenAI Responses API client. This client uses the /responses endpoint and is designed to handle streaming responses from the new API. ```typescript const responsesApi = new OpenaiResponsesApi(modelId); // Uses /responses endpoint instead // Handles streaming responses from new API ``` -------------------------------- ### Configure Ollama for Vision Support Source: https://github.com/johnnyz93/oai-compatible-copilot/blob/main/_autodocs/api-reference/ollamaapi.md Enable vision capabilities for compatible Ollama models by setting the `vision` field to `true`. Images are sent in the `images` field as base64. ```json { "id": "llava:7b", "owned_by": "ollama", "vision": true } ``` -------------------------------- ### Initialize Tokenizer Manager Source: https://github.com/johnnyz93/oai-compatible-copilot/blob/main/_autodocs/EXPORTS.md Manages tokenization for language models. Use this to initialize the manager and count tokens for text or chat messages. ```typescript export class TokenizerManager { static initialize(extensionPath: string): void; static countTokens(text: string, modelFamily?: string): number; static countMessageTokens(message: LanguageModelChatRequestMessage, modelFamily?: string): number; } ``` -------------------------------- ### Utilities Module Source: https://github.com/johnnyz93/oai-compatible-copilot/blob/main/_autodocs/SUMMARY.txt Provides utility functions for message and tool conversion, image handling, model configuration, retries, JSON parsing, and more. ```APIDOC ## Utilities Module ### Core Utilities - **Message & Tool Conversion**: Functions like `mapRole()`, `convertToolsToOpenAI()`. - **Image Utilities**: Functions for handling image data. - **Model Configuration Utilities**: Helpers for managing model settings. - **Retry & Delay Utilities**: Implements retry logic and delays. - **JSON Parsing Utilities**: For parsing JSON data. - **Tool Result Utilities**: For processing tool outputs. - **Logger Utilities**: For logging information. - **Tokenizer Utilities**: For tokenization tasks. ``` -------------------------------- ### Provider Stack Diagram Source: https://github.com/johnnyz93/oai-compatible-copilot/blob/main/_autodocs/INDEX.md Illustrates the flow of requests from VS Code Copilot Chat through the extension's provider stack to external APIs. ```text VS Code Copilot Chat ↓ HuggingFaceChatModelProvider ↓ API-Specific Implementations ├── OpenaiApi (/chat/completions) ├── OpenaiResponsesApi (/responses) ├── AnthropicApi (/v1/messages) ├── GeminiApi (/v1beta/models/{model}:streamGenerateContent) └── OllamaApi (/api/chat) ↓ External APIs ``` -------------------------------- ### Prepare Language Model Chat Information Source: https://github.com/johnnyz93/oai-compatible-copilot/blob/main/_autodocs/api-reference/modelinfo.md Retrieves and prepares model information for VS Code Copilot from extension configuration. Use this function to populate the Copilot model picker with available language models. ```typescript export async function prepareLanguageModelChatInformation( options: { silent: boolean }, token: CancellationToken, secrets: vscode.SecretStorage ): Promise ``` ```typescript const models = await prepareLanguageModelChatInformation( { silent: false }, cancellationToken, secrets ); console.log(`Prepared ${models.length} models for Copilot`); ```