You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Resolve Token Overflow Issue in Sonnet Mode of GitHub Copilot
Problem
When running in the Sonnet mode of GitHub Copilot, there is an error occurring related to token overflow recovery. Specifically, the system fails to calculate the number of tokens, leading to fallback on an approximate count. This error is due to an "Unknown model" response when attempting to determine correct encoding for the model in use.
Analysis
The root cause of the problem lies in the incorrect model identifier being utilized when invoking getEncodingNameForModel, resulting in an "Unknown model" error during token count calculations. This error indicates that the current logic does not recognize the model being used or the model identifier provided is not accurately interpreted within the js-tiktoken library.
For the getEncodingNameForModel function to execute correctly, the model identifier, presumably originating from the ChatOpenAI or LLMChain setup, must be mapped correctly to the encoding configurations understood by the library. A lack of proper mapping leads to failure in token calculations essential for managing inputs and outputs of the Sonnet mode.
Ensure a comprehensive mapping of encoding names to models supported by getEncodingNameForModel. Add any missing model identifiers causing the "Unknown model" error, if not present, should be verified against expected model listings.
Revise the function encodingForModel to correctly obtain and pass the model-specific encoding needed for token calculation. This may involve fetching or parsing model details differently to align with encoding names recognized by js-tiktoken.
Adjustment in ChatOpenAI Module:
Location: /snapshot/appmap-js/node_modules/@langchain/core/dist/language_models/base.cjs:205:75 and /snapshot/appmap-js/node_modules/@langchain/openai/dist/chat_models.cjs:1243:64
Review and ensure that the model identifiers being used in ChatOpenAI.getNumTokensFromGenerations and any associated routines are valid and correctly handled by tiktoken library.
Conduct a detailed check on how the chain setups dictate model identifiers, ensuring all chain invocations embed valid model-to-encoding references.
Error Handling Improvements:
Add mechanisms to log better diagnostic messages upon encountering model-related errors, facilitating easier troubleshooting in future instances.
The above steps should enhance the robustness of the Copilot Sonnet mode's token management by aligning model usage with encoding processing libraries, ensuring reliable function performance without fallback on approximations.
The text was updated successfully, but these errors were encountered: