-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
149 additions
and
37 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import sys | ||
import os | ||
import json | ||
|
||
sys.path.insert( | ||
0, os.path.abspath(os.path.join(os.path.dirname(__file__), "..")) | ||
) | ||
from promptex.promptex import Promptex | ||
from promptex.elements import * | ||
from promptex.encoding_strategy import * | ||
|
||
|
||
promptex = Promptex() | ||
|
||
promptex.set_elements( | ||
[ | ||
Instruction("Create an innovative quest for a new fantasy RPG game."), | ||
OutputFormat("Markdown text in English"), | ||
] | ||
) | ||
|
||
text = SimpleTextEncodingStrategy().encode(promptex) | ||
encoding_model_name = "gpt-4" | ||
token_count = promptex.get_token_count( | ||
text=text, encoding_model_name=encoding_model_name | ||
) | ||
stats = promptex.get_stats(text=text, encoding_model_name=encoding_model_name) | ||
|
||
print(f"Token consumption: {token_count}") | ||
|
||
print(f"Stats: {json.dumps(stats, indent=2, ensure_ascii=False)}") |
This file contains 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
This file contains 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
This file contains 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
This file contains 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