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
We are currently implementing a process wherein certain tokens are substituted with alternative tokens in the OpenAI request, and subsequently restored in the response. This method has been adopted as a strategy to minimize the total number of tokens utilized.
To facilitate this process, we are using the SharpToken library. However, we have encountered an issue related to encoding, arising due to the fact that the OpenAI API accepts and returns data in the UTF-8 format, whereas our replacements are causing discrepancies when mapped onto C# UTF-16 strings.
As a temporary solution, we have been extracting the BytePairEncodingCore from GptEncoding using reflection, and invoking the DecodeNative function on it. This has been providing the expected results.
Activity
dmitry-brazhenko commentedon Sep 14, 2024
Hi!
Thanks for reaching out.
Why do you need this?
abdulkareemnalband commentedon Sep 16, 2024
We are currently implementing a process wherein certain tokens are substituted with alternative tokens in the OpenAI request, and subsequently restored in the response. This method has been adopted as a strategy to minimize the total number of tokens utilized.
To facilitate this process, we are using the SharpToken library. However, we have encountered an issue related to encoding, arising due to the fact that the OpenAI API accepts and returns data in the UTF-8 format, whereas our replacements are causing discrepancies when mapped onto C# UTF-16 strings.
As a temporary solution, we have been extracting the
BytePairEncodingCorefromGptEncodingusing reflection, and invoking theDecodeNativefunction on it. This has been providing the expected results.