Open kgilpin opened 4 days ago
Resolve Token Overflow Issue in Sonnet Mode of GitHub Copilot
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.
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.
js-tiktoken Library Integration:
/snapshot/appmap-js/node_modules/js-tiktoken/dist/lite.cjs:239:13
getEncodingNameForModel
. Add any missing model identifiers causing the "Unknown model" error, if not present, should be verified against expected model listings.Langchain Library Configuration:
/snapshot/appmap-js/node_modules/@langchain/core/dist/utils/tiktoken.cjs:23:59
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:
/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
ChatOpenAI.getNumTokensFromGenerations
and any associated routines are valid and correctly handled by tiktoken library.LLMChain Component Debugging:
/snapshot/appmap-js/node_modules/langchain/dist/chains/llm_chain.cjs:162:37
Error Handling Improvements:
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.