Skip to content

Extra learning

Exercise: Enhanced Blog Post Generation with Function Calling

Objective: Refine the blog post generation process from the first exercise by introducing structured information retrieval through function calling. This exercise aims to create a more precise and scalable solution for generating blog posts with distinct elements such as title, body, and author.

Background

In our initial exercise, we generated a blog post using a simple chat completion method. While this approach is straightforward, it often results in unstructured and sometimes inconsistent output. To enhance the precision and scalability of our blog post generation, we will now incorporate a structured approach using function calling, specifically a “saveBlogpost” function.

Why Function Calling?

Function calling allows us to define a specific structure for the output we expect from the model. It reduces the chances of imprecise and error-prone results, which are common when simply describing the desired output format in text. This method is especially useful when you require structured data like a blog post with a specific title, author, and body.

Task

Your task is to modify the first exercise to include a function calling approach for generating a blog post. Instead of using a general chat completion, you will define and utilize the “saveBlogpost” function to instruct the model to generate structured output.

Steps to Follow

  1. Understanding Function Calling:
    • Before modifying the exercise, familiarize yourself with the concept of function calling in the context of the Azure SDK for OpenAI. Refer to the detailed documentation on Function calling to understand how to implement and use this feature.
  2. Defining the “saveBlogpost” Function:
    • Define a “saveBlogpost” function that takes structured input from the model. This function should be capable of receiving and appropriately formatting the title, author, and body of the blog post.
    • Ensure the function is well-documented and clear in its purpose and usage.
  3. Instructing the Model:
    • Modify your request to the model to include instructions for using the “saveBlogpost” function. Clearly specify how the model should structure the output.
    • Test the modified request to ensure the model understands and correctly implements the function calling as intended.
  4. Evaluating Output:
    • Once you have implemented the changes, generate a few blog posts to evaluate the effectiveness of the structured output.
    • Compare the results with the initial exercise to assess improvements in precision and structure.

Exercise: Semantic Search using Embeddings

The current search does some rudimentary string matching, but we think it would much more valuable to use embedding to provide semantic search result. Now that you have embeddings in place, it should be a breeze!

More help

The current related algorithm is implemented in BlogSearch.cs, you could probably use GenerateEmbedding from ContentGenerator here along with the previously mentioned CosineSimilarity.

Even more help

Grab a supervisor or ask on slack!


Last update : November 20, 2023
Created : November 17, 2023