[WIP] feat(llm): migrate to official SDKs and add use_max_completion_tokens…#42
Open
stay-foolish-forever wants to merge 1 commit into
Open
Conversation
… config
Migrate LLM client from custom HTTP implementation to official SDKs:
- github.com/openai/openai-go v3.38.0
- github.com/anthropics/anthropic-sdk-go v1.46.0
Key changes in this branch:
1. SDK Migration (refactor)
- Use SDK native streaming with RawJSON() for format preservation
- ExtraBody support via option.WithJSONSet
- Custom User-Agent headers via option.WithHeader
- Retry logic delegated to SDK (option.WithMaxRetries)
- StreamCompletion now accepts context.Context for cancellation
- URL normalization reversed (strip suffixes, SDKs append them)
- Anthropic tool schema includes required field constraints
- OpenAI streaming: include_usage enabled for token stats
- Remove unused resolveUsage/probePath from usage_resolver.go
2. Token Usage Fix
- Compute totalTokensUsed as input+output instead of relying on
API TotalTokens, which some providers report inconsistently
3. use_max_completion_tokens Config Option (feat)
- Add UseMaxCompletionTokens field to ResolvedEndpoint and ClientConfig
- Support config file field: llm.use_max_completion_tokens
- Support environment variable: OCR_USE_MAX_COMPLETION_TOKENS
- Wire into CLI config set command for user toggle
- Default to max_tokens for backward compatibility
4. Test Coverage
- Comprehensive unit tests for client.go (message conversion,
utility functions, constructors, streaming response handling)
- Unit tests for setConfigValue covering all config keys (30 cases)
5. Documentation
- Add llm.use_max_completion_tokens config key and
OCR_USE_MAX_COMPLETION_TOKENS env var to both EN and ZH READMEs
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.
Description
Migrate LLM client from custom HTTP implementation to official SDKs:
Key changes in this branch:
SDK Migration (refactor)
Token Usage Fix
use_max_completion_tokens Config Option (feat)
Test Coverage
Documentation
Type of Change
How Has This Been Tested?
make testpasses locallyTested using various LLM model provider to ensure it functions correctly
Checklist
go fmt,go vet)Related Issues
Issue #30