JSON Writer Style Guide
2024-11-102 turns17,714 charso1-preview
Summary
rewrite prompt to load json objects with pydantic and store in django database
Messages
Rewrite the following prompt so that you can load JSON objects like pydantic to fill in the values from the keys, also write a guide on how I can store those values in a database using models.py in Django:
prompt = f"""
You are an AI language model tasked with writing content that emulates the writing style and personality of a writer with the following characteristics:
**Personal Information:**
- **Name:** {name}
- **Age:** {age}
- **Gender:** {gender}
- **Education Level:** {education_level}
- **Professional Background:** {professional_background}
- **Cultural Background:** {cultural_background}
- **Primary Language:** {primary_language}
- **Language Fluency:** {language_fluency}
- **Background:** {background}
**Writing Style Parameters:**
- **Vocabulary Complexity:** {vocabulary_complexity}
- **Sentence Structure:** {sentence_structure}
- **Paragraph Organization:** {paragraph_organization}
- **Idiom Usage:** {idiom_usage}
- **Metaphor Frequency:** {metaphor_frequency}
- **Simile Frequency:** {simile_frequency}
- **Tone:** {tone}
- **Punctuation Style:** {punctuation_style}
- **Contraction Usage:** {contraction_usage}
- **Pronoun Preference:** {pronoun_preference}
- **Passive Voice Frequency:** {passive_voice_frequency}
- **Rhetorical Question Usage:** {rhetorical_question_usage}
- **List Usage Tendency:** {list_usage_tendency}
- **Personal Anecdote Inclusion:** {personal_anecdote_inclusion}
- **Pop Culture Reference Frequency:** {pop_culture_reference_frequency}
- **Technical Jargon Usage:** {technical_jargon_usage}
- **Parenthetical Aside Frequency:** {parenthetical_aside_frequency}
- **Humor/Sarcasm Usage:** {humor_sarcasm_usage}
- **Emotional Expressiveness:** {emotional_expressiveness}
- **Emphatic Device Usage:** {emphatic_device_usage}
- **Quotation Frequency:** {quotation_frequency}
- **Analogy Usage:** {analogy_usage}
- **Sensory Detail Inclusion:** {sensory_detail_inclusion}
- **Onomatopoeia Usage:** {onomatopoeia_usage}
- **Alliteration Frequency:** {alliteration_frequency}
- **Word Length Preference:** {word_length_preference}
- **Foreign Phrase Usage:** {foreign_phrase_usage}
- **Rhetorical Device Usage:** {rhetorical_device_usage}
- **Statistical Data Usage:** {statistical_data_usage}
- **Personal Opinion Inclusion:** {personal_opinion_inclusion}
- **Transition Usage:** {transition_usage}
- **Reader Question Frequency:** {reader_question_frequency}
- **Imperative Sentence Usage:** {imperative_sentence_usage}
- **Dialogue Inclusion:** {dialogue_inclusion}
- **Regional Dialect Usage:** {regional_dialect_usage}
- **Hedging Language Frequency:** {hedging_language_frequency}
- **Language Abstraction:** {language_abstraction}
- **Personal Belief Inclusion:** {personal_belief_inclusion}
- **Repetition Usage:** {repetition_usage}
- **Subordinate Clause Frequency:** {subordinate_clause_frequency}
- **Verb Type Preference:** {verb_type_preference}
- **Sensory Imagery Usage:** {sensory_imagery_usage}
- **Symbolism Usage:** {symbolism_usage}
- **Digression Frequency:** {digression_frequency}
- **Formality Level:** {formality_level}
- **Reflection Inclusion:** {reflection_inclusion}
- **Irony Usage:** {irony_usage}
- **Neologism Frequency:** {neologism_frequency}
- **Ellipsis Usage:** {ellipsis_usage}
- **Cultural Reference Inclusion:** {cultural_reference_inclusion}
- **Stream of Consciousness Usage:** {stream_of_consciousness_usage}
**Psychological Traits:**
- **Openness to Experience:** {openness_to_experience}
- **Conscientiousness:** {conscientiousness}
- **Extraversion:** {extraversion}
- **Agreeableness:** {agreeableness}
- **Emotional Stability:** {emotional_stability}
- **Dominant Motivations:** {dominant_motivations}
- **Core Values:** {core_values}
- **Decision-Making Style:** {decision_making_style}
- **Empathy Level:** {empathy_level}
- **Self-Confidence:** {self_confidence}
- **Risk-Taking Tendency:** {risk_taking_tendency}
- **Idealism vs. Realism:** {idealism_vs_realism}
- **Conflict Resolution Style:** {conflict_resolution_style}
- **Relationship Orientation:** {relationship_orientation}
- **Emotional Response Tendency:** {emotional_response_tendency}
- **Creativity Level:** {creativity_level}
**Task:**
Based on the above characteristics, Rewrite the following text after the instructions. The content should reflect the writing style and personality traits described, incorporating the specified stylistic elements and psychological traits. Ensure the writing is coherent, engaging, and provides insight into the topic from the perspective of the described writer.
**Instructions:**
- Use the specified vocabulary complexity and sentence structures.
- Organize paragraphs according to the given style.
- Incorporate idioms, metaphors, similes, and other rhetorical devices as indicated.
- Adjust tone, punctuation, and formality to match the described preferences.
- Reflect the psychological traits in the writing, showcasing the writer's motivations, values, and personality.
- Ensure that the content is original and adheres to all content policies.
text:
"""
**Rewritten Prompt:**
```plaintext
You are an AI language model tasked with writing content that emulates the writing style and personality of a writer described in the JSON object below.
**Writer Profile JSON:**
{
"personal_information": {
"name": "John Doe",
"age": 35,
"gender": "Male",
"education_level": "Master's Degree in Literature",
"professional_background": "Journalist and Novelist",
"cultural_background": "Western European",
"primary_language": "English",
"language_fluency": "Native",
"background": "Grew up in a small coastal town."
},
"writing_style_parameters": {
"vocabulary_complexity": "High",
"sentence_structure": "Complex",
"paragraph_organization": "Logical progression",
"idiom_usage": "Frequent",
"metaphor_frequency": "Moderate",
"simile_frequency": "Low",
"tone": "Formal",
"punctuation_style": "Standard",
"contraction_usage": "Minimal",
"pronoun_preference": "Third person",
"passive_voice_frequency": "Occasional",
"rhetorical_question_usage": "Rare",
"list_usage_tendency": "Moderate",
"personal_anecdote_inclusion": "Occasional",
"pop_culture_reference_frequency": "Low",
"technical_jargon_usage": "Subject-specific",
"parenthetical_aside_frequency": "Moderate",
"humor_sarcasm_usage": "Subtle humor",
"emotional_expressiveness": "Controlled",
"emphatic_device_usage": "Moderate",
"quotation_frequency": "Occasional",
"analogy_usage": "Frequent",
"sensory_detail_inclusion": "High",
"onomatopoeia_usage": "Rare",
"alliteration_frequency": "Occasional",
"word_length_preference": "Long",
"foreign_phrase_usage": "Occasional",
"rhetorical_device_usage": "High",
"statistical_data_usage": "Minimal",
"personal_opinion_inclusion": "Moderate",
"transition_usage": "Frequent",
"reader_question_frequency": "Rare",
"imperative_sentence_usage": "Minimal",
"dialogue_inclusion": "Rare",
"regional_dialect_usage": "Minimal",
"hedging_language_frequency": "Occasional",
"language_abstraction": "High",
"personal_belief_inclusion": "Moderate",
"repetition_usage": "Occasional",
"subordinate_clause_frequency": "High",
"verb_type_preference": "Active",
"sensory_imagery_usage": "High",
"symbolism_usage": "Frequent",
"digression_frequency": "Minimal",
"formality_level": "High",
"reflection_inclusion": "Frequent",
"irony_usage": "Subtle",
"neologism_frequency": "Rare",
"ellipsis_usage": "Minimal",
"cultural_reference_inclusion": "Occasional",
"stream_of_consciousness_usage": "Minimal"
},
"psychological_traits": {
"openness_to_experience": "High",
"conscientiousness": "High",
"extraversion": "Moderate",
"agreeableness": "High",
"emotional_stability": "High",
"dominant_motivations": "Achievement, Knowledge",
"core_values": "Integrity, Excellence",
"decision_making_style": "Analytical",
"empathy_level": "High",
"self_confidence": "High",
"risk_taking_tendency": "Moderate",
"idealism_vs_realism": "Realism",
"conflict_resolution_style": "Collaborative",
"relationship_orientation": "Interdependent",
"emotional_response_tendency": "Measured",
"creativity_level": "High"
}
}
**Task:**
Based on the above characteristics, rewrite the following text after the instructions. The content should reflect the writing style and personality traits described, incorporating the specified stylistic elements and psychological traits. Ensure the writing is coherent, engaging, and provides insight into the topic from the perspective of the described writer.
**Instructions:**
- Use the specified vocabulary complexity and sentence structures.
- Organize paragraphs according to the given style.
- Incorporate idioms, metaphors, similes, and other rhetorical devices as indicated.
- Adjust tone, punctuation, and formality to match the described preferences.
- Reflect the psychological traits in the writing, showcasing the writer's motivations, values, and personality.
- Ensure that the content is original and adheres to all content policies.
**Text to be rewritten:**
*Place the text here.*
```
---
**Guide on Storing Values in a Database Using `models.py` in Django:**
To store the values from the JSON object into a Django database, follow these steps:
1. **Define Django Models:**
In your `models.py` file, define models that match the structure of your JSON data.
```python
# models.py
from django.db import models
class PersonalInformation(models.Model):
name = models.CharField(max_length=255)
age = models.IntegerField()
gender = models.CharField(max_length=50)
education_level = models.CharField(max_length=255)
professional_background = models.TextField()
cultural_background = models.TextField()
primary_language = models.CharField(max_length=100)
language_fluency = models.CharField(max_length=100)
background = models.TextField()
def __str__(self):
return self.name
class WritingStyleParameters(models.Model):
vocabulary_complexity = models.CharField(max_length=50)
sentence_structure = models.CharField(max_length=50)
paragraph_organization = models.CharField(max_length=100)
idiom_usage = models.CharField(max_length=50)
metaphor_frequency = models.CharField(max_length=50)
# Add all other fields similarly...
def __str__(self):
return f"Writing Style Parameters for {self.id}"
class PsychologicalTraits(models.Model):
openness_to_experience = models.CharField(max_length=50)
conscientiousness = models.CharField(max_length=50)
extraversion = models.CharField(max_length=50)
# Add all other fields similarly...
def __str__(self):
return f"Psychological Traits for {self.id}"
class WriterProfile(models.Model):
personal_information = models.OneToOneField(PersonalInformation, on_delete=models.CASCADE)
writing_style_parameters = models.OneToOneField(WritingStyleParameters, on_delete=models.CASCADE)
psychological_traits = models.OneToOneField(PsychologicalTraits, on_delete=models.CASCADE)
def __str__(self):
return f"Writer Profile for {self.personal_information.name}"
```
2. **Create and Apply Migrations:**
Run the following commands to create and apply migrations:
```bash
python manage.py makemigrations
python manage.py migrate
```
3. **Parse JSON Data:**
Load and parse your JSON data. If your JSON data is in a file or a string, you can use Python's built-in `json` module.
```python
import json
# If the JSON data is in a string
json_data = '''{
"personal_information": { ... },
"writing_style_parameters": { ... },
"psychological_traits": { ... }
}'''
data = json.loads(json_data)
```
4. **Save Data to Database:**
Map the parsed JSON data to your Django models and save them to the database.
```python
# Assuming you are in a Django view or script where models are accessible
from .models import PersonalInformation, WritingStyleParameters, PsychologicalTraits, WriterProfile
# Save Personal Information
personal_info_data = data['personal_information']
personal_info = PersonalInformation.objects.create(
name=personal_info_data['name'],
age=personal_info_data['age'],
gender=personal_info_data['gender'],
education_level=personal_info_data['education_level'],
professional_background=personal_info_data['professional_background'],
cultural_background=personal_info_data['cultural_background'],
primary_language=personal_info_data['primary_language'],
language_fluency=personal_info_data['language_fluency'],
background=personal_info_data['background']
)
# Save Writing Style Parameters
writing_style_data = data['writing_style_parameters']
writing_style = WritingStyleParameters.objects.create(
vocabulary_complexity=writing_style_data['vocabulary_complexity'],
sentence_structure=writing_style_data['sentence_structure'],
paragraph_organization=writing_style_data['paragraph_organization'],
idiom_usage=writing_style_data['idiom_usage'],
metaphor_frequency=writing_style_data['metaphor_frequency'],
# Add all other fields...
)
# Save Psychological Traits
psychological_traits_data = data['psychological_traits']
psychological_traits = PsychologicalTraits.objects.create(
openness_to_experience=psychological_traits_data['openness_to_experience'],
conscientiousness=psychological_traits_data['conscientiousness'],
extraversion=psychological_traits_data['extraversion'],
# Add all other fields...
)
# Create Writer Profile
writer_profile = WriterProfile.objects.create(
personal_information=personal_info,
writing_style_parameters=writing_style,
psychological_traits=psychological_traits
)
```
5. **Use Pydantic for Data Validation (Optional):**
If you want to validate your JSON data before saving it to the database, you can use Pydantic.
```python
from pydantic import BaseModel, ValidationError
class PersonalInformationModel(BaseModel):
name: str
age: int
gender: str
education_level: str
professional_background: str
cultural_background: str
primary_language: str
language_fluency: str
background: str
class WritingStyleParametersModel(BaseModel):
vocabulary_complexity: str
sentence_structure: str
# Add all other fields...
class PsychologicalTraitsModel(BaseModel):
openness_to_experience: str
# Add all other fields...
class WriterProfileModel(BaseModel):
personal_information: PersonalInformationModel
writing_style_parameters: WritingStyleParametersModel
psychological_traits: PsychologicalTraitsModel
# Validate JSON data
try:
writer_profile_data = WriterProfileModel(**data)
except ValidationError as e:
print(e.json())
# Handle validation errors
else:
# Data is valid, proceed to save to the database
# Map writer_profile_data to your Django models as shown earlier
pass
```
6. **Register Models in Admin (Optional):**
To manage your data through the Django admin interface, register your models in `admin.py`.
```python
# admin.py
from django.contrib import admin
from .models import PersonalInformation, WritingStyleParameters, PsychologicalTraits, WriterProfile
admin.site.register(PersonalInformation)
admin.site.register(WritingStyleParameters)
admin.site.register(PsychologicalTraits)
admin.site.register(WriterProfile)
```
7. **Testing:**
Ensure you test the entire flow:
- Load JSON data.
- Validate using Pydantic (if used).
- Save to the database.
- Retrieve and display data as needed.
8. **Considerations:**
- **Field Types:** Adjust field types in your models to match the data (e.g., use `TextField` for longer text).
- **Null and Blank Values:** Use `null=True` and `blank=True` in model fields if some data might be missing.
- **Data Integrity:** Ensure that the data you're saving is clean and doesn't violate any database constraints.
9. **Example View Function:**
```python
# views.py
from django.shortcuts import render
from django.http import HttpResponse
from .models import PersonalInformation, WritingStyleParameters, PsychologicalTraits, WriterProfile
import json
def save_writer_profile(request):
if request.method == 'POST':
json_data = request.body.decode('utf-8')
data = json.loads(json_data)
# Proceed with data validation and saving as shown earlier
return HttpResponse('Writer profile saved successfully.')
else:
return HttpResponse('Invalid request.')
```
10. **Advanced Usage:**
- **Bulk Create:** If you're handling multiple profiles, consider using `bulk_create` for efficiency.
- **Transactions:** Use database transactions to ensure data integrity when creating related objects.
- **Asynchronous Tasks:** For large datasets, you might offload the processing to a background task using Celery.
**By following these steps, you can successfully parse a JSON object containing a writer's characteristics and store the data in your Django application's database using `models.py`.**
o1-preview