|
1. Read |
|
```Python |
|
import json |
|
|
|
def parse_json_file(file_path): |
|
with open(file_path, 'r') as file: |
|
data = json.load(file) |
|
|
|
# Group results by used_addon |
|
addons = {} |
|
for item in data['results']: |
|
addon = item.get('used_addon', 'None') |
|
if addon not in addons: |
|
addons[addon] = 0 |
|
addons[addon] += 1 |
|
|
|
return addons |
|
|
|
file_path = '/raid/vladimir_albrekht/projects/data_temp/results_batch_5_fine_web_edu.json' |
|
addon_counts = parse_json_file(file_path) |
|
|
|
for addon, count in addon_counts.items(): |
|
print(f"Used addon: {addon} - Count: {count}") |
|
``` |
|
|
|
2. To word |
|
```Python |
|
import json |
|
from docx import Document |
|
from docx.shared import Inches |
|
|
|
def extract_examples(file_path, output_file_path): |
|
with open(file_path, 'r') as file: |
|
data = json.load(file) |
|
|
|
primary_addons = [ |
|
"Make output from 'gpt' larger as possible 5000 tokens minimum in one value", |
|
"Use шалақазақ style where appropriate, keeping Russian words for technical terms." |
|
] |
|
|
|
other_addons = [ |
|
"Mark important information with emojis", |
|
"Add similar to this question in the end of each value 'If you want to know more about this topic, please ask me!', but in Kazakh and in different versions", |
|
"Ask first question in English, but other values and question keep in Kazakh", |
|
"Break down complex concepts into simpler terms.", |
|
"Include a practical application example in one answer.", |
|
"Define key terminology used in the context.", |
|
"Compare and contrast different approaches or methods.", |
|
"Make questions simple", |
|
"Explain the broader impact or significance of the topic.", |
|
"Present contrasting viewpoints in one answer.", |
|
"Include a conclusion in the final answer.", |
|
"Discuss practical implications for different stakeholders.", |
|
"Provide step-by-step explanation in one of your answers.", |
|
"Provide real-world case studies if applicable.", |
|
"Use emotional 😊 emojis in your answers", |
|
"Ask first question in Russian, but other values and question keep in Kazakh", |
|
"Use comparison elements in your answers.", |
|
"Try your best to make it as good as you can and I will pay you 300$", |
|
"Provide at least one specific example in an answer." |
|
] |
|
|
|
# Create Word document |
|
doc = Document() |
|
sections = doc.sections |
|
for section in sections: |
|
section.left_margin = Inches(0.5) |
|
section.right_margin = Inches(0.5) |
|
|
|
# Add table of contents |
|
doc.add_heading("Table of Contents", level=1) |
|
|
|
doc.add_paragraph("Primary Addons:") |
|
for i, addon in enumerate(primary_addons, 1): |
|
p = doc.add_paragraph() |
|
p.paragraph_format.left_indent = Inches(0.5) |
|
p.add_run(f"{i}. {addon}") |
|
|
|
doc.add_paragraph("\nOther Addons:") |
|
for i, addon in enumerate(other_addons, 1): |
|
p = doc.add_paragraph() |
|
p.paragraph_format.left_indent = Inches(0.5) |
|
p.add_run(f"{i}. {addon}") |
|
|
|
doc.add_page_break() |
|
|
|
examples = {addon: [] for addon in primary_addons} |
|
examples.update({addon: [] for addon in other_addons}) |
|
|
|
# Collect examples |
|
for item in data['results']: |
|
addon = item.get('used_addon') |
|
if addon in primary_addons and len(examples[addon]) < 2: |
|
examples[addon].append({ |
|
'text': item.get('text', ''), |
|
'response': item.get('response', ''), |
|
'addon': addon |
|
}) |
|
elif addon in other_addons and len(examples[addon]) < 1: |
|
examples[addon].append({ |
|
'text': item.get('text', ''), |
|
'response': item.get('response', ''), |
|
'addon': addon |
|
}) |
|
|
|
# First add primary addons with 2 examples each |
|
doc.add_heading("PRIMARY ADDONS (2 examples each):", level=1) |
|
for addon in primary_addons: |
|
doc.add_heading(f"Addon: {addon}", level=1) |
|
for i, example in enumerate(examples[addon], 1): |
|
doc.add_heading(f"Example {i}:", level=2) |
|
doc.add_heading("TEXT:", level=3) |
|
doc.add_paragraph(example['text']) |
|
doc.add_heading("RESPONSE:", level=3) |
|
doc.add_paragraph(example['response']) |
|
doc.add_paragraph('=' * 80) |
|
doc.add_page_break() |
|
|
|
# Then add other addons with 1 example each |
|
doc.add_heading("OTHER ADDONS (1 example each):", level=1) |
|
for addon in other_addons: |
|
if examples[addon]: |
|
doc.add_heading(f"Addon: {addon}", level=1) |
|
doc.add_heading("TEXT:", level=2) |
|
doc.add_paragraph(examples[addon][0]['text']) |
|
doc.add_heading("RESPONSE:", level=2) |
|
doc.add_paragraph(examples[addon][0]['response']) |
|
doc.add_paragraph('=' * 80) |
|
doc.add_page_break() |
|
|
|
doc.save(output_file_path) |
|
|
|
# Usage |
|
input_file = '/raid/vladimir_albrekht/projects/data_temp/results_batch_5_fine_web_edu.json' |
|
output_file = 'all_addon_examples.docx' |
|
extract_examples(input_file, output_file) |
|
``` |