moved to beta 3.4.0
Browse files- README.md +106 -65
- handlers/json_handler.py +33 -25
- kudasai.py +3 -8
- models/kijiku.py +42 -84
- modules/common/exceptions.py +1 -0
- modules/common/file_ensurer.py +3 -3
- modules/common/toolkit.py +3 -2
- webgui.py +0 -0
README.md
CHANGED
@@ -1,28 +1,16 @@
|
|
1 |
-
---
|
2 |
-
license: gpl-3.0
|
3 |
-
title: Kudasai
|
4 |
-
sdk: gradio
|
5 |
-
emoji: 🈷️
|
6 |
-
python_version: 3.10.0
|
7 |
-
app_file: webgui.py
|
8 |
-
colorFrom: gray
|
9 |
-
colorTo: gray
|
10 |
-
short_description: Japanese-English preprocessor with automated translation.
|
11 |
-
pinned: true
|
12 |
-
---
|
13 |
-
|
14 |
---------------------------------------------------------------------------------------------------------------------------------------------------
|
15 |
**Table of Contents**
|
16 |
|
17 |
- [Notes](#notes)
|
18 |
- [Dependencies](#dependencies)
|
19 |
-
- [Quick Start](#quick-start)
|
20 |
- [Naming Conventions](#naming-conventions)
|
|
|
21 |
- [Kairyou](#kairyou)
|
22 |
- [Kaiseki](#kaiseki)
|
23 |
- [Kijiku](#kijiku)
|
24 |
- [Kijiku Settings](#kijiku-settings)
|
25 |
- [Web GUI](#webgui)
|
|
|
26 |
- [License](#license)
|
27 |
- [Contact](#contact)
|
28 |
|
@@ -31,9 +19,9 @@ pinned: true
|
|
31 |
|
32 |
Windows 10 and Linux Mint are the only tested operating systems, feel free to test on other operating systems and report back to me. I will do my best to fix any issues that arise.
|
33 |
|
34 |
-
Python version: 3.
|
35 |
|
36 |
-
Used to make (Japanese - English) translation easier by preprocessing the Japanese text (optional auto translation using
|
37 |
|
38 |
Preprocessor is sourced from an external package, which I also designed, called [Kairyou](https://github.com/Bikatr7/Kairyou).
|
39 |
|
@@ -56,15 +44,44 @@ kairyou==1.4.0
|
|
56 |
|
57 |
google-generativeai==0.4.0
|
58 |
|
59 |
-
ja_core_news_lg @ https://github.com/explosion/spacy-models/releases/download/ja_core_news_lg-3.7.0/ja_core_news_lg-3.7.0-py3-none-any.whl#sha256=f08eecb4d40523045c9478ce59a67564fd71edd215f32c076fa91dc1f05cc7fd
|
60 |
-
|
61 |
or see requirements.txt
|
62 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
63 |
---------------------------------------------------------------------------------------------------------------------------------------------------
|
64 |
**Quick Start**<a name="quick-start"></a>
|
65 |
|
66 |
Windows is assumed for the rest of this README, but the process should be similar for Linux.
|
67 |
|
|
|
|
|
|
|
|
|
|
|
|
|
68 |
Simply run Kudasai.py, enter a txt file path to the text you wish to translate, and then insert a replacement json file path if you wish to use one. If you do not wish to use a replacement json file, you can simply input a blank space and Kudasai will skip preprocessing and go straight to translation.
|
69 |
|
70 |
Kudasai will offer to index the text, which is useful for finding new names to add to the replacement json file. This is optional and can be skipped.
|
@@ -81,19 +98,6 @@ Follow the prompts from there and you should be good to go, results will be stor
|
|
81 |
|
82 |
If you have any questions, comments, or concerns, please feel free to open an issue.
|
83 |
|
84 |
-
---------------------------------------------------------------------------------------------------------------------------------------------------
|
85 |
-
**Naming Conventions**<a name="naming-conventions"></a>
|
86 |
-
|
87 |
-
kudasai.py - Main script - ください - Please
|
88 |
-
|
89 |
-
Kairyou - Preprocessing Package - 改良 - Reform
|
90 |
-
|
91 |
-
kaiseki.py - DeepL translation module - 解析 - Parsing
|
92 |
-
|
93 |
-
kijiku.py - OpenAI translation module - 基軸 - Foundation
|
94 |
-
|
95 |
-
Kudasai gets it's original name idea from it's inspiration, Atreyagaurav's Onegai. Which also means please. You can find that [here](https://github.com/Atreyagaurav/onegai)
|
96 |
-
|
97 |
---------------------------------------------------------------------------------------------------------------------------------------------------
|
98 |
|
99 |
**Kairyou**<a name="kairyou"></a>
|
@@ -157,7 +161,7 @@ Kaiseki is the DeepL translation module, it is used to translate Japanese to Eng
|
|
157 |
|
158 |
Kaiseki is effectively deprecated and is only maintained. Do not expect any updates to it anytime soon other than bug fixes or compatibility updates.
|
159 |
|
160 |
-
Please note an API key is required for Kaiseki to work, you can get one here
|
161 |
|
162 |
It is free under 500k characters per month.
|
163 |
|
@@ -171,15 +175,17 @@ Kaiseki will store your obfuscated api key locally under KudasaiSecrets under %A
|
|
171 |
|
172 |
**Kijiku**<a name="kijiku"></a>
|
173 |
|
174 |
-
Kijiku is the
|
175 |
|
176 |
-
You also need an api key for Kijiku to work
|
177 |
|
178 |
-
|
|
|
|
|
179 |
|
180 |
Kijiku is vastly more complicated and has a lot of steps, so let's go over them.
|
181 |
|
182 |
-
Provided you accept the prompt and choose '2' to run Kijiku, you will be prompted to enter your
|
183 |
|
184 |
You will be prompted if you'd like to change these settings, if you choose to do so, you'll be asked for which setting you'd like to change, and what to change it too, until you choose to exit. Multiple things can be done in this menu, so follow the prompts. If you want to change anything about the settings, you do it here.
|
185 |
|
@@ -187,7 +193,7 @@ You can also choose to upload your own settings file in the settings change menu
|
|
187 |
|
188 |
You can change your api key right after this step if you wish.
|
189 |
|
190 |
-
After that you will be shown an estimated cost of translation, this is based on the number of tokens in the preprocessed text as determined by tiktoken. Kijiku will then prompt for confirmation, run, and translate the preprocessed text and no other input is required.
|
191 |
|
192 |
Your translated text will be stored in the output folder in the same directory as kudasai.py.
|
193 |
|
@@ -199,46 +205,73 @@ Also note that Kijiku's settings are somewhat complex, please see the section be
|
|
199 |
|
200 |
(Fairly technical, can be abstracted away by using default settings or someone else's settings file.)
|
201 |
|
202 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
203 |
|
|
|
204 |
----------------------------------------------------------------------------------
|
205 |
-
|
|
|
|
|
|
|
|
|
|
|
206 |
|
207 |
-
|
208 |
|
209 |
-
|
210 |
|
211 |
-
|
212 |
|
213 |
-
|
214 |
|
215 |
-
|
216 |
|
217 |
-
|
218 |
|
219 |
-
|
220 |
|
221 |
-
|
222 |
|
223 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
224 |
|
225 |
-
|
226 |
|
227 |
-
|
228 |
|
229 |
-
|
230 |
|
231 |
-
|
232 |
|
233 |
-
|
234 |
|
235 |
-
|
236 |
|
237 |
-
|
238 |
|
239 |
-
|
|
|
|
|
240 |
----------------------------------------------------------------------------------
|
241 |
-
stream, logit_bias, stop and n are included for legacy purposes, current versions of Kudasai will hardcode their values when validating the Kijiku_rule.json to their default values.
|
242 |
|
243 |
---------------------------------------------------------------------------------------------------------------------------------------------------
|
244 |
|
@@ -251,24 +284,32 @@ To run the Web GUI, simply run webgui.py in the same directory as kudasai.py
|
|
251 |
Below are some images of the Web GUI.
|
252 |
|
253 |
Indexing | Kairyou:
|
254 |
-
![Indexing Screen | Kairyou](https://i.imgur.com/
|
255 |
|
256 |
Preprocessing | Kairyou:
|
257 |
-
![Preprocessing Screen | Kairyou](https://i.imgur.com/
|
258 |
|
259 |
Translation | Kaiseki:
|
260 |
-
![Translation Screen | Kaiseki](https://i.imgur.com/
|
261 |
|
262 |
Translation | Kijiku:
|
263 |
-
![Translation Screen | Kijiku](https://i.imgur.com/
|
|
|
|
|
264 |
|
265 |
Kijiku Settings:
|
266 |
-
![Kijiku Settings](https://i.imgur.com/
|
|
|
|
|
267 |
|
268 |
Logging:
|
269 |
-
![Logging](https://i.imgur.com/
|
270 |
|
271 |
-
|
|
|
|
|
|
|
|
|
272 |
|
273 |
---------------------------------------------------------------------------------------------------------------------------------------------------
|
274 |
**License**<a name="license"></a>
|
@@ -288,4 +329,4 @@ For any bugs or suggestions please use the issues tab [here](https://github.com/
|
|
288 |
|
289 |
Once again, I actively encourage and welcome any feedback on this project.
|
290 |
|
291 |
-
---------------------------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
---------------------------------------------------------------------------------------------------------------------------------------------------
|
2 |
**Table of Contents**
|
3 |
|
4 |
- [Notes](#notes)
|
5 |
- [Dependencies](#dependencies)
|
|
|
6 |
- [Naming Conventions](#naming-conventions)
|
7 |
+
- [Quick Start](#quick-start)
|
8 |
- [Kairyou](#kairyou)
|
9 |
- [Kaiseki](#kaiseki)
|
10 |
- [Kijiku](#kijiku)
|
11 |
- [Kijiku Settings](#kijiku-settings)
|
12 |
- [Web GUI](#webgui)
|
13 |
+
- [Hugging Face](#huggingface)
|
14 |
- [License](#license)
|
15 |
- [Contact](#contact)
|
16 |
|
|
|
19 |
|
20 |
Windows 10 and Linux Mint are the only tested operating systems, feel free to test on other operating systems and report back to me. I will do my best to fix any issues that arise.
|
21 |
|
22 |
+
Python version: 3.10+
|
23 |
|
24 |
+
Used to make (Japanese - English) translation easier by preprocessing the Japanese text (optional auto translation using DeepL, Gemini, and OpenAI APIs).
|
25 |
|
26 |
Preprocessor is sourced from an external package, which I also designed, called [Kairyou](https://github.com/Bikatr7/Kairyou).
|
27 |
|
|
|
44 |
|
45 |
google-generativeai==0.4.0
|
46 |
|
|
|
|
|
47 |
or see requirements.txt
|
48 |
|
49 |
+
Also requires spacy's ja_core_news_lg model, which can be installed via the following command:
|
50 |
+
|
51 |
+
```bash
|
52 |
+
python -m spacy download ja_core_news_lg
|
53 |
+
```
|
54 |
+
|
55 |
+
or on Linux
|
56 |
+
|
57 |
+
```bash
|
58 |
+
python3 -m spacy download ja_core_news_lg
|
59 |
+
```
|
60 |
+
|
61 |
+
---------------------------------------------------------------------------------------------------------------------------------------------------
|
62 |
+
**Naming Conventions**<a name="naming-conventions"></a>
|
63 |
+
|
64 |
+
kudasai.py - Main script - ください - Please
|
65 |
+
|
66 |
+
Kairyou - Preprocessing Package - 改良 - Reform
|
67 |
+
|
68 |
+
kaiseki.py - DeepL translation module - 解析 - Parsing
|
69 |
+
|
70 |
+
kijiku.py - OpenAI translation module - 基軸 - Foundation
|
71 |
+
|
72 |
+
Kudasai gets it's original name idea from it's inspiration, Atreyagaurav's Onegai. Which also means please. You can find that [here](https://github.com/Atreyagaurav/onegai)
|
73 |
+
|
74 |
---------------------------------------------------------------------------------------------------------------------------------------------------
|
75 |
**Quick Start**<a name="quick-start"></a>
|
76 |
|
77 |
Windows is assumed for the rest of this README, but the process should be similar for Linux.
|
78 |
|
79 |
+
Due to PyPi limitations, you need to install Spacy's JP Model, which can not be included automatically due to it being a direct dependency link which PyPi does not support. Make sure you do this after installing the requirements.txt file.
|
80 |
+
|
81 |
+
```bash
|
82 |
+
python -m spacy download ja_core_news_lg
|
83 |
+
```
|
84 |
+
|
85 |
Simply run Kudasai.py, enter a txt file path to the text you wish to translate, and then insert a replacement json file path if you wish to use one. If you do not wish to use a replacement json file, you can simply input a blank space and Kudasai will skip preprocessing and go straight to translation.
|
86 |
|
87 |
Kudasai will offer to index the text, which is useful for finding new names to add to the replacement json file. This is optional and can be skipped.
|
|
|
98 |
|
99 |
If you have any questions, comments, or concerns, please feel free to open an issue.
|
100 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
101 |
---------------------------------------------------------------------------------------------------------------------------------------------------
|
102 |
|
103 |
**Kairyou**<a name="kairyou"></a>
|
|
|
161 |
|
162 |
Kaiseki is effectively deprecated and is only maintained. Do not expect any updates to it anytime soon other than bug fixes or compatibility updates.
|
163 |
|
164 |
+
Please note an API key is required for Kaiseki to work, you can get one [here](https://www.deepl.com/pro#developer).
|
165 |
|
166 |
It is free under 500k characters per month.
|
167 |
|
|
|
175 |
|
176 |
**Kijiku**<a name="kijiku"></a>
|
177 |
|
178 |
+
Kijiku is the LLM translation module, it is used to translate Japanese to English. It is very accurate and is the recommended translation module.
|
179 |
|
180 |
+
You also need an api key for Kijiku to work.
|
181 |
|
182 |
+
You can get one here for OpenAI [here](https://platform.openai.com/)
|
183 |
+
|
184 |
+
and for Gemini is a bit more complicated, you'll need to make a google cloud project, enable the vertex AI API, and then create an api key. Although Gemini is free under 60 request at once as of Kudasai v3.4.0.
|
185 |
|
186 |
Kijiku is vastly more complicated and has a lot of steps, so let's go over them.
|
187 |
|
188 |
+
Provided you accept the prompt and choose '2' to run Kijiku, you will be prompted to choose a LLM. Then to enter your api key. Provided all goes well, Kijiku will attempt to load it's settings from KudasaiConfig, if it cannot find them, it will create them. Kijiku will store your obfuscated api key locally under KudasaiSecrets under %APPDATA% or ~/.config/ depending on your OS.
|
189 |
|
190 |
You will be prompted if you'd like to change these settings, if you choose to do so, you'll be asked for which setting you'd like to change, and what to change it too, until you choose to exit. Multiple things can be done in this menu, so follow the prompts. If you want to change anything about the settings, you do it here.
|
191 |
|
|
|
193 |
|
194 |
You can change your api key right after this step if you wish.
|
195 |
|
196 |
+
After that you will be shown an estimated cost of translation, this is based on the number of tokens in the preprocessed text as determined by tiktoken for OpenAI, and by Google for Gemini. Kijiku will then prompt for confirmation, run, and translate the preprocessed text and no other input is required.
|
197 |
|
198 |
Your translated text will be stored in the output folder in the same directory as kudasai.py.
|
199 |
|
|
|
205 |
|
206 |
(Fairly technical, can be abstracted away by using default settings or someone else's settings file.)
|
207 |
|
208 |
+
----------------------------------------------------------------------------------
|
209 |
+
Kijiku Settings:
|
210 |
+
|
211 |
+
prompt_assembly_mode : 1 or 2. 1 means the system message will actually be treated as a system message. 2 means it'll be treated as a user message. 1 is recommend for gpt-4 otherwise either works. For Gemini, this setting is ignored.
|
212 |
+
|
213 |
+
number_of_lines_per_batch : The number of lines to be built into a prompt at once. Theoretically, more lines would be more cost effective, but other complications may occur with higher lines. So far been tested up to 48.
|
214 |
+
|
215 |
+
sentence_fragmenter_mode : 1 or 2 (1 - via regex and other nonsense) 2 - None (Takes formatting and text directly from API return)) the API can sometimes return a result on a single line, so this determines the way Kijiku fragments the sentences if at all. Use 2 for newer models.
|
216 |
+
|
217 |
+
je_check_mode : 1 or 2, 1 will print out the jap then the english below separated by ---, 2 will attempt to pair the english and jap sentences, placing the jap above the eng. If it cannot, it will default to 1. Use 2 for newer models.
|
218 |
+
|
219 |
+
number_of_malformed_batch_retries : (Malformed batch is when je-fixing fails) How many times Kijiku will attempt to mend a malformed batch (mending is resending the request), only for gpt4. Be careful with increasing as cost increases at (cost * length * n) at worst case. This setting is ignored if je_check_mode is set to 1.
|
220 |
+
|
221 |
+
batch_retry_timeout : How long Kijiku will try to translate a batch in seconds, if a requests exceeds this duration, Kijiku will leave it untranslated.
|
222 |
|
223 |
+
number_of_concurrent_batches : How many translations batches Kijiku will send to the translation API at a time. For OpenAI, be conservative as rate-limiting is aggressive, I'd suggest 3-5. For Gemini, do not exceed 60.
|
224 |
----------------------------------------------------------------------------------
|
225 |
+
Open AI Settings:
|
226 |
+
See https://platform.openai.com/docs/api-reference/chat/create for further details
|
227 |
+
----------------------------------------------------------------------------------
|
228 |
+
openai_model : ID of the model to use. Kijiku only works with 'chat' models.
|
229 |
+
|
230 |
+
openai_system_message : Instructions to the model. Basically tells the model how to translate.
|
231 |
|
232 |
+
openai_temperature : What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic. Lower values are typically better for translation.
|
233 |
|
234 |
+
openai_top_p : An alternative to sampling with temperature, called nucleus sampling, where the model considers the results of the tokens with top_p probability mass. So 0.1 means only the tokens comprising the top 10% probability mass are considered. I generally recommend altering this or temperature but not both.
|
235 |
|
236 |
+
openai_n : How many chat completion choices to generate for each input message. Do not change this.
|
237 |
|
238 |
+
openai_stream : If set, partial message deltas will be sent, like in ChatGPT. Tokens will be sent as data-only server-sent events as they become available, with the stream terminated by a data: [DONE] message. See the OpenAI python library on GitHub for example code. Do not change this.
|
239 |
|
240 |
+
openai_stop : Up to 4 sequences where the API will stop generating further tokens. Do not change this.
|
241 |
|
242 |
+
openai_logit_bias : Modifies the likelihood of specified tokens appearing in the completion. Do not change this.
|
243 |
|
244 |
+
openai_max_tokens : The maximum number of tokens to generate in the chat completion. The total length of input tokens and generated tokens is limited by the model's context length. I wouldn't recommend changing this. Is none by default. If you change to an integer, make sure it doesn't exceed that model's context length or your request will fail and repeat till timeout.
|
245 |
|
246 |
+
openai_presence_penalty : Number between -2.0 and 2.0. Positive values penalize new tokens based on whether they appear in the text so far, increasing the model's likelihood to talk about new topics. While negative values encourage repetition. Should leave this at 0.0.
|
247 |
|
248 |
+
openai_frequency_penalty : Number between -2.0 and 2.0. Positive values penalize new tokens based on their existing frequency in the text so far, decreasing the model's likelihood to repeat the same line verbatim. Negative values encourage repetition. Should leave this at 0.0.
|
249 |
+
----------------------------------------------------------------------------------
|
250 |
+
openai_stream, openai_logit_bias, openai_stop and openai_n are included for completion's sake, current versions of Kudasai will hardcode their values when validating the Kijiku_rule.json to their default values. As different values for these settings do not have a use case in Kudasai's current implementation.
|
251 |
+
----------------------------------------------------------------------------------
|
252 |
+
Gemini Settings:
|
253 |
+
https://ai.google.dev/docs/concepts#model-parameters for further details
|
254 |
+
----------------------------------------------------------------------------------
|
255 |
+
gemini_model : The model to use. Currently only supports gemini-pro and gemini-pro-vision, the 1.0 model and it's aliases.
|
256 |
|
257 |
+
gemini_prompt : Instructions to the model. Basically tells the model how to translate.
|
258 |
|
259 |
+
gemini_temperature : What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic. Lower values are typically better for translation.
|
260 |
|
261 |
+
gemini_top_p : An alternative to sampling with temperature, called nucleus sampling, where the model considers the results of the tokens with top_p probability mass. So 0.1 means only the tokens comprising the top 10% probability mass are considered. I generally recommend altering this or temperature but not both.
|
262 |
|
263 |
+
gemini_top_k : Determines the number of most probable tokens to consider for each selection step. A higher value increases diversity, a lower value makes the output more deterministic.
|
264 |
|
265 |
+
gemini_candidate_count : The number of candidates to generate for each input message. Do not change this.
|
266 |
|
267 |
+
gemini_stream : If set, partial message deltas will be sent, like in Gemini Chat. Tokens will be sent as data-only server-sent events as they become available, with the stream terminated by a data: [DONE] message. Do not change this.
|
268 |
|
269 |
+
gemini_stop_sequences : Up to 4 sequences where the API will stop generating further tokens. Do not change this.
|
270 |
|
271 |
+
gemini_max_output_tokens : The maximum number of tokens to generate in the chat completion. The total length of input tokens and generated tokens is limited by the model's context length. I wouldn't recommend changing this. Is none by default. If you change to an integer, make sure it doesn't exceed that model's context length or your request will fail and repeat till timeout.
|
272 |
+
----------------------------------------------------------------------------------
|
273 |
+
gemini_stream, gemini_stop_sequences and gemini_candidate_count are included for completion's sake, current versions of Kudasai will hardcode their values when validating the Kijiku_rule.json to their default values. As different values for these settings do not have a use case in Kudasai's current implementation.
|
274 |
----------------------------------------------------------------------------------
|
|
|
275 |
|
276 |
---------------------------------------------------------------------------------------------------------------------------------------------------
|
277 |
|
|
|
284 |
Below are some images of the Web GUI.
|
285 |
|
286 |
Indexing | Kairyou:
|
287 |
+
![Indexing Screen | Kairyou](https://i.imgur.com/0a2mzOI.png)
|
288 |
|
289 |
Preprocessing | Kairyou:
|
290 |
+
![Preprocessing Screen | Kairyou](https://i.imgur.com/2pt06gC.png)
|
291 |
|
292 |
Translation | Kaiseki:
|
293 |
+
![Translation Screen | Kaiseki](https://i.imgur.com/X98JYsp.png)
|
294 |
|
295 |
Translation | Kijiku:
|
296 |
+
![Translation Screen | Kijiku](https://i.imgur.com/X6IxyL8.png)
|
297 |
+
|
298 |
+
|
299 |
|
300 |
Kijiku Settings:
|
301 |
+
![Kijiku Settings](https://i.imgur.com/VX0fGd5.png)
|
302 |
+
|
303 |
+
|
304 |
|
305 |
Logging:
|
306 |
+
![Logging](https://i.imgur.com/IkUjpXR.png)
|
307 |
|
308 |
+
---------------------------------------------------------------------------------------------------------------------------------------------------
|
309 |
+
|
310 |
+
**Hugging Face**<a name="huggingface"></a>
|
311 |
+
|
312 |
+
For those who are interested, or simply cannot run Kudasai locally, a instance of Kudasai's WebGUI is hosted on Hugging Face's servers. You can find it [here](https://huggingface.co/spaces/Bikatr7/Kudasai).
|
313 |
|
314 |
---------------------------------------------------------------------------------------------------------------------------------------------------
|
315 |
**License**<a name="license"></a>
|
|
|
329 |
|
330 |
Once again, I actively encourage and welcome any feedback on this project.
|
331 |
|
332 |
+
---------------------------------------------------------------------------------------------------------------------------------------------------
|
handlers/json_handler.py
CHANGED
@@ -137,27 +137,27 @@ gemini_stream, gemini_stop_sequences and gemini_candidate_count are included for
|
|
137 |
]
|
138 |
|
139 |
validation_rules = {
|
140 |
-
"prompt_assembly_mode": lambda x: 1 <= x <= 2,
|
141 |
-
"number_of_lines_per_batch": lambda x:
|
142 |
-
"sentence_fragmenter_mode": lambda x: 1 <= x <= 2,
|
143 |
-
"je_check_mode": lambda x: 1 <= x <= 2,
|
144 |
-
"number_of_malformed_batch_retries": lambda x:
|
145 |
-
"batch_retry_timeout": lambda x:
|
146 |
-
"number_of_concurrent_batches": lambda x:
|
147 |
-
"openai_model": lambda x: x in FileEnsurer.ALLOWED_OPENAI_MODELS,
|
148 |
"openai_system_message": lambda x: x not in ["", "None", None],
|
149 |
-
"openai_temperature": lambda x: 0 <= x <= 2,
|
150 |
-
"openai_top_p": lambda x: 0 <= x <= 1,
|
151 |
-
"openai_max_tokens": lambda x: x is None or isinstance(x, int),
|
152 |
-
"openai_presence_penalty": lambda x: -2 <= x <= 2,
|
153 |
-
"gemini_model": lambda x: x in FileEnsurer.ALLOWED_GEMINI_MODELS,
|
154 |
"gemini_prompt": lambda x: x not in ["", "None", None],
|
155 |
-
"gemini_temperature": lambda x: 0 <= x <= 2,
|
156 |
-
"gemini_top_p": lambda x: x is None or 0 <= x <= 2,
|
157 |
-
"gemini_top_k": lambda x: x is None or isinstance(x, int) and x >= 0,
|
158 |
"gemini_max_output_tokens": lambda x: x is None or isinstance(x, int),
|
159 |
}
|
160 |
-
|
161 |
try:
|
162 |
## ensure categories are present
|
163 |
assert "base kijiku settings" in JsonHandler.current_kijiku_rules
|
@@ -197,6 +197,7 @@ gemini_stream, gemini_stop_sequences and gemini_candidate_count are included for
|
|
197 |
|
198 |
except Exception as e:
|
199 |
Logger.log_action("Kijiku Rules.json is not valid, setting to invalid_placeholder, current:")
|
|
|
200 |
Logger.log_action(str(JsonHandler.current_kijiku_rules))
|
201 |
JsonHandler.current_kijiku_rules = FileEnsurer.INVALID_KIJIKU_RULES_PLACEHOLDER
|
202 |
|
@@ -342,7 +343,7 @@ gemini_stream, gemini_stop_sequences and gemini_candidate_count are included for
|
|
342 |
|
343 |
Parameters:
|
344 |
setting_name (str) : The name of the setting to convert.
|
345 |
-
|
346 |
|
347 |
Returns:
|
348 |
(typing.Any) : The converted value.
|
@@ -367,18 +368,18 @@ gemini_stream, gemini_stop_sequences and gemini_candidate_count are included for
|
|
367 |
"openai_stream": {"type": bool, "constraints": lambda x: x is False},
|
368 |
"openai_stop": {"type": None, "constraints": lambda x: x is None},
|
369 |
"openai_logit_bias": {"type": None, "constraints": lambda x: x is None},
|
370 |
-
"openai_max_tokens": {"type":
|
371 |
"openai_presence_penalty": {"type": float, "constraints": lambda x: -2 <= x <= 2},
|
372 |
"openai_frequency_penalty": {"type": float, "constraints": lambda x: -2 <= x <= 2},
|
373 |
"gemini_model": {"type": str, "constraints": lambda x: x in FileEnsurer.ALLOWED_GEMINI_MODELS},
|
374 |
"gemini_prompt": {"type": str, "constraints": lambda x: x not in ["", "None", None]},
|
375 |
"gemini_temperature": {"type": float, "constraints": lambda x: 0 <= x <= 2},
|
376 |
-
"gemini_top_p": {"type":
|
377 |
-
"gemini_top_k": {"type":
|
378 |
"gemini_candidate_count": {"type": int, "constraints": lambda x: x == 1},
|
379 |
"gemini_stream": {"type": bool, "constraints": lambda x: x is False},
|
380 |
"gemini_stop_sequences": {"type": None, "constraints": lambda x: x is None},
|
381 |
-
"gemini_max_output_tokens": {"type":
|
382 |
}
|
383 |
|
384 |
if(setting_name not in type_expectations):
|
@@ -394,11 +395,18 @@ gemini_stream, gemini_stop_sequences and gemini_candidate_count are included for
|
|
394 |
|
395 |
if(setting_info["type"] is None):
|
396 |
converted_value = None
|
397 |
-
|
398 |
-
|
|
|
|
|
399 |
converted_value = None
|
400 |
-
|
|
|
401 |
converted_value = int(value)
|
|
|
|
|
|
|
|
|
402 |
else:
|
403 |
converted_value = setting_info["type"](value)
|
404 |
|
|
|
137 |
]
|
138 |
|
139 |
validation_rules = {
|
140 |
+
"prompt_assembly_mode": lambda x: isinstance(x, int) and 1 <= x <= 2,
|
141 |
+
"number_of_lines_per_batch": lambda x: isinstance(x, int) and x > 0,
|
142 |
+
"sentence_fragmenter_mode": lambda x: isinstance(x, int) and 1 <= x <= 2,
|
143 |
+
"je_check_mode": lambda x: isinstance(x, int) and 1 <= x <= 2,
|
144 |
+
"number_of_malformed_batch_retries": lambda x: isinstance(x, int) and x >= 0,
|
145 |
+
"batch_retry_timeout": lambda x: isinstance(x, int) and x >= 0,
|
146 |
+
"number_of_concurrent_batches": lambda x: isinstance(x, int) and x >= 0,
|
147 |
+
"openai_model": lambda x: isinstance(x, str) and x in FileEnsurer.ALLOWED_OPENAI_MODELS,
|
148 |
"openai_system_message": lambda x: x not in ["", "None", None],
|
149 |
+
"openai_temperature": lambda x: isinstance(x, float) and 0 <= x <= 2,
|
150 |
+
"openai_top_p": lambda x: isinstance(x, float) and 0 <= x <= 1,
|
151 |
+
"openai_max_tokens": lambda x: x is None or isinstance(x, int) and x > 0,
|
152 |
+
"openai_presence_penalty": lambda x: isinstance(x, float) and -2 <= x <= 2,
|
153 |
+
"gemini_model": lambda x: isinstance(x, str) and x in FileEnsurer.ALLOWED_GEMINI_MODELS,
|
154 |
"gemini_prompt": lambda x: x not in ["", "None", None],
|
155 |
+
"gemini_temperature": lambda x: isinstance(x, float) and 0 <= x <= 2,
|
156 |
+
"gemini_top_p": lambda x: x is None or (isinstance(x, float) and 0 <= x <= 2),
|
157 |
+
"gemini_top_k": lambda x: x is None or (isinstance(x, int) and x >= 0),
|
158 |
"gemini_max_output_tokens": lambda x: x is None or isinstance(x, int),
|
159 |
}
|
160 |
+
|
161 |
try:
|
162 |
## ensure categories are present
|
163 |
assert "base kijiku settings" in JsonHandler.current_kijiku_rules
|
|
|
197 |
|
198 |
except Exception as e:
|
199 |
Logger.log_action("Kijiku Rules.json is not valid, setting to invalid_placeholder, current:")
|
200 |
+
Logger.log_action("Reason: " + str(e))
|
201 |
Logger.log_action(str(JsonHandler.current_kijiku_rules))
|
202 |
JsonHandler.current_kijiku_rules = FileEnsurer.INVALID_KIJIKU_RULES_PLACEHOLDER
|
203 |
|
|
|
343 |
|
344 |
Parameters:
|
345 |
setting_name (str) : The name of the setting to convert.
|
346 |
+
initial_value (str) : The initial value to convert.
|
347 |
|
348 |
Returns:
|
349 |
(typing.Any) : The converted value.
|
|
|
368 |
"openai_stream": {"type": bool, "constraints": lambda x: x is False},
|
369 |
"openai_stop": {"type": None, "constraints": lambda x: x is None},
|
370 |
"openai_logit_bias": {"type": None, "constraints": lambda x: x is None},
|
371 |
+
"openai_max_tokens": {"type": int, "constraints": lambda x: x is None or isinstance(x, int)},
|
372 |
"openai_presence_penalty": {"type": float, "constraints": lambda x: -2 <= x <= 2},
|
373 |
"openai_frequency_penalty": {"type": float, "constraints": lambda x: -2 <= x <= 2},
|
374 |
"gemini_model": {"type": str, "constraints": lambda x: x in FileEnsurer.ALLOWED_GEMINI_MODELS},
|
375 |
"gemini_prompt": {"type": str, "constraints": lambda x: x not in ["", "None", None]},
|
376 |
"gemini_temperature": {"type": float, "constraints": lambda x: 0 <= x <= 2},
|
377 |
+
"gemini_top_p": {"type": float, "constraints": lambda x: x is None or (isinstance(x, float) and 0 <= x <= 2)},
|
378 |
+
"gemini_top_k": {"type": int, "constraints": lambda x: x is None or x >= 0},
|
379 |
"gemini_candidate_count": {"type": int, "constraints": lambda x: x == 1},
|
380 |
"gemini_stream": {"type": bool, "constraints": lambda x: x is False},
|
381 |
"gemini_stop_sequences": {"type": None, "constraints": lambda x: x is None},
|
382 |
+
"gemini_max_output_tokens": {"type": int, "constraints": lambda x: x is None or isinstance(x, int)},
|
383 |
}
|
384 |
|
385 |
if(setting_name not in type_expectations):
|
|
|
395 |
|
396 |
if(setting_info["type"] is None):
|
397 |
converted_value = None
|
398 |
+
|
399 |
+
elif(setting_info["type"] == int) or (setting_info["type"] == float):
|
400 |
+
|
401 |
+
if(value is None or value is ''):
|
402 |
converted_value = None
|
403 |
+
|
404 |
+
elif(setting_info["type"] == int):
|
405 |
converted_value = int(value)
|
406 |
+
|
407 |
+
else:
|
408 |
+
converted_value = float(value)
|
409 |
+
|
410 |
else:
|
411 |
converted_value = setting_info["type"](value)
|
412 |
|
kudasai.py
CHANGED
@@ -55,16 +55,11 @@ class Kudasai:
|
|
55 |
|
56 |
FileEnsurer.setup_needed_files()
|
57 |
|
58 |
-
Logger.clear_log_file()
|
59 |
-
|
60 |
Logger.log_barrier()
|
61 |
Logger.log_action("Kudasai started")
|
62 |
Logger.log_action("Current version: " + Toolkit.CURRENT_VERSION)
|
63 |
Logger.log_barrier()
|
64 |
|
65 |
-
Logger.push_batch()
|
66 |
-
Logger.clear_batch()
|
67 |
-
|
68 |
try:
|
69 |
|
70 |
with open(FileEnsurer.config_kijiku_rules_path, "r") as kijiku_rules_file:
|
@@ -316,11 +311,11 @@ async def main() -> None:
|
|
316 |
|
317 |
"""
|
318 |
|
319 |
-
Kudasai.boot()
|
320 |
-
Toolkit.clear_console()
|
321 |
-
|
322 |
try:
|
323 |
|
|
|
|
|
|
|
324 |
if(len(sys.argv) <= 1):
|
325 |
await run_console_version()
|
326 |
|
|
|
55 |
|
56 |
FileEnsurer.setup_needed_files()
|
57 |
|
|
|
|
|
58 |
Logger.log_barrier()
|
59 |
Logger.log_action("Kudasai started")
|
60 |
Logger.log_action("Current version: " + Toolkit.CURRENT_VERSION)
|
61 |
Logger.log_barrier()
|
62 |
|
|
|
|
|
|
|
63 |
try:
|
64 |
|
65 |
with open(FileEnsurer.config_kijiku_rules_path, "r") as kijiku_rules_file:
|
|
|
311 |
|
312 |
"""
|
313 |
|
|
|
|
|
|
|
314 |
try:
|
315 |
|
316 |
+
Kudasai.boot()
|
317 |
+
Toolkit.clear_console()
|
318 |
+
|
319 |
if(len(sys.argv) <= 1):
|
320 |
await run_console_version()
|
321 |
|
models/kijiku.py
CHANGED
@@ -19,7 +19,7 @@ from handlers.json_handler import JsonHandler
|
|
19 |
from modules.common.file_ensurer import FileEnsurer
|
20 |
from modules.common.logger import Logger
|
21 |
from modules.common.toolkit import Toolkit
|
22 |
-
from modules.common.exceptions import AuthenticationError, MaxBatchDurationExceededException, AuthenticationError, InternalServerError, RateLimitError, APITimeoutError
|
23 |
from modules.common.decorators import permission_error_decorator
|
24 |
|
25 |
from custom_classes.messages import SystemTranslationMessage, ModelTranslationMessage, Message
|
@@ -273,7 +273,7 @@ class Kijiku:
|
|
273 |
FileEnsurer.standard_overwrite_file(api_key_path, base64.b64encode(api_key.encode('utf-8')).decode('utf-8'), omit=True)
|
274 |
|
275 |
## if invalid key exit
|
276 |
-
except AuthenticationError:
|
277 |
|
278 |
Toolkit.clear_console()
|
279 |
|
@@ -390,8 +390,11 @@ class Kijiku:
|
|
390 |
|
391 |
"""
|
392 |
|
|
|
|
|
|
|
393 |
Logger.log_barrier()
|
394 |
-
Logger.log_action("
|
395 |
Logger.log_barrier()
|
396 |
|
397 |
JsonHandler.print_kijiku_rules()
|
@@ -448,13 +451,9 @@ class Kijiku:
|
|
448 |
Logger.log_action("Starting Prompt Building")
|
449 |
Logger.log_barrier()
|
450 |
|
451 |
-
|
452 |
-
Kijiku.build_openai_translation_batches()
|
453 |
-
model = OpenAIService.model
|
454 |
|
455 |
-
else
|
456 |
-
Kijiku.build_gemini_translation_batches()
|
457 |
-
model = GeminiService.model
|
458 |
|
459 |
await Kijiku.handle_cost_estimate_prompt(model, omit_prompt=is_webgui)
|
460 |
|
@@ -549,10 +548,10 @@ class Kijiku:
|
|
549 |
|
550 |
sentence = Kijiku.text_to_translate[index]
|
551 |
stripped_sentence = sentence.strip()
|
552 |
-
|
553 |
|
554 |
has_quotes = any(char in sentence for char in ["「", "」", "『", "』", "【", "】", "\"", "'"])
|
555 |
-
is_part_in_sentence = "part" in
|
556 |
|
557 |
if(len(prompt) < Kijiku.number_of_lines_per_batch):
|
558 |
|
@@ -581,78 +580,38 @@ class Kijiku:
|
|
581 |
|
582 |
return prompt, index
|
583 |
|
584 |
-
##-------------------start-of-
|
585 |
|
586 |
@staticmethod
|
587 |
-
def
|
588 |
|
589 |
"""
|
590 |
|
591 |
-
Builds translations batches dict for the
|
592 |
-
|
593 |
"""
|
594 |
|
595 |
i = 0
|
596 |
|
597 |
while i < len(Kijiku.text_to_translate):
|
598 |
-
batch, i = Kijiku.generate_text_to_translate_batches(i)
|
599 |
|
|
|
600 |
batch = ''.join(batch)
|
601 |
|
602 |
-
|
603 |
-
if(Kijiku.prompt_assembly_mode == 1):
|
604 |
-
system_msg = SystemTranslationMessage(content=str(OpenAIService.system_message))
|
605 |
-
|
606 |
-
## while message mode two structures the first message as a model message and the second message as a model message too, typically used for non-gpt-4 models if at all
|
607 |
-
else:
|
608 |
-
system_msg = ModelTranslationMessage(content=str(OpenAIService.system_message))
|
609 |
-
|
610 |
-
Kijiku.openai_translation_batches.append(system_msg)
|
611 |
-
|
612 |
-
model_msg = ModelTranslationMessage(content=batch)
|
613 |
-
|
614 |
-
Kijiku.openai_translation_batches.append(model_msg)
|
615 |
|
616 |
-
|
617 |
-
|
618 |
-
|
619 |
-
|
620 |
-
i = 0
|
621 |
-
|
622 |
-
for message in Kijiku.openai_translation_batches:
|
623 |
-
|
624 |
-
i+=1
|
625 |
|
626 |
-
|
|
|
|
|
627 |
|
628 |
-
Logger.log_action(str(message))
|
629 |
-
|
630 |
else:
|
631 |
-
|
632 |
-
|
633 |
-
Logger.log_barrier()
|
634 |
-
|
635 |
-
##-------------------start-of-build_gemini_translation_batches()---------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
636 |
-
|
637 |
-
@staticmethod
|
638 |
-
def build_gemini_translation_batches() -> None:
|
639 |
-
|
640 |
-
"""
|
641 |
-
|
642 |
-
Builds translations batches dict for the Gemini service.
|
643 |
-
|
644 |
-
"""
|
645 |
-
|
646 |
-
i = 0
|
647 |
-
|
648 |
-
while i < len(Kijiku.text_to_translate):
|
649 |
-
batch, i = Kijiku.generate_text_to_translate_batches(i)
|
650 |
-
|
651 |
-
batch = ''.join(batch)
|
652 |
-
|
653 |
-
## Gemini does not use system messages or model messages, and instead just takes a string input, so we just need to place the prompt before the text to be translated
|
654 |
-
Kijiku.gemini_translation_batches.append(GeminiService.prompt)
|
655 |
-
Kijiku.gemini_translation_batches.append(batch)
|
656 |
|
657 |
Logger.log_barrier()
|
658 |
Logger.log_action("Built Messages : ")
|
@@ -660,19 +619,17 @@ class Kijiku:
|
|
660 |
|
661 |
i = 0
|
662 |
|
663 |
-
for message in Kijiku.gemini_translation_batches:
|
664 |
|
665 |
i+=1
|
666 |
|
667 |
-
|
668 |
-
|
669 |
-
Logger.log_action(str(message))
|
670 |
-
|
671 |
-
else:
|
672 |
|
673 |
-
|
674 |
Logger.log_barrier()
|
675 |
|
|
|
|
|
676 |
##-------------------start-of-estimate_cost()---------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
677 |
|
678 |
@staticmethod
|
@@ -850,7 +807,7 @@ class Kijiku:
|
|
850 |
Logger.log_barrier()
|
851 |
|
852 |
if(Kijiku.LLM_TYPE == "gemini"):
|
853 |
-
|
854 |
|
855 |
Logger.log_action("Estimated number of tokens : " + str(num_tokens), output=True, omit_timestamp=True)
|
856 |
Logger.log_action("Estimated minimum cost : " + str(min_cost) + " USD", output=True, omit_timestamp=True)
|
@@ -873,19 +830,20 @@ class Kijiku:
|
|
873 |
async def handle_translation(model:str, index:int, length:int, translation_instructions:typing.Union[str, Message], translation_prompt:typing.Union[str, Message]) -> tuple[int, typing.Union[str, Message], str]:
|
874 |
|
875 |
"""
|
876 |
-
|
|
|
877 |
|
878 |
Parameters:
|
879 |
-
model (string) :
|
880 |
-
index (int) :
|
881 |
-
length (int) :
|
882 |
-
translation_instructions (typing.Union[str, Message]) :
|
883 |
-
translation_prompt (typing.Union[str, Message]) :
|
884 |
|
885 |
Returns:
|
886 |
-
index (int) :
|
887 |
-
translation_prompt (typing.Union[str, Message]) :
|
888 |
-
translated_message (str) :
|
889 |
|
890 |
"""
|
891 |
|
@@ -1044,7 +1002,7 @@ class Kijiku:
|
|
1044 |
|
1045 |
"""
|
1046 |
|
1047 |
-
Fixes the J->E text to be more j-e
|
1048 |
|
1049 |
Note that fix_je() is not always accurate, and may use standard j-e formatting instead of the corrected formatting.
|
1050 |
|
|
|
19 |
from modules.common.file_ensurer import FileEnsurer
|
20 |
from modules.common.logger import Logger
|
21 |
from modules.common.toolkit import Toolkit
|
22 |
+
from modules.common.exceptions import AuthenticationError, MaxBatchDurationExceededException, AuthenticationError, InternalServerError, RateLimitError, APITimeoutError, GoogleAuthError
|
23 |
from modules.common.decorators import permission_error_decorator
|
24 |
|
25 |
from custom_classes.messages import SystemTranslationMessage, ModelTranslationMessage, Message
|
|
|
273 |
FileEnsurer.standard_overwrite_file(api_key_path, base64.b64encode(api_key.encode('utf-8')).decode('utf-8'), omit=True)
|
274 |
|
275 |
## if invalid key exit
|
276 |
+
except (GoogleAuthError, AuthenticationError):
|
277 |
|
278 |
Toolkit.clear_console()
|
279 |
|
|
|
390 |
|
391 |
"""
|
392 |
|
393 |
+
|
394 |
+
Logger.log_barrier()
|
395 |
+
Logger.log_action("Kijiku Activated, LLM Type : " + Kijiku.LLM_TYPE)
|
396 |
Logger.log_barrier()
|
397 |
+
Logger.log_action("Settings are as follows : ")
|
398 |
Logger.log_barrier()
|
399 |
|
400 |
JsonHandler.print_kijiku_rules()
|
|
|
451 |
Logger.log_action("Starting Prompt Building")
|
452 |
Logger.log_barrier()
|
453 |
|
454 |
+
Kijiku.build_translation_batches()
|
|
|
|
|
455 |
|
456 |
+
model = OpenAIService.model if Kijiku.LLM_TYPE == "openai" else GeminiService.model
|
|
|
|
|
457 |
|
458 |
await Kijiku.handle_cost_estimate_prompt(model, omit_prompt=is_webgui)
|
459 |
|
|
|
548 |
|
549 |
sentence = Kijiku.text_to_translate[index]
|
550 |
stripped_sentence = sentence.strip()
|
551 |
+
lowercase_sentence = sentence.lower()
|
552 |
|
553 |
has_quotes = any(char in sentence for char in ["「", "」", "『", "』", "【", "】", "\"", "'"])
|
554 |
+
is_part_in_sentence = "part" in lowercase_sentence
|
555 |
|
556 |
if(len(prompt) < Kijiku.number_of_lines_per_batch):
|
557 |
|
|
|
580 |
|
581 |
return prompt, index
|
582 |
|
583 |
+
##-------------------start-of-build_translation_batches()---------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
584 |
|
585 |
@staticmethod
|
586 |
+
def build_translation_batches() -> None:
|
587 |
|
588 |
"""
|
589 |
|
590 |
+
Builds translations batches dict for the specified service.
|
591 |
+
|
592 |
"""
|
593 |
|
594 |
i = 0
|
595 |
|
596 |
while i < len(Kijiku.text_to_translate):
|
|
|
597 |
|
598 |
+
batch, i = Kijiku.generate_text_to_translate_batches(i)
|
599 |
batch = ''.join(batch)
|
600 |
|
601 |
+
if(Kijiku.LLM_TYPE == 'openai'):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
602 |
|
603 |
+
if(Kijiku.prompt_assembly_mode == 1):
|
604 |
+
system_msg = SystemTranslationMessage(content=str(OpenAIService.system_message))
|
605 |
+
else:
|
606 |
+
system_msg = ModelTranslationMessage(content=str(OpenAIService.system_message))
|
|
|
|
|
|
|
|
|
|
|
607 |
|
608 |
+
Kijiku.openai_translation_batches.append(system_msg)
|
609 |
+
model_msg = ModelTranslationMessage(content=batch)
|
610 |
+
Kijiku.openai_translation_batches.append(model_msg)
|
611 |
|
|
|
|
|
612 |
else:
|
613 |
+
Kijiku.gemini_translation_batches.append(GeminiService.prompt)
|
614 |
+
Kijiku.gemini_translation_batches.append(batch)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
615 |
|
616 |
Logger.log_barrier()
|
617 |
Logger.log_action("Built Messages : ")
|
|
|
619 |
|
620 |
i = 0
|
621 |
|
622 |
+
for message in (Kijiku.openai_translation_batches if Kijiku.LLM_TYPE == 'openai' else Kijiku.gemini_translation_batches):
|
623 |
|
624 |
i+=1
|
625 |
|
626 |
+
message = str(message) if Kijiku.LLM_TYPE == 'gemini' else message.content # type: ignore
|
|
|
|
|
|
|
|
|
627 |
|
628 |
+
if(i % 2 == 1):
|
629 |
Logger.log_barrier()
|
630 |
|
631 |
+
Logger.log_action(message)
|
632 |
+
|
633 |
##-------------------start-of-estimate_cost()---------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
634 |
|
635 |
@staticmethod
|
|
|
807 |
Logger.log_barrier()
|
808 |
|
809 |
if(Kijiku.LLM_TYPE == "gemini"):
|
810 |
+
Logger.log_action(f"As of Kudasai {Toolkit.CURRENT_VERSION}, Gemini Pro is Free to use", output=True, omit_timestamp=True)
|
811 |
|
812 |
Logger.log_action("Estimated number of tokens : " + str(num_tokens), output=True, omit_timestamp=True)
|
813 |
Logger.log_action("Estimated minimum cost : " + str(min_cost) + " USD", output=True, omit_timestamp=True)
|
|
|
830 |
async def handle_translation(model:str, index:int, length:int, translation_instructions:typing.Union[str, Message], translation_prompt:typing.Union[str, Message]) -> tuple[int, typing.Union[str, Message], str]:
|
831 |
|
832 |
"""
|
833 |
+
|
834 |
+
Handles the translation requests for the specified service.
|
835 |
|
836 |
Parameters:
|
837 |
+
model (string) : The model of the service used to translate the text.
|
838 |
+
index (int) : The index of the translation batch.
|
839 |
+
length (int) : The length of the translation batch.
|
840 |
+
translation_instructions (typing.Union[str, Message]) : The translation instructions.
|
841 |
+
translation_prompt (typing.Union[str, Message]) : The translation prompt.
|
842 |
|
843 |
Returns:
|
844 |
+
index (int) : The index of the translation batch.
|
845 |
+
translation_prompt (typing.Union[str, Message]) : The translation prompt.
|
846 |
+
translated_message (str) : The translated message.
|
847 |
|
848 |
"""
|
849 |
|
|
|
1002 |
|
1003 |
"""
|
1004 |
|
1005 |
+
Fixes the J->E text to be more j-e checker friendly.
|
1006 |
|
1007 |
Note that fix_je() is not always accurate, and may use standard j-e formatting instead of the corrected formatting.
|
1008 |
|
modules/common/exceptions.py
CHANGED
@@ -3,6 +3,7 @@
|
|
3 |
## for importing, other scripts will use from common.exceptions instead of from the third-party libraries themselves
|
4 |
from openai import AuthenticationError, InternalServerError, RateLimitError, APITimeoutError
|
5 |
from deepl.exceptions import AuthorizationException, QuotaExceededException
|
|
|
6 |
|
7 |
##-------------------start-of-MaxBatchDurationExceededException--------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
8 |
|
|
|
3 |
## for importing, other scripts will use from common.exceptions instead of from the third-party libraries themselves
|
4 |
from openai import AuthenticationError, InternalServerError, RateLimitError, APITimeoutError
|
5 |
from deepl.exceptions import AuthorizationException, QuotaExceededException
|
6 |
+
from google.auth.exceptions import GoogleAuthError
|
7 |
|
8 |
##-------------------start-of-MaxBatchDurationExceededException--------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
9 |
|
modules/common/file_ensurer.py
CHANGED
@@ -80,14 +80,14 @@ class FileEnsurer():
|
|
80 |
"openai_model": "gpt-4",
|
81 |
"openai_system_message": "As a Japanese to English translator, translate narration into English simple past, everything else should remain in its original tense. Maintain original formatting, punctuation, and paragraph structure. Keep pre-translated terms and anticipate names not replaced. Preserve terms and markers marked with >>><<< and match the output's line count to the input's. Note: 〇 indicates chapter changes.",
|
82 |
"openai_temperature": 0.3,
|
83 |
-
"openai_top_p": 1,
|
84 |
"openai_n": 1,
|
85 |
"openai_stream": False,
|
86 |
"openai_stop": None,
|
87 |
"openai_logit_bias": None,
|
88 |
"openai_max_tokens": None,
|
89 |
-
"openai_presence_penalty": 0,
|
90 |
-
"openai_frequency_penalty": 0
|
91 |
},
|
92 |
|
93 |
"gemini settings": {
|
|
|
80 |
"openai_model": "gpt-4",
|
81 |
"openai_system_message": "As a Japanese to English translator, translate narration into English simple past, everything else should remain in its original tense. Maintain original formatting, punctuation, and paragraph structure. Keep pre-translated terms and anticipate names not replaced. Preserve terms and markers marked with >>><<< and match the output's line count to the input's. Note: 〇 indicates chapter changes.",
|
82 |
"openai_temperature": 0.3,
|
83 |
+
"openai_top_p": 1.0,
|
84 |
"openai_n": 1,
|
85 |
"openai_stream": False,
|
86 |
"openai_stop": None,
|
87 |
"openai_logit_bias": None,
|
88 |
"openai_max_tokens": None,
|
89 |
+
"openai_presence_penalty": 0.0,
|
90 |
+
"openai_frequency_penalty": 0.0
|
91 |
},
|
92 |
|
93 |
"gemini settings": {
|
modules/common/toolkit.py
CHANGED
@@ -7,13 +7,14 @@ import platform
|
|
7 |
import subprocess
|
8 |
|
9 |
class Toolkit():
|
|
|
10 |
"""
|
11 |
|
12 |
A class containing various functions that are used throughout Kudasai.
|
13 |
|
14 |
"""
|
15 |
|
16 |
-
CURRENT_VERSION = "v3.4.0-
|
17 |
|
18 |
##-------------------start-of-clear_console()---------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
19 |
|
@@ -228,7 +229,7 @@ class Toolkit():
|
|
228 |
"""
|
229 |
|
230 |
if(is_archival):
|
231 |
-
time_stamp = datetime.now().strftime("%Y-%m-%
|
232 |
|
233 |
else:
|
234 |
time_stamp = "[" + datetime.now().strftime("%Y-%m-%d %H:%M:%S") + "] "
|
|
|
7 |
import subprocess
|
8 |
|
9 |
class Toolkit():
|
10 |
+
|
11 |
"""
|
12 |
|
13 |
A class containing various functions that are used throughout Kudasai.
|
14 |
|
15 |
"""
|
16 |
|
17 |
+
CURRENT_VERSION = "v3.4.0-beta"
|
18 |
|
19 |
##-------------------start-of-clear_console()---------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
20 |
|
|
|
229 |
"""
|
230 |
|
231 |
if(is_archival):
|
232 |
+
time_stamp = datetime.now().strftime("%Y-%m-%d_%H-%M-%S")
|
233 |
|
234 |
else:
|
235 |
time_stamp = "[" + datetime.now().strftime("%Y-%m-%d %H:%M:%S") + "] "
|
webgui.py
CHANGED
The diff for this file is too large to render.
See raw diff
|
|