From e13b28f689cca3bdc2ea119cc2a35c1588cc5a0c Mon Sep 17 00:00:00 2001 From: Andrew Ellis Date: Thu, 28 Nov 2024 09:23:32 +0100 Subject: [PATCH] Render --- .../example/index/execute-results/html.json | 4 +- docs/projects/anki/example/index.html | 245 +++++++++--------- docs/sitemap.xml | 2 +- 3 files changed, 132 insertions(+), 119 deletions(-) diff --git a/_freeze/projects/anki/example/index/execute-results/html.json b/_freeze/projects/anki/example/index/execute-results/html.json index 2d6c457..853500e 100644 --- a/_freeze/projects/anki/example/index/execute-results/html.json +++ b/_freeze/projects/anki/example/index/execute-results/html.json @@ -1,8 +1,8 @@ { - "hash": "693eaafcd014332b4b1220990dbe7fe8", + "hash": "cf8d119842df88d0a5ec554afd5eb06f", "result": { "engine": "jupyter", - "markdown": "---\ntitle: \"Generate Anki flashcards: example code\"\njupyter: python3\nexecute: \n cache: true\n---\n\n::: {#de27807c .cell execution_count=1}\n``` {.python .cell-code}\nimport os\nimport csv\nfrom dotenv import load_dotenv # For loading environment variables\nfrom openai import OpenAI \n\nfrom pydantic import BaseModel, Field\nfrom typing import List\n```\n:::\n\n\n::: {#2c201188 .cell execution_count=2}\n``` {.python .cell-code}\nload_dotenv()\nclient = OpenAI()\n```\n:::\n\n\n::: {#38f58126 .cell execution_count=3}\n``` {.python .cell-code}\nclass AnkiFlashcard(BaseModel):\n \"\"\"\n Model representing a single Anki flashcard with question, answer, and tags.\n \"\"\"\n # Define required fields with descriptions\n question: str = Field(..., description=\"The front side of the flashcard containing the question\")\n answer: str = Field(..., description=\"The back side of the flashcard containing the answer\")\n tags: List[str] = Field(..., description=\"List of tags associated with the flashcard\")\n```\n:::\n\n\n::: {#571a9bda .cell execution_count=4}\n``` {.python .cell-code}\nclass AnkiDeck(BaseModel):\n \"\"\"\n Model representing a complete Anki deck containing multiple flashcards.\n \"\"\"\n # Define required fields with descriptions\n cards: List[AnkiFlashcard] = Field(..., description=\"List of flashcards in the deck\")\n deck_name: str = Field(..., description=\"Name of the Anki deck\")\n```\n:::\n\n\n::: {#93d3c3f9 .cell execution_count=5}\n``` {.python .cell-code}\ndef generate_structured_flashcards(text: str, \n deck_name: str, \n num_cards: int = 5) -> AnkiDeck:\n \"\"\"\n Generate structured flashcards using GPT-4o with enforced Pydantic model output.\n \n Args:\n text (str): The input text to generate flashcards from\n deck_name (str): Name for the Anki deck\n num_cards (int): Number of flashcards to generate (default: 5)\n \n Returns:\n AnkiDeck: A structured deck of flashcards with proper validation\n \n Raises:\n ValueError: If num_cards is less than 1\n \"\"\"\n # Validate input\n if num_cards < 1:\n raise ValueError(\"Number of cards must be at least 1\")\n \n # Make API call with structured output format\n completion = client.beta.chat.completions.parse(\n model=\"gpt-4o\",\n messages=[\n {\n \"role\": \"system\",\n \"content\": f\"\"\"You are an expert at creating Anki flashcards. Your task is to:\n1. Read the provided text\n2. Create {num_cards} Anki flashcards that cover the main concepts\n3. Add relevant tags to each flashcard\n4. Structure the output as an Anki deck with the name \"{deck_name}\".\"\"\"\n },\n {\n \"role\": \"user\",\n \"content\": f\"Please create Anki flashcards for the following text: {text}\"\n }\n ],\n response_format=AnkiDeck,\n )\n \n # Return the parsed response\n return completion.choices[0].message.parsed\n```\n:::\n\n\n\n\n:::{.callout-note collapse=true title=\"`romantic_text`\"}\n## The Romantic Era: Emotion Unleashed (1810-1910)\n\nThe Romantic era represented a dramatic shift in musical aesthetics, prioritizing emotional expression, individualism, and nationalism over the formal constraints of the Classical period. This century-long period saw an unprecedented expansion in the scope, scale, and emotional range of classical music.\n\n### The Romantic Spirit\n\nRomanticism emerged as a reaction against the rationalism of the Enlightenment and the Industrial Revolution. Composers sought to express intense personal emotions, explore supernatural themes, and celebrate national identity through music. This new aesthetic led to the development of program music - compositions that told specific stories or painted musical pictures.\n\n### Expansion of Musical Language\n\nThe Romantic period saw a significant expansion of harmonic language. Composers pushed the boundaries of chromatic harmony, using increasingly complex chord progressions and modulations to distant keys. This development reached its apex in Wagner's \"Tristan und Isolde,\" whose famous \"Tristan chord\" symbolized the dissolution of traditional tonality.\n\n### The Symphony Transformed\n\nThe symphony, inherited from the Classical era, underwent radical transformation. Beethoven's Ninth Symphony, with its unprecedented scale and inclusion of vocal soloists and chorus, set new standards for symphonic composition. Later composers like Berlioz, Mahler, and Bruckner created symphonies of enormous proportions, both in length and orchestral forces.\n\n### New Forms and Genres\n\nThe period saw the emergence of new musical forms suited to Romantic expression. The symphonic poem, developed by Franz Liszt, combined orchestral music with extra-musical narratives. The art song (Lied) reached new heights of sophistication in the hands of Schubert and Schumann, creating perfect unions of poetry and music.\n\n### Nationalism in Music\n\nNational schools of composition emerged as countries sought to express their cultural identity through music. Russian composers like Tchaikovsky and the \"Mighty Five\" incorporated folk melodies and national themes. Similar movements appeared in Bohemia (Smetana, Dvoล™รกk), Norway (Grieg), and other European nations.\n\n### The Rise of the Virtuoso\n\nThe Romantic era celebrated individual achievement, leading to the rise of the virtuoso performer. Pianists like Liszt and Chopin composed works of unprecedented technical difficulty, while violinists like Paganini pushed the boundaries of what was possible on their instrument. This emphasis on virtuosity influenced compositional style and public performance practices.\n\n### Wagner and Music Drama\n\nRichard Wagner revolutionized opera through his concept of Gesamtkunstwerk (total artwork), combining music, drama, poetry, and visual arts. His use of leitmotifs - recurring musical themes associated with characters, objects, or ideas - influenced not only opera but also symphonic composition and, later, film music.\n\n### Technical and Social Developments\n\nThe period saw significant developments in instrument construction. The modern piano reached its current form, while brass instruments benefited from the invention of valves. Orchestras grew larger, requiring the emergence of the conductor as an interpreter rather than merely a timekeeper.\n\n### The End of an Era\n\nThe Romantic period gradually gave way to various modern movements. The increasing chromatic harmony of late Romanticism led naturally to the breakdown of traditional tonality in the early 20th century. However, Romantic ideals of emotional expression and individualism continued to influence composers well into the modern era.\n\nThe Romantic era's emphasis on emotional expression, its technical innovations, and its expansion of musical possibilities created a legacy that continues to influence musicians today. The period's great works remain central to the concert repertoire, beloved for their emotional depth and expressive power.\n:::\n\n\n\n::: {#b6f029bd .cell execution_count=8}\n``` {.python .cell-code}\nromantic_deck = generate_structured_flashcards(romantic_text,\n \"Romanticism\", \n num_cards=10)\n```\n:::\n\n\n::: {#a6ec19d9 .cell execution_count=9}\n``` {.python .cell-code}\nromantic_deck\n```\n\n::: {.cell-output .cell-output-display execution_count=52}\n```\nAnkiDeck(cards=[AnkiFlashcard(question='What major shift did the Romantic era represent in musical aesthetics?', answer='The Romantic era represented a shift towards prioritizing emotional expression, individualism, and nationalism, moving away from the formal constraints of the Classical period.', tags=['Romanticism', 'MusicAesthetics']), AnkiFlashcard(question='What is program music and how did it relate to Romanticism?', answer=\"Program music is a type of composition that tells specific stories or paints musical pictures, aligned with Romanticism's emphasis on emotional expression and supernatural themes.\", tags=['Romanticism', 'ProgramMusic']), AnkiFlashcard(question='How did harmonic language expand during the Romantic period?', answer='Composers expanded harmonic language by pushing boundaries of chromatic harmony, using complex chord progressions and modulations, exemplified by Wagner\\'s \"Tristan chord.\"', tags=['Romanticism', 'HarmonicLanguage']), AnkiFlashcard(question='Which symphony transformed the symphonic form during the Romantic era?', answer=\"Beethoven's Ninth Symphony transformed the symphonic form with its unprecedented scale and inclusion of vocal soloists and chorus.\", tags=['Romanticism', 'Symphony']), AnkiFlashcard(question='What is a symphonic poem and who developed it?', answer='A symphonic poem is an orchestral work that combines music with extra-musical narratives, developed by Franz Liszt.', tags=['Romanticism', 'MusicalForms']), AnkiFlashcard(question='Which regions developed national schools of composition during the Romantic era?', answer='National schools of composition emerged in Russia, Bohemia, Norway, and other European nations, often incorporating folk melodies and national themes.', tags=['Romanticism', 'Nationalism']), AnkiFlashcard(question='Who were some notable virtuoso performers during the Romantic era?', answer='Notable virtuoso performers included pianists like Liszt and Chopin, and violinists like Paganini, known for their technical achievements.', tags=['Romanticism', 'Virtuosos']), AnkiFlashcard(question='What concept did Wagner introduce in opera, and how did it influence other genres?', answer='Wagner introduced the concept of Gesamtkunstwerk (total artwork) and leitmotifs, influencing opera, symphonic composition, and film music.', tags=['Romanticism', 'Opera']), AnkiFlashcard(question='How did instrument construction and orchestra management change during the Romantic period?', answer='Instruments like the piano and brass instruments evolved; orchestras grew larger, making conductors interpreters rather than merely timekeepers.', tags=['Romanticism', 'Instrumentation']), AnkiFlashcard(question='How did the Romantic era influence later musical movements?', answer='The breakdown of traditional tonality led to modern movements, but Romantic ideals of emotional expression and individualism continued influencing composers.', tags=['Romanticism', 'ModernInfluence'])], deck_name='Romanticism')\n```\n:::\n:::\n\n\n::: {#ae689ec1 .cell execution_count=10}\n``` {.python .cell-code}\nprint(romantic_deck.model_dump_json())\n```\n\n::: {.cell-output .cell-output-stdout}\n```\n{\"cards\":[{\"question\":\"What major shift did the Romantic era represent in musical aesthetics?\",\"answer\":\"The Romantic era represented a shift towards prioritizing emotional expression, individualism, and nationalism, moving away from the formal constraints of the Classical period.\",\"tags\":[\"Romanticism\",\"MusicAesthetics\"]},{\"question\":\"What is program music and how did it relate to Romanticism?\",\"answer\":\"Program music is a type of composition that tells specific stories or paints musical pictures, aligned with Romanticism's emphasis on emotional expression and supernatural themes.\",\"tags\":[\"Romanticism\",\"ProgramMusic\"]},{\"question\":\"How did harmonic language expand during the Romantic period?\",\"answer\":\"Composers expanded harmonic language by pushing boundaries of chromatic harmony, using complex chord progressions and modulations, exemplified by Wagner's \\\"Tristan chord.\\\"\",\"tags\":[\"Romanticism\",\"HarmonicLanguage\"]},{\"question\":\"Which symphony transformed the symphonic form during the Romantic era?\",\"answer\":\"Beethoven's Ninth Symphony transformed the symphonic form with its unprecedented scale and inclusion of vocal soloists and chorus.\",\"tags\":[\"Romanticism\",\"Symphony\"]},{\"question\":\"What is a symphonic poem and who developed it?\",\"answer\":\"A symphonic poem is an orchestral work that combines music with extra-musical narratives, developed by Franz Liszt.\",\"tags\":[\"Romanticism\",\"MusicalForms\"]},{\"question\":\"Which regions developed national schools of composition during the Romantic era?\",\"answer\":\"National schools of composition emerged in Russia, Bohemia, Norway, and other European nations, often incorporating folk melodies and national themes.\",\"tags\":[\"Romanticism\",\"Nationalism\"]},{\"question\":\"Who were some notable virtuoso performers during the Romantic era?\",\"answer\":\"Notable virtuoso performers included pianists like Liszt and Chopin, and violinists like Paganini, known for their technical achievements.\",\"tags\":[\"Romanticism\",\"Virtuosos\"]},{\"question\":\"What concept did Wagner introduce in opera, and how did it influence other genres?\",\"answer\":\"Wagner introduced the concept of Gesamtkunstwerk (total artwork) and leitmotifs, influencing opera, symphonic composition, and film music.\",\"tags\":[\"Romanticism\",\"Opera\"]},{\"question\":\"How did instrument construction and orchestra management change during the Romantic period?\",\"answer\":\"Instruments like the piano and brass instruments evolved; orchestras grew larger, making conductors interpreters rather than merely timekeepers.\",\"tags\":[\"Romanticism\",\"Instrumentation\"]},{\"question\":\"How did the Romantic era influence later musical movements?\",\"answer\":\"The breakdown of traditional tonality led to modern movements, but Romantic ideals of emotional expression and individualism continued influencing composers.\",\"tags\":[\"Romanticism\",\"ModernInfluence\"]}],\"deck_name\":\"Romanticism\"}\n```\n:::\n:::\n\n\n::: {#0098c8a5 .cell execution_count=11}\n``` {.python .cell-code}\nfor card in romantic_deck.cards:\n print(f\"Question: {card.question}\")\n print(f\"Answer: {card.answer}\")\n print(f\"Tags: {', '.join(card.tags)}\")\n print(\"-\" * 20)\n```\n\n::: {.cell-output .cell-output-stdout}\n```\nQuestion: What major shift did the Romantic era represent in musical aesthetics?\nAnswer: The Romantic era represented a shift towards prioritizing emotional expression, individualism, and nationalism, moving away from the formal constraints of the Classical period.\nTags: Romanticism, MusicAesthetics\n--------------------\nQuestion: What is program music and how did it relate to Romanticism?\nAnswer: Program music is a type of composition that tells specific stories or paints musical pictures, aligned with Romanticism's emphasis on emotional expression and supernatural themes.\nTags: Romanticism, ProgramMusic\n--------------------\nQuestion: How did harmonic language expand during the Romantic period?\nAnswer: Composers expanded harmonic language by pushing boundaries of chromatic harmony, using complex chord progressions and modulations, exemplified by Wagner's \"Tristan chord.\"\nTags: Romanticism, HarmonicLanguage\n--------------------\nQuestion: Which symphony transformed the symphonic form during the Romantic era?\nAnswer: Beethoven's Ninth Symphony transformed the symphonic form with its unprecedented scale and inclusion of vocal soloists and chorus.\nTags: Romanticism, Symphony\n--------------------\nQuestion: What is a symphonic poem and who developed it?\nAnswer: A symphonic poem is an orchestral work that combines music with extra-musical narratives, developed by Franz Liszt.\nTags: Romanticism, MusicalForms\n--------------------\nQuestion: Which regions developed national schools of composition during the Romantic era?\nAnswer: National schools of composition emerged in Russia, Bohemia, Norway, and other European nations, often incorporating folk melodies and national themes.\nTags: Romanticism, Nationalism\n--------------------\nQuestion: Who were some notable virtuoso performers during the Romantic era?\nAnswer: Notable virtuoso performers included pianists like Liszt and Chopin, and violinists like Paganini, known for their technical achievements.\nTags: Romanticism, Virtuosos\n--------------------\nQuestion: What concept did Wagner introduce in opera, and how did it influence other genres?\nAnswer: Wagner introduced the concept of Gesamtkunstwerk (total artwork) and leitmotifs, influencing opera, symphonic composition, and film music.\nTags: Romanticism, Opera\n--------------------\nQuestion: How did instrument construction and orchestra management change during the Romantic period?\nAnswer: Instruments like the piano and brass instruments evolved; orchestras grew larger, making conductors interpreters rather than merely timekeepers.\nTags: Romanticism, Instrumentation\n--------------------\nQuestion: How did the Romantic era influence later musical movements?\nAnswer: The breakdown of traditional tonality led to modern movements, but Romantic ideals of emotional expression and individualism continued influencing composers.\nTags: Romanticism, ModernInfluence\n--------------------\n```\n:::\n:::\n\n\n::: {#66b0e2e0 .cell execution_count=12}\n``` {.python .cell-code}\nos.makedirs('assets/flashcards', exist_ok=True)\n\n# Export flashcards to CSV file\nwith open('assets/flashcards/romantic-flashcards.csv', \n 'w', \n newline='',\n encoding='utf-8') as csvfile:\n writer = csv.writer(csvfile)\n # Write header row\n writer.writerow(['Question', 'Answer', 'Tags'])\n # Write each flashcard as a row in the CSV\n for card in romantic_deck.cards:\n writer.writerow([card.question, card.answer, ', '.join(card.tags)])\n```\n:::\n\n\n", + "markdown": "---\ntitle: \"Generate Anki flashcards: example code\"\njupyter: python3\nexecute: \n cache: true\n---\n\n\n\n\nFirst, we import the required libraries:\n\n::: {#de27807c .cell execution_count=2}\n``` {.python .cell-code}\nimport os\nimport csv\nfrom dotenv import load_dotenv # For loading environment variables\nfrom openai import OpenAI \n\nfrom pydantic import BaseModel, Field\nfrom typing import List\n```\n:::\n\n\nInitialize the OpenAI client using environment variables:\n\n::: {#2c201188 .cell execution_count=3}\n``` {.python .cell-code}\nload_dotenv()\nclient = OpenAI()\n```\n:::\n\n\nDefine our data models using Pydantic for type safety and validation:\n\n::: {#38f58126 .cell execution_count=4}\n``` {.python .cell-code}\nclass AnkiFlashcard(BaseModel):\n \"\"\"\n Model representing a single Anki flashcard with question, answer, and tags.\n \"\"\"\n # Define required fields with descriptions\n question: str = Field(..., description=\"The front side of the flashcard containing the question\")\n answer: str = Field(..., description=\"The back side of the flashcard containing the answer\")\n tags: List[str] = Field(..., description=\"List of tags associated with the flashcard\")\n```\n:::\n\n\nCreate a model to represent a complete deck of flashcards:\n\n::: {#571a9bda .cell execution_count=5}\n``` {.python .cell-code}\nclass AnkiDeck(BaseModel):\n \"\"\"\n Model representing a complete Anki deck containing multiple flashcards.\n \"\"\"\n # Define required fields with descriptions\n cards: List[AnkiFlashcard] = Field(..., description=\"List of flashcards in the deck\")\n deck_name: str = Field(..., description=\"Name of the Anki deck\")\n```\n:::\n\n\nDefine the main function that generates flashcards using GPT-4:\n\n::: {#93d3c3f9 .cell execution_count=6}\n``` {.python .cell-code}\ndef generate_structured_flashcards(text: str, \n deck_name: str, \n num_cards: int = 5) -> AnkiDeck:\n \"\"\"\n Generate structured flashcards using GPT-4o with enforced Pydantic model output.\n \n Args:\n text (str): The input text to generate flashcards from\n deck_name (str): Name for the Anki deck\n num_cards (int): Number of flashcards to generate (default: 5)\n \n Returns:\n AnkiDeck: A structured deck of flashcards with proper validation\n \n Raises:\n ValueError: If num_cards is less than 1\n \"\"\"\n # Validate input\n if num_cards < 1:\n raise ValueError(\"Number of cards must be at least 1\")\n \n # Make API call with structured output format\n completion = client.beta.chat.completions.parse(\n model=\"gpt-4o\",\n messages=[\n {\n \"role\": \"system\",\n \"content\": f\"\"\"You are an expert at creating Anki flashcards. Your task is to:\n1. Read the provided text\n2. Create {num_cards} Anki flashcards that cover the main concepts\n3. Add relevant tags to each flashcard\n4. Structure the output as an Anki deck with the name \"{deck_name}\".\"\"\"\n },\n {\n \"role\": \"user\",\n \"content\": f\"Please create Anki flashcards for the following text: {text}\"\n }\n ],\n response_format=AnkiDeck,\n )\n \n # Return the parsed response\n return completion.choices[0].message.parsed\n```\n:::\n\n\nLoad our sample text about the Romantic era from a markdown file:\n\n\n\nDisplay the content of the romantic text (hidden by default):\n\n:::{.callout-note collapse=true title=\"`romantic_text`\"}\n## The Romantic Era: Emotion Unleashed (1810-1910)\n\nThe Romantic era represented a dramatic shift in musical aesthetics, prioritizing emotional expression, individualism, and nationalism over the formal constraints of the Classical period. This century-long period saw an unprecedented expansion in the scope, scale, and emotional range of classical music.\n\n### The Romantic Spirit\n\nRomanticism emerged as a reaction against the rationalism of the Enlightenment and the Industrial Revolution. Composers sought to express intense personal emotions, explore supernatural themes, and celebrate national identity through music. This new aesthetic led to the development of program music - compositions that told specific stories or painted musical pictures.\n\n### Expansion of Musical Language\n\nThe Romantic period saw a significant expansion of harmonic language. Composers pushed the boundaries of chromatic harmony, using increasingly complex chord progressions and modulations to distant keys. This development reached its apex in Wagner's \"Tristan und Isolde,\" whose famous \"Tristan chord\" symbolized the dissolution of traditional tonality.\n\n### The Symphony Transformed\n\nThe symphony, inherited from the Classical era, underwent radical transformation. Beethoven's Ninth Symphony, with its unprecedented scale and inclusion of vocal soloists and chorus, set new standards for symphonic composition. Later composers like Berlioz, Mahler, and Bruckner created symphonies of enormous proportions, both in length and orchestral forces.\n\n### New Forms and Genres\n\nThe period saw the emergence of new musical forms suited to Romantic expression. The symphonic poem, developed by Franz Liszt, combined orchestral music with extra-musical narratives. The art song (Lied) reached new heights of sophistication in the hands of Schubert and Schumann, creating perfect unions of poetry and music.\n\n### Nationalism in Music\n\nNational schools of composition emerged as countries sought to express their cultural identity through music. Russian composers like Tchaikovsky and the \"Mighty Five\" incorporated folk melodies and national themes. Similar movements appeared in Bohemia (Smetana, Dvoล™รกk), Norway (Grieg), and other European nations.\n\n### The Rise of the Virtuoso\n\nThe Romantic era celebrated individual achievement, leading to the rise of the virtuoso performer. Pianists like Liszt and Chopin composed works of unprecedented technical difficulty, while violinists like Paganini pushed the boundaries of what was possible on their instrument. This emphasis on virtuosity influenced compositional style and public performance practices.\n\n### Wagner and Music Drama\n\nRichard Wagner revolutionized opera through his concept of Gesamtkunstwerk (total artwork), combining music, drama, poetry, and visual arts. His use of leitmotifs - recurring musical themes associated with characters, objects, or ideas - influenced not only opera but also symphonic composition and, later, film music.\n\n### Technical and Social Developments\n\nThe period saw significant developments in instrument construction. The modern piano reached its current form, while brass instruments benefited from the invention of valves. Orchestras grew larger, requiring the emergence of the conductor as an interpreter rather than merely a timekeeper.\n\n### The End of an Era\n\nThe Romantic period gradually gave way to various modern movements. The increasing chromatic harmony of late Romanticism led naturally to the breakdown of traditional tonality in the early 20th century. However, Romantic ideals of emotional expression and individualism continued to influence composers well into the modern era.\n\nThe Romantic era's emphasis on emotional expression, its technical innovations, and its expansion of musical possibilities created a legacy that continues to influence musicians today. The period's great works remain central to the concert repertoire, beloved for their emotional depth and expressive power.\n:::\n\n\n\nGenerate a deck of 10 flashcards about the Romantic era:\n\n::: {#b6f029bd .cell execution_count=9}\n``` {.python .cell-code}\nromantic_deck = generate_structured_flashcards(romantic_text,\n \"Romanticism\", \n num_cards=10)\n```\n:::\n\n\nDisplay the complete deck object:\n\n::: {#a6ec19d9 .cell execution_count=10}\n``` {.python .cell-code}\nromantic_deck\n```\n\n::: {.cell-output .cell-output-display execution_count=52}\n```\nAnkiDeck(cards=[AnkiFlashcard(question='What major shift did the Romantic era represent in musical aesthetics?', answer='The Romantic era represented a shift towards prioritizing emotional expression, individualism, and nationalism, moving away from the formal constraints of the Classical period.', tags=['Romanticism', 'MusicAesthetics']), AnkiFlashcard(question='What is program music and how did it relate to Romanticism?', answer=\"Program music is a type of composition that tells specific stories or paints musical pictures, aligned with Romanticism's emphasis on emotional expression and supernatural themes.\", tags=['Romanticism', 'ProgramMusic']), AnkiFlashcard(question='How did harmonic language expand during the Romantic period?', answer='Composers expanded harmonic language by pushing boundaries of chromatic harmony, using complex chord progressions and modulations, exemplified by Wagner\\'s \"Tristan chord.\"', tags=['Romanticism', 'HarmonicLanguage']), AnkiFlashcard(question='Which symphony transformed the symphonic form during the Romantic era?', answer=\"Beethoven's Ninth Symphony transformed the symphonic form with its unprecedented scale and inclusion of vocal soloists and chorus.\", tags=['Romanticism', 'Symphony']), AnkiFlashcard(question='What is a symphonic poem and who developed it?', answer='A symphonic poem is an orchestral work that combines music with extra-musical narratives, developed by Franz Liszt.', tags=['Romanticism', 'MusicalForms']), AnkiFlashcard(question='Which regions developed national schools of composition during the Romantic era?', answer='National schools of composition emerged in Russia, Bohemia, Norway, and other European nations, often incorporating folk melodies and national themes.', tags=['Romanticism', 'Nationalism']), AnkiFlashcard(question='Who were some notable virtuoso performers during the Romantic era?', answer='Notable virtuoso performers included pianists like Liszt and Chopin, and violinists like Paganini, known for their technical achievements.', tags=['Romanticism', 'Virtuosos']), AnkiFlashcard(question='What concept did Wagner introduce in opera, and how did it influence other genres?', answer='Wagner introduced the concept of Gesamtkunstwerk (total artwork) and leitmotifs, influencing opera, symphonic composition, and film music.', tags=['Romanticism', 'Opera']), AnkiFlashcard(question='How did instrument construction and orchestra management change during the Romantic period?', answer='Instruments like the piano and brass instruments evolved; orchestras grew larger, making conductors interpreters rather than merely timekeepers.', tags=['Romanticism', 'Instrumentation']), AnkiFlashcard(question='How did the Romantic era influence later musical movements?', answer='The breakdown of traditional tonality led to modern movements, but Romantic ideals of emotional expression and individualism continued influencing composers.', tags=['Romanticism', 'ModernInfluence'])], deck_name='Romanticism')\n```\n:::\n:::\n\n\nShow the deck in JSON format:\n\n::: {#ae689ec1 .cell execution_count=11}\n``` {.python .cell-code}\nprint(romantic_deck.model_dump_json())\n```\n\n::: {.cell-output .cell-output-stdout}\n```\n{\"cards\":[{\"question\":\"What major shift did the Romantic era represent in musical aesthetics?\",\"answer\":\"The Romantic era represented a shift towards prioritizing emotional expression, individualism, and nationalism, moving away from the formal constraints of the Classical period.\",\"tags\":[\"Romanticism\",\"MusicAesthetics\"]},{\"question\":\"What is program music and how did it relate to Romanticism?\",\"answer\":\"Program music is a type of composition that tells specific stories or paints musical pictures, aligned with Romanticism's emphasis on emotional expression and supernatural themes.\",\"tags\":[\"Romanticism\",\"ProgramMusic\"]},{\"question\":\"How did harmonic language expand during the Romantic period?\",\"answer\":\"Composers expanded harmonic language by pushing boundaries of chromatic harmony, using complex chord progressions and modulations, exemplified by Wagner's \\\"Tristan chord.\\\"\",\"tags\":[\"Romanticism\",\"HarmonicLanguage\"]},{\"question\":\"Which symphony transformed the symphonic form during the Romantic era?\",\"answer\":\"Beethoven's Ninth Symphony transformed the symphonic form with its unprecedented scale and inclusion of vocal soloists and chorus.\",\"tags\":[\"Romanticism\",\"Symphony\"]},{\"question\":\"What is a symphonic poem and who developed it?\",\"answer\":\"A symphonic poem is an orchestral work that combines music with extra-musical narratives, developed by Franz Liszt.\",\"tags\":[\"Romanticism\",\"MusicalForms\"]},{\"question\":\"Which regions developed national schools of composition during the Romantic era?\",\"answer\":\"National schools of composition emerged in Russia, Bohemia, Norway, and other European nations, often incorporating folk melodies and national themes.\",\"tags\":[\"Romanticism\",\"Nationalism\"]},{\"question\":\"Who were some notable virtuoso performers during the Romantic era?\",\"answer\":\"Notable virtuoso performers included pianists like Liszt and Chopin, and violinists like Paganini, known for their technical achievements.\",\"tags\":[\"Romanticism\",\"Virtuosos\"]},{\"question\":\"What concept did Wagner introduce in opera, and how did it influence other genres?\",\"answer\":\"Wagner introduced the concept of Gesamtkunstwerk (total artwork) and leitmotifs, influencing opera, symphonic composition, and film music.\",\"tags\":[\"Romanticism\",\"Opera\"]},{\"question\":\"How did instrument construction and orchestra management change during the Romantic period?\",\"answer\":\"Instruments like the piano and brass instruments evolved; orchestras grew larger, making conductors interpreters rather than merely timekeepers.\",\"tags\":[\"Romanticism\",\"Instrumentation\"]},{\"question\":\"How did the Romantic era influence later musical movements?\",\"answer\":\"The breakdown of traditional tonality led to modern movements, but Romantic ideals of emotional expression and individualism continued influencing composers.\",\"tags\":[\"Romanticism\",\"ModernInfluence\"]}],\"deck_name\":\"Romanticism\"}\n```\n:::\n:::\n\n\nPrint each flashcard in a readable format:\n\n::: {#0098c8a5 .cell execution_count=12}\n``` {.python .cell-code}\nfor card in romantic_deck.cards:\n print(f\"Question: {card.question}\")\n print(f\"Answer: {card.answer}\")\n print(f\"Tags: {', '.join(card.tags)}\")\n print(\"-\" * 20)\n```\n\n::: {.cell-output .cell-output-stdout}\n```\nQuestion: What major shift did the Romantic era represent in musical aesthetics?\nAnswer: The Romantic era represented a shift towards prioritizing emotional expression, individualism, and nationalism, moving away from the formal constraints of the Classical period.\nTags: Romanticism, MusicAesthetics\n--------------------\nQuestion: What is program music and how did it relate to Romanticism?\nAnswer: Program music is a type of composition that tells specific stories or paints musical pictures, aligned with Romanticism's emphasis on emotional expression and supernatural themes.\nTags: Romanticism, ProgramMusic\n--------------------\nQuestion: How did harmonic language expand during the Romantic period?\nAnswer: Composers expanded harmonic language by pushing boundaries of chromatic harmony, using complex chord progressions and modulations, exemplified by Wagner's \"Tristan chord.\"\nTags: Romanticism, HarmonicLanguage\n--------------------\nQuestion: Which symphony transformed the symphonic form during the Romantic era?\nAnswer: Beethoven's Ninth Symphony transformed the symphonic form with its unprecedented scale and inclusion of vocal soloists and chorus.\nTags: Romanticism, Symphony\n--------------------\nQuestion: What is a symphonic poem and who developed it?\nAnswer: A symphonic poem is an orchestral work that combines music with extra-musical narratives, developed by Franz Liszt.\nTags: Romanticism, MusicalForms\n--------------------\nQuestion: Which regions developed national schools of composition during the Romantic era?\nAnswer: National schools of composition emerged in Russia, Bohemia, Norway, and other European nations, often incorporating folk melodies and national themes.\nTags: Romanticism, Nationalism\n--------------------\nQuestion: Who were some notable virtuoso performers during the Romantic era?\nAnswer: Notable virtuoso performers included pianists like Liszt and Chopin, and violinists like Paganini, known for their technical achievements.\nTags: Romanticism, Virtuosos\n--------------------\nQuestion: What concept did Wagner introduce in opera, and how did it influence other genres?\nAnswer: Wagner introduced the concept of Gesamtkunstwerk (total artwork) and leitmotifs, influencing opera, symphonic composition, and film music.\nTags: Romanticism, Opera\n--------------------\nQuestion: How did instrument construction and orchestra management change during the Romantic period?\nAnswer: Instruments like the piano and brass instruments evolved; orchestras grew larger, making conductors interpreters rather than merely timekeepers.\nTags: Romanticism, Instrumentation\n--------------------\nQuestion: How did the Romantic era influence later musical movements?\nAnswer: The breakdown of traditional tonality led to modern movements, but Romantic ideals of emotional expression and individualism continued influencing composers.\nTags: Romanticism, ModernInfluence\n--------------------\n```\n:::\n:::\n\n\nExport the flashcards to a CSV file for importing into Anki:\n\n::: {#66b0e2e0 .cell execution_count=13}\n``` {.python .cell-code}\nos.makedirs('assets/flashcards', exist_ok=True)\n\n# Export flashcards to CSV file\nwith open('assets/flashcards/romantic-flashcards.csv', \n 'w', \n newline='',\n encoding='utf-8') as csvfile:\n writer = csv.writer(csvfile)\n # Write header row\n writer.writerow(['Question', 'Answer', 'Tags'])\n # Write each flashcard as a row in the CSV\n for card in romantic_deck.cards:\n writer.writerow([card.question, card.answer, ', '.join(card.tags)])\n```\n:::\n\n\n", "supporting": [ "index_files" ], diff --git a/docs/projects/anki/example/index.html b/docs/projects/anki/example/index.html index f58e86c..8799b5a 100644 --- a/docs/projects/anki/example/index.html +++ b/docs/projects/anki/example/index.html @@ -116,15 +116,15 @@ }); + @@ -469,7 +470,8 @@

