bakrianoo commited on
Commit
e39d0f6
·
1 Parent(s): c25ce6b

update the llm parser with json repair

Browse files
Files changed (3) hide show
  1. app.py +7 -0
  2. requirements.txt +1 -0
  3. utils/llm_prompts.py +1 -1
app.py CHANGED
@@ -3,6 +3,7 @@ from utils import (extract_wiki_id, get_wiki_details,
3
  init_llm_client, split_content_into_sections,
4
  get_translate_prompt)
5
  import json
 
6
 
7
  # Define language options for translation
8
  LANGUAGES = {
@@ -62,6 +63,12 @@ def translate_content(content, article_title, artice_summary, target_lang, api_k
62
  temperature=0.5
63
  )
64
 
 
 
 
 
 
 
65
  def update_ui_with_sections(sections_dict):
66
  """
67
  Creates a list of components to display in the sections area
 
3
  init_llm_client, split_content_into_sections,
4
  get_translate_prompt)
5
  import json
6
+ import json_repair
7
 
8
  # Define language options for translation
9
  LANGUAGES = {
 
63
  temperature=0.5
64
  )
65
 
66
+ decoded_object = json_repair.loads(response.choices[0].message['content'])
67
+ if 'output_content' in decoded_object:
68
+ return decoded_object['output_content']
69
+
70
+ return "Error: Translation output not found in the response."
71
+
72
  def update_ui_with_sections(sections_dict):
73
  """
74
  Creates a list of components to display in the sections area
requirements.txt CHANGED
@@ -1,3 +1,4 @@
1
  gradio==5.29.1
2
  wikipedia==1.4.0
3
  openai==1.78.1
 
 
1
  gradio==5.29.1
2
  wikipedia==1.4.0
3
  openai==1.78.1
4
+ json-repair==0.44.1
utils/llm_prompts.py CHANGED
@@ -37,7 +37,7 @@ def get_translate_prompt(article_title, artice_summary, original_content, target
37
  "Return a single JSON object with the following structure:\n"
38
  "```json\n" +
39
  json.dumps({
40
- "translated_content": "The complete translated XML content with all tags preserved",
41
  }, indent=4, ensure_ascii=False) +
42
  "\n```\n\n"
43
 
 
37
  "Return a single JSON object with the following structure:\n"
38
  "```json\n" +
39
  json.dumps({
40
+ "output_content": "The complete translated XML content with all tags preserved",
41
  }, indent=4, ensure_ascii=False) +
42
  "\n```\n\n"
43