mirror of
https://github.com/HackTricks-wiki/hacktricks-cloud.git
synced 2026-07-28 14:47:17 -07:00
f
This commit is contained in:
@@ -10,6 +10,7 @@ import tiktoken
|
|||||||
import concurrent.futures
|
import concurrent.futures
|
||||||
from tqdm import tqdm #pip3 install tqdm
|
from tqdm import tqdm #pip3 install tqdm
|
||||||
import traceback
|
import traceback
|
||||||
|
import re
|
||||||
|
|
||||||
|
|
||||||
MASTER_BRANCH = "master"
|
MASTER_BRANCH = "master"
|
||||||
@@ -85,6 +86,10 @@ def _get_encoding_for_model(model: str):
|
|||||||
print(f"Tokenizer for model {model} not found. Falling back to {FINAL_TOKENIZER_FALLBACK}.")
|
print(f"Tokenizer for model {model} not found. Falling back to {FINAL_TOKENIZER_FALLBACK}.")
|
||||||
return tiktoken.get_encoding(FINAL_TOKENIZER_FALLBACK)
|
return tiktoken.get_encoding(FINAL_TOKENIZER_FALLBACK)
|
||||||
|
|
||||||
|
def _fix_translated_shortcodes(text: str) -> str:
|
||||||
|
"""Keep mdBook shortcode attribute names valid after translation."""
|
||||||
|
return re.sub(r'(\{\{#tab\s+)(?!name=)[^=\s}]+=', r'\1name=', text)
|
||||||
|
|
||||||
def reportTokens(prompt, model):
|
def reportTokens(prompt, model):
|
||||||
encoding = _get_encoding_for_model(model)
|
encoding = _get_encoding_for_model(model)
|
||||||
# print number of tokens in light gray, with first 50 characters of prompt in green. if truncated, show that it is truncated
|
# print number of tokens in light gray, with first 50 characters of prompt in green. if truncated, show that it is truncated
|
||||||
@@ -263,6 +268,7 @@ Also don't add any extra stuff in your response that is not part of the translat
|
|||||||
response_message = response_message.replace("bypassy", "bypasses") # PL translations translates that from time to time
|
response_message = response_message.replace("bypassy", "bypasses") # PL translations translates that from time to time
|
||||||
response_message = response_message.replace("Bypassy", "Bypasses")
|
response_message = response_message.replace("Bypassy", "Bypasses")
|
||||||
response_message = response_message.replace("-privec.md", "-privesc.md") # PL translations translates that from time to time
|
response_message = response_message.replace("-privec.md", "-privesc.md") # PL translations translates that from time to time
|
||||||
|
response_message = _fix_translated_shortcodes(response_message)
|
||||||
|
|
||||||
# Sometimes chatgpt modified the number of "#" at the beginning of the text, so we need to fix that. This is specially important for the first line of the MD that mucst have only 1 "#"
|
# Sometimes chatgpt modified the number of "#" at the beginning of the text, so we need to fix that. This is specially important for the first line of the MD that mucst have only 1 "#"
|
||||||
cont2 = 0
|
cont2 = 0
|
||||||
|
|||||||
Reference in New Issue
Block a user