Generate Anki flashcards: example code

-
+

First, we import the required libraries:

+
import os
 import csv
 from dotenv import load_dotenv  # For loading environment variables
@@ -478,11 +480,13 @@ 

Generate Anki flashcards: example code

from pydantic import BaseModel, Field from typing import List
-
+

Initialize the OpenAI client using environment variables:

+
load_dotenv()
 client = OpenAI()
-
+

Define our data models using Pydantic for type safety and validation:

+
class AnkiFlashcard(BaseModel):
     """
     Model representing a single Anki flashcard with question, answer, and tags.
@@ -492,7 +496,8 @@ 

Generate Anki flashcards: example code

answer: str = Field(..., description="The back side of the flashcard containing the answer") tags: List[str] = Field(..., description="List of tags associated with the flashcard")
-
+

Create a model to represent a complete deck of flashcards:

+
class AnkiDeck(BaseModel):
     """
     Model representing a complete Anki deck containing multiple flashcards.
@@ -501,7 +506,8 @@ 

Generate Anki flashcards: example code

cards: List[AnkiFlashcard] = Field(..., description="List of flashcards in the deck") deck_name: str = Field(..., description="Name of the Anki deck")
-
+

Define the main function that generates flashcards using GPT-4:

+
def generate_structured_flashcards(text: str, 
                                    deck_name: str, 
                                    num_cards: int = 5) -> AnkiDeck:
