8. Content creation workflo

  1. Initializing the LLM Client: The example starts by creating an LLM instance with specific configurations:

    llm, err := gollm.NewLLM(
        gollm.SetProvider("openai"),                  // Set the LLM provider
        gollm.SetModel("gpt-4o-mini"),                // Set the model (ensure it's compatible with the provider)
        gollm.SetAPIKey(os.Getenv("OPENAI_API_KEY")), // Set the API Key
        gollm.SetMaxTokens(500))                      // Limit the response length
    if err != nil {
        log.Fatalf("Failed to create LLM: %v", err)
    }

    This configuration uses OpenAI's GPT-4o-mini model and sets a maximum of 500 tokens for responses.

  2. Step 1: Research Phase The example starts with a research phase to generate a brief overview of quantum computing:

    researchPrompt := gollm.NewPrompt(
        "Provide a brief overview of quantum computing",
        gollm.WithMaxLength(200), // Limit the research to 200 words
    )
    research, err := llm.Generate(ctx, researchPrompt)
    if err != nil {
        log.Fatalf("Research failed: %v", err)
    }
    fmt.Printf("Research:\n%s\n\n", research)

    This step generates a brief overview of quantum computing, limited to 200 words.

  3. Step 2: Ideation Phase Using the research from step 1 as context, the example generates article ideas:

    ideaPrompt := gollm.NewPrompt(
        "Generate 3 article ideas about quantum computing for a general audience",
        gollm.WithContext(research), // Use the research as context for generating ideas
    )
    ideas, err := llm.Generate(ctx, ideaPrompt)
    if err != nil {
        log.Fatalf("Ideation failed: %v", err)
    }
    fmt.Printf("Article Ideas:\n%s\n\n", ideas)

    This step generates three article ideas about quantum computing, using the research as context to inform the ideas.

  4. Step 3: Writing Refinement The final step demonstrates how to refine a paragraph using specific directives:

    refinementPrompt := gollm.NewPrompt(
        "Improve the following paragraph about quantum computing:",
        gollm.WithContext(research), // Use the research as the paragraph to improve
        gollm.WithDirectives( // Provide specific instructions for improvement
            "Use simpler language for a general audience",
            "Add an engaging opening sentence",
            "Conclude with a thought-provoking question",
        ),
    )
    refinedParagraph, err := llm.Generate(ctx, refinementPrompt)
    if err != nil {
        log.Fatalf("Refinement failed: %v", err)
    }
    fmt.Printf("Refined Paragraph:\n%s\n", refinedParagraph)

    This step takes the research from step 1 as the paragraph to improve, and provides specific directives for the refinement process. It asks the LLM to use simpler language, add an engaging opening sentence, and conclude with a thought-provoking question.

In summary, this example demonstrates a three-step content creation workflow:

  1. Research: Generate a brief overview of a topic (quantum computing in this case).

  2. Ideation: Use the research to generate article ideas for a general audience.

  3. Refinement: Improve a paragraph (the research in this case) with specific directives for better engagement and accessibility.

This workflow showcases how gollm can be used to create a multi-step content creation process, where each step builds upon the previous one. It demonstrates the use of context (passing information from one step to the next) and directives (giving specific instructions to the LLM) to guide the content creation process.

This example is particularly useful for content creators, writers, or anyone looking to automate parts of their writing process while maintaining control over the direction and style of the content.

Last updated