def generate_syllabus()

in glan-instruct/glan.py [0:0]


def generate_syllabus(subject, level, subtopics, max_number_of_session_name=5, model_name="gpt-4o", **kwargs):
    """
    Generate a syllabus for a given subject at a specific level. Please refer to section 2.3 of the paper.
    """
    prompt = f"""
    You are an expert in creating educational syllabi. Create a detailed syllabus for the subject "{subject}" at the {level} level. 
    The syllabus should be broken down into multiple class sessions, each covering different key concepts. 
    The subtopics for this subject include: {subtopics}. Provide the syllabus in JSON format with the following structure in JSON format:

    {{    
        "syllabus": [
            {{
                "session_name": "Session 1 Name",
                "description": "Brief description of the session",
                "key_concepts": ["Key concept 1", "Key concept 2", ...]
            }},
            ...
        ]
    }} 
    Limit the number of `session_name` to a maximum of {max_number_of_session_name}.      
    """
    t0 = time.time()
    response = client.chat.completions.create(
        model=model_name,
        messages=[{"role": "user", "content": prompt}],
        response_format = {'type': "json_object"},
        **kwargs    
    )

    output = response.choices[0].message.content.strip()
    #logger.info(textwrap.indent(output, '\t'))
    
    try:
        syllabus_json = json.loads(output)
        key = next(iter(syllabus_json))
        syllabus = syllabus_json[key]
    except json.JSONDecodeError:
        logger.error("Failed to parse JSON")
        return None, None

    # Extract class details
    class_sessions = [session['session_name'] for session in syllabus]
    key_concepts = [session['key_concepts'] for session in syllabus]
    t1 = time.time()
    logger.info(f"\tGenerating syllabus took {t1 - t0:.4f} seconds.")

    return class_sessions, key_concepts