@@ -546,6 +552,8 @@ 

Generate Anki flashcards: example code

# Return the parsed response return completion.choices[0].message.parsed
+

Load our sample text about the Romantic era from a markdown file:

+

Display the content of the romantic text (hidden by default):

-
+

Generate a deck of 10 flashcards about the Romantic era:

+
romantic_deck = generate_structured_flashcards(romantic_text,
                                               "Romanticism", 
                                               num_cards=10)
-
+

Display the complete deck object:

+
romantic_deck
AnkiDeck(cards=[AnkiFlashcard(question='What major shift did the Romantic era represent in musical aesthetics?', answer='The Romantic era represented a shift towards prioritizing emotional expression, individualism, and nationalism, moving away from the formal constraints of the Classical period.', tags=['Romanticism', 'MusicAesthetics']), AnkiFlashcard(question='What is program music and how did it relate to Romanticism?', answer="Program music is a type of composition that tells specific stories or paints musical pictures, aligned with Romanticism's emphasis on emotional expression and supernatural themes.", tags=['Romanticism', 'ProgramMusic']), AnkiFlashcard(question='How did harmonic language expand during the Romantic period?', answer='Composers expanded harmonic language by pushing boundaries of chromatic harmony, using complex chord progressions and modulations, exemplified by Wagner\'s "Tristan chord."', tags=['Romanticism', 'HarmonicLanguage']), AnkiFlashcard(question='Which symphony transformed the symphonic form during the Romantic era?', answer="Beethoven's Ninth Symphony transformed the symphonic form with its unprecedented scale and inclusion of vocal soloists and chorus.", tags=['Romanticism', 'Symphony']), AnkiFlashcard(question='What is a symphonic poem and who developed it?', answer='A symphonic poem is an orchestral work that combines music with extra-musical narratives, developed by Franz Liszt.', tags=['Romanticism', 'MusicalForms']), AnkiFlashcard(question='Which regions developed national schools of composition during the Romantic era?', answer='National schools of composition emerged in Russia, Bohemia, Norway, and other European nations, often incorporating folk melodies and national themes.', tags=['Romanticism', 'Nationalism']), AnkiFlashcard(question='Who were some notable virtuoso performers during the Romantic era?', answer='Notable virtuoso performers included pianists like Liszt and Chopin, and violinists like Paganini, known for their technical achievements.', tags=['Romanticism', 'Virtuosos']), AnkiFlashcard(question='What concept did Wagner introduce in opera, and how did it influence other genres?', answer='Wagner introduced the concept of Gesamtkunstwerk (total artwork) and leitmotifs, influencing opera, symphonic composition, and film music.', tags=['Romanticism', 'Opera']), AnkiFlashcard(question='How did instrument construction and orchestra management change during the Romantic period?', answer='Instruments like the piano and brass instruments evolved; orchestras grew larger, making conductors interpreters rather than merely timekeepers.', tags=['Romanticism', 'Instrumentation']), AnkiFlashcard(question='How did the Romantic era influence later musical movements?', answer='The breakdown of traditional tonality led to modern movements, but Romantic ideals of emotional expression and individualism continued influencing composers.', tags=['Romanticism', 'ModernInfluence'])], deck_name='Romanticism')
-
+

