bakrianoo commited on
Commit
186544d
·
1 Parent(s): 571e415

pass preference prompt

Browse files
Files changed (2) hide show
  1. app.py +15 -3
  2. utils/llm_prompts.py +22 -4
app.py CHANGED
@@ -54,7 +54,7 @@ def extract_wikipedia_content(wiki_url, api_key, model_id, base_url, target_lang
54
  )
55
 
56
  def translate_content(content, article_title, artice_summary, content_format,
57
- target_lang, api_key, model_id, base_url, debug_mode=False):
58
 
59
  llm_client = init_llm_client(api_key, base_url=base_url)
60
 
@@ -65,7 +65,8 @@ def translate_content(content, article_title, artice_summary, content_format,
65
  artice_summary=artice_summary,
66
  original_content=content,
67
  target_lang=target_lang,
68
- content_format=content_format
 
69
  )
70
 
71
  # Call the LLM to get the translation - updating params to match OpenAI's requirements
@@ -104,7 +105,7 @@ def translate_content(content, article_title, artice_summary, content_format,
104
  return "Error: Translation output not found in the response."
105
 
106
  def translate_section(section_content, article_title, article_summary, content_format,
107
- target_lang, custom_lang, api_key, model_id, base_url, debug_mode=False):
108
  """
109
  Translates a single section of the Wikipedia article
110
  """
@@ -126,6 +127,7 @@ def translate_section(section_content, article_title, article_summary, content_f
126
  api_key=api_key,
127
  model_id=model_id,
128
  base_url=base_url,
 
129
  debug_mode=debug_mode
130
  )
131
 
@@ -281,6 +283,15 @@ with gr.Blocks(theme=gr.themes.Monochrome()) as demo:
281
  value=False,
282
  info="Show detailed information about LLM calls"
283
  )
 
 
 
 
 
 
 
 
 
284
 
285
  gr.Markdown("### About")
286
  gr.Markdown("""
@@ -370,6 +381,7 @@ with gr.Blocks(theme=gr.themes.Monochrome()) as demo:
370
  api_key,
371
  model_id,
372
  base_url,
 
373
  debug_mode
374
  ],
375
  outputs=[translation_output, debug_info_state]
 
54
  )
55
 
56
  def translate_content(content, article_title, artice_summary, content_format,
57
+ target_lang, api_key, model_id, base_url, preference_prompt=None, debug_mode=False):
58
 
59
  llm_client = init_llm_client(api_key, base_url=base_url)
60
 
 
65
  artice_summary=artice_summary,
66
  original_content=content,
67
  target_lang=target_lang,
68
+ content_format=content_format,
69
+ preference_prompt=preference_prompt
70
  )
71
 
72
  # Call the LLM to get the translation - updating params to match OpenAI's requirements
 
105
  return "Error: Translation output not found in the response."
106
 
107
  def translate_section(section_content, article_title, article_summary, content_format,
108
+ target_lang, custom_lang, api_key, model_id, base_url, preference_prompt=None, debug_mode=False):
109
  """
110
  Translates a single section of the Wikipedia article
111
  """
 
127
  api_key=api_key,
128
  model_id=model_id,
129
  base_url=base_url,
130
+ preference_prompt=preference_prompt,
131
  debug_mode=debug_mode
132
  )
133
 
 
283
  value=False,
284
  info="Show detailed information about LLM calls"
285
  )
286
+
287
+ # Add preference prompt section
288
+ gr.Markdown("### Translation Preferences")
289
+ preference_prompt = gr.Textbox(
290
+ label="Additional Translation Preferences",
291
+ placeholder="Enter any specific translation preferences or instructions...",
292
+ lines=5,
293
+ info="Optional: Add specific preferences for how the translation should be performed"
294
+ )
295
 
296
  gr.Markdown("### About")
297
  gr.Markdown("""
 
381
  api_key,
382
  model_id,
383
  base_url,
384
+ preference_prompt, # Add preference prompt to inputs
385
  debug_mode
386
  ],
387
  outputs=[translation_output, debug_info_state]
utils/llm_prompts.py CHANGED
@@ -1,9 +1,17 @@
1
  import json
2
 
3
- def get_translate_prompt(article_title, artice_summary, content_format, original_content, target_lang):
4
  """
5
  Function to get the translation prompt for the LLM to translate Wikipedia {content_format} content
6
  with high quality and fidelity to the original.
 
 
 
 
 
 
 
 
7
  """
8
  # Define the prompt template
9
  translate_prompt = (
@@ -31,9 +39,19 @@ def get_translate_prompt(article_title, artice_summary, content_format, original
31
  "4. Preserve proper nouns, scientific terminology, and citations appropriately\n"
32
  "5. Adapt cultural references or idioms to be understandable in the target language\n"
33
  "6. Use terminology consistent with the {target_lang} Wikipedia for similar topics\n"
34
- "7. Maintain the same paragraph structure and information hierarchy\n\n"
35
-
36
- "# Output Format\n"
 
 
 
 
 
 
 
 
 
 
37
  "Return a single JSON object with the following structure:\n"
38
  "```json\n"
39
  "{{\n"
 
1
  import json
2
 
3
+ def get_translate_prompt(article_title, artice_summary, content_format, original_content, target_lang, preference_prompt=None):
4
  """
5
  Function to get the translation prompt for the LLM to translate Wikipedia {content_format} content
6
  with high quality and fidelity to the original.
7
+
8
+ Args:
9
+ article_title: Title of the Wikipedia article
10
+ artice_summary: Summary of the Wikipedia article
11
+ content_format: Format of the content (e.g., XML, Text)
12
+ original_content: The content to be translated
13
+ target_lang: The target language for translation
14
+ preference_prompt: Optional additional user preferences for translation
15
  """
16
  # Define the prompt template
17
  translate_prompt = (
 
39
  "4. Preserve proper nouns, scientific terminology, and citations appropriately\n"
40
  "5. Adapt cultural references or idioms to be understandable in the target language\n"
41
  "6. Use terminology consistent with the {target_lang} Wikipedia for similar topics\n"
42
+ "7. Maintain the same paragraph structure and information hierarchy\n"
43
+ )
44
+
45
+ # Add user preference prompt if provided
46
+ if preference_prompt and preference_prompt.strip():
47
+ translate_prompt += (
48
+ "\n# Additional Translation Preferences\n"
49
+ f"{preference_prompt}\n"
50
+ )
51
+
52
+ # Add the output format section
53
+ translate_prompt += (
54
+ "\n# Output Format\n"
55
  "Return a single JSON object with the following structure:\n"
56
  "```json\n"
57
  "{{\n"