fix: enhance tokenizer and add comprehensive tool support#42
Open
nghyane wants to merge 15 commits intoericc-ch:masterfrom
Open
fix: enhance tokenizer and add comprehensive tool support#42nghyane wants to merge 15 commits intoericc-ch:masterfrom
nghyane wants to merge 15 commits intoericc-ch:masterfrom
Conversation
added 4 commits
June 10, 2025 19:51
- Fix null content handling in getTokenCount (fixes ericc-ch#21) - Add support for tool calls and content parts in token counting - Improve token counting accuracy for different message roles - Add null safety checks for message processing - Handle ContentPart arrays and extract text content properly
- Add tool/function calling support to chat completions (addresses ericc-ch#30) - Enhanced error handling for unsupported tool features - Support for tool choice and tool responses in message types - Better message processing for tool-related content - Add proper TypeScript types for Tool, ToolCall, and ToolChoice - Improve vision capability detection logic - Simplify default parameter syntax in copilotHeaders
- Fix undefined error when accessing selectedModel.capabilities.limits.max_output_tokens - Add proper optional chaining to prevent crashes when model is not found - Ensures graceful handling when state.models or selectedModel is undefined
added 11 commits
June 15, 2025 15:56
- Enhanced tokenizer with better model support and fallback mechanisms - Added comprehensive logging system with global logger - Improved model utilities and streaming capabilities - Added format converter for better data handling - Enhanced error handling and debugging capabilities - Updated dependencies and configurations for better compatibility
- Remove format-converter.ts and replace with format-detector.ts - Enhance format detection logic for better compatibility - Update streaming utilities and chat completion handlers - Improve model handling and route processing - Build new Docker images with multi-architecture support
Owner
|
@fondoger I mean it says in the PR description that this is done by AI. The changes are too much in terms of scope. They changed the package name as well. But still thank you @nghyane , I may be able to use the code as reference. I also appreciate you wanting to contribute to this repo. I've been wanting to try out Claude Code anyway. |
|
@ericc-ch Thank you very much for making this good project. I managed get ClaudeCode work with Github Copilot API use the instructions by #43 (comment).
|
cuipengfei
pushed a commit
to cuipengfei/copilot-api
that referenced
this pull request
Nov 28, 2025
…ns-reasoning fix: handleReasoningOpaqueInToolCalls add isToolBlockOpen judge
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


Overview
This PR addresses several critical issues and adds comprehensive tool support to the copilot-api wrapper.
Issues Fixed
error in getTokenCount > countTokens- Enhanced tokenizer to handle null content and complex message typesTool calls don't work with Claude models- Added comprehensive tool/function calling supportToken counting logic- Better token counting accuracy for different message rolesChanges Made
1. Enhanced Tokenizer (
src/lib/tokenizer.ts)message.contentis null (common in tool call messages)tool,assistant,user, andsystemmessage roles correctly2. Comprehensive Tool Support (
src/services/copilot/create-chat-completions.ts)tools,tool_choice, and tool responsesTool,ToolCall,ToolChoice, andDeltaToolCallinterfacestool_calls,length, andcontent_filterfinish reasons3. Safety Improvements (
src/routes/chat-completions/handler.ts)getTokenCountpayload.messagesis undefined4. Code Quality (
src/lib/api-config.ts)copilotHeadersTesting
The changes have been tested with:
Backward Compatibility
✅ Fully backward compatible - All existing functionality continues to work as before. These changes only enhance existing capabilities and fix edge cases.
Technical Details
Tokenizer Enhancements
The tokenizer now properly handles:
Tool Support
Added complete OpenAI-compatible tool calling:
Impact
This PR significantly enhances the robustness and functionality of copilot-api while maintaining full backward compatibility.
Pull Request opened by Augment Code with guidance from the PR author