Show the deck in JSON format:

+
print(romantic_deck.model_dump_json())
{"cards":[{"question":"What major shift did the Romantic era represent in musical aesthetics?","answer":"The Romantic era represented a shift towards prioritizing emotional expression, individualism, and nationalism, moving away from the formal constraints of the Classical period.","tags":["Romanticism","MusicAesthetics"]},{"question":"What is program music and how did it relate to Romanticism?","answer":"Program music is a type of composition that tells specific stories or paints musical pictures, aligned with Romanticism's emphasis on emotional expression and supernatural themes.","tags":["Romanticism","ProgramMusic"]},{"question":"How did harmonic language expand during the Romantic period?","answer":"Composers expanded harmonic language by pushing boundaries of chromatic harmony, using complex chord progressions and modulations, exemplified by Wagner's \"Tristan chord.\"","tags":["Romanticism","HarmonicLanguage"]},{"question":"Which symphony transformed the symphonic form during the Romantic era?","answer":"Beethoven's Ninth Symphony transformed the symphonic form with its unprecedented scale and inclusion of vocal soloists and chorus.","tags":["Romanticism","Symphony"]},{"question":"What is a symphonic poem and who developed it?","answer":"A symphonic poem is an orchestral work that combines music with extra-musical narratives, developed by Franz Liszt.","tags":["Romanticism","MusicalForms"]},{"question":"Which regions developed national schools of composition during the Romantic era?","answer":"National schools of composition emerged in Russia, Bohemia, Norway, and other European nations, often incorporating folk melodies and national themes.","tags":["Romanticism","Nationalism"]},{"question":"Who were some notable virtuoso performers during the Romantic era?","answer":"Notable virtuoso performers included pianists like Liszt and Chopin, and violinists like Paganini, known for their technical achievements.","tags":["Romanticism","Virtuosos"]},{"question":"What concept did Wagner introduce in opera, and how did it influence other genres?","answer":"Wagner introduced the concept of Gesamtkunstwerk (total artwork) and leitmotifs, influencing opera, symphonic composition, and film music.","tags":["Romanticism","Opera"]},{"question":"How did instrument construction and orchestra management change during the Romantic period?","answer":"Instruments like the piano and brass instruments evolved; orchestras grew larger, making conductors interpreters rather than merely timekeepers.","tags":["Romanticism","Instrumentation"]},{"question":"How did the Romantic era influence later musical movements?","answer":"The breakdown of traditional tonality led to modern movements, but Romantic ideals of emotional expression and individualism continued influencing composers.","tags":["Romanticism","ModernInfluence"]}],"deck_name":"Romanticism"}
-
+

Print each flashcard in a readable format:

+
for card in romantic_deck.cards:
     print(f"Question: {card.question}")
     print(f"Answer: {card.answer}")
@@ -666,7 +678,8 @@ 

The End of an Era

--------------------
-
+

Export the flashcards to a CSV file for importing into Anki:

+
os.makedirs('assets/flashcards', exist_ok=True)
 
 # Export flashcards to CSV file
diff --git a/docs/sitemap.xml b/docs/sitemap.xml
index eed1c75..e8542d2 100644
--- a/docs/sitemap.xml
+++ b/docs/sitemap.xml
@@ -86,6 +86,6 @@
   
   
     https://virtuelleakademie.github.io/promptly-engineered/projects/anki/example/index.html
-    2024-11-28T08:19:35.247Z
+    2024-11-28T08:22:50.613Z