توليد المحتوى باستخدام نماذج اللغة الكبيرة (LLM)

توليد المحتوى باستخدام نماذج اللغة الكبيرة (LLM)

مقدمة

يمكن استخدام نماذج اللغة لتوليد أنواع مختلفة من المحتوى بطريقة آلية وإبداعية. يستعرض هذا الدرس الطرق المختلفة لاستخدام LLM في إنشاء المحتوى.

أنواع المحتوى القابلة للتوليد

1. المحتوى التسويقي

2. المحتوى التقني

3. المحتوى الإبداعي

التنفيذ

1. مولّد المحتوى الأساسي

from openai import OpenAI
import json

class ContentGenerator:
    def __init__(self, api_key):
        self.client = OpenAI(api_key=api_key)
    
    def generate_content(self, content_type, parameters):
        prompt = self._create_prompt(content_type, parameters)
        
        response = self.client.chat.completions.create(
            model="gpt-3.5-turbo",
            messages=[
                {"role": "system", "content": "Tu es un expert en création de contenu."},
                {"role": "user", "content": prompt}
            ],
            temperature=0.7
        )
        
        return response.choices[0].message.content
    
    def _create_prompt(self, content_type, parameters):
        prompts = {
            "blog_post": """
                Crée un article de blog sur le sujet suivant :
                Sujet : {topic}
                Ton : {tone}
                Longueur : {length} mots
                Public cible : {target_audience}
                
                Structure :
                1. Introduction accrocheuse
                2. Points principaux
                3. Exemples et illustrations
                4. Conclusion
                """,
            
            "social_media": """
                Crée un post pour {platform} sur le sujet suivant :
                Sujet : {topic}
                Ton : {tone}
                Hashtags : {hashtags}
                Longueur maximale : {max_length} caractères
                """,
            
            "product_description": """
                Crée une description de produit pour :
                Produit : {product_name}
                Caractéristiques : {features}
                Public cible : {target_audience}
                Ton : {tone}
                
                Inclus :
                1. Titre accrocheur
                2. Description principale
                3. Points clés
                4. Call-to-action
                """
        }
        
        return prompts[content_type].format(**parameters)