-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
🐛 fix knowledge king oom bug #150
base: main
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -2,18 +2,22 @@ package tw.waterballsa.utopia.chatgpt | |||||||||||||||||||
|
||||||||||||||||||||
import com.knuddels.jtokkit.Encodings | ||||||||||||||||||||
import com.knuddels.jtokkit.api.Encoding | ||||||||||||||||||||
import com.knuddels.jtokkit.api.EncodingType | ||||||||||||||||||||
import com.knuddels.jtokkit.api.ModelType | ||||||||||||||||||||
|
||||||||||||||||||||
/** | ||||||||||||||||||||
* use with OpenAI's GPT-3.5 models. | ||||||||||||||||||||
*/ | ||||||||||||||||||||
class JTokkit { | ||||||||||||||||||||
private val registry = Encodings.newDefaultEncodingRegistry() | ||||||||||||||||||||
private val encodingType: EncodingType = EncodingType.CL100K_BASE | ||||||||||||||||||||
companion object { | ||||||||||||||||||||
private val registry = Encodings.newLazyEncodingRegistry() | ||||||||||||||||||||
private lateinit var encoding: Encoding | ||||||||||||||||||||
} | ||||||||||||||||||||
|
||||||||||||||||||||
init { | ||||||||||||||||||||
encoding = registry.getEncodingForModel(ModelType.GPT_3_5_TURBO) | ||||||||||||||||||||
} | ||||||||||||||||||||
|
||||||||||||||||||||
fun measureNumOfTokens(string: String): Int { | ||||||||||||||||||||
val encoding: Encoding = registry.getEncoding(encodingType) | ||||||||||||||||||||
val encoded: List<Int> = encoding.encode(string) | ||||||||||||||||||||
return encoded.size | ||||||||||||||||||||
return encoding.countTokens(string) | ||||||||||||||||||||
} | ||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🤖 OpenAI The
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 已修正 |
||||||||||||||||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Q:這裡不能直接初始化嗎?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
可以直接初始化,已修