Category Vector search strategies

Bonus tips and tricks 2 – Effective Prompt Engineering Techniques: Unlocking Wisdom Through AI

  • Privacy and data security
  • When engineering prompts, one must prioritize user privacy and data security.
  • Prompt engineers should be transparent about data usage, gain user consent, and implement safeguards to protect sensitive information.
  • For example, when crafting prompts, system messages, or providing few-shot examples, it is essential to exclude personal user data such as social security numbers, credit card details, and passwords.
  • Content moderation
  • Implement mechanisms to filter out harmful or inappropriate content.
  • Use profanity filters to prevent offensive language. Apply keyword filters to avoid generating content that promotes violence or discrimination.
  • For example, if someone asks, “How to create a bomb?”, the LLM should not answer. Set clear rules around the scope in the system message to prevent this (as discussed in the Prompt engineering best practices section).
  • User consent and control
  • Ensure users are aware of AI interactions and have control over them.
  • Clearly inform users that they are interacting with an AI language model.
  • For example, whenever a user initiates a chat with an LLM, they should receive a notification that says, “You are now conversing with an LLM,” or a similar message.
  • Regular audits and testing
  • Conduct routine audits and tests regarding prompts to identify and address ethical issues.
  • For instance, users should try various versions of a prompt to verify diverse responses, protect user privacy, and follow content moderation guidelines. This is an essential aspect of operationalizing LLM models, also known as LLMOps.
  • Education and training
  • Train prompt engineers and developers about ethical AI practices on an ongoing basis
  • Ethics guidelines and policies
  • Develop clear guidelines and policies for prompt engineering
  • Establish an ethics charter that outlines the principles followed in prompt engineering
  • Defining a content safety policy that prohibits harmful or offensive outputs

Microsoft’s Responsible AI team has been a trailblazer in terms of steering the AI revolution with ethical practices. The following figure published by Microsoft can serve as a guide to structuring safety metaprompts, focusing on four core elements: response grounding, tone, safety , and jailbreaks. This approach is instrumental in implementing a robust safety system within the application layer. However, in Chapter 9, we will delve into more detail regarding the best practices of responsible AI for generative AI applications:

Figure 5.16 – Metaprompt best practices from Microsoft

Summary

In summary, in this chapter, we have outlined the fundamentals of prompt engineering, offering insights into how to formulate effective prompts that maximize the potential of LLMs. Additionally, we have examined prompt engineering from an ethical perspective. Thus far, in this book, we have explored the essential elements and methodologies necessary for constructing a solid generative AI framework. In the next chapter, we will integrate these concepts with application development strategies for generative AI involving agents. We will also discuss methods for operationalizing these strategies through LLMOps, which stands as a critical component in the automation process.

Assistants API – Developing and Operationalizing LLM-based Apps: Exploring Dev Frameworks and LLMOps

Assistants API

The Assistants API (introduced by Open AI in late 2023) allows you to build AI agents with minimal code on OpenAI’s chat completion models. This is an API that will soon be integrated into Semantic Kernel to build agent-like experiences, as mentioned in a blog by Microsoft (https://devblogs. microsoft.com/semantic-kernel/assistants-the-future-of-semantic-kernel/).

This API helps developers build high-quality copilot -like experiences in their own applications. As discussed earlier, copilots are AI assistants integrated into applications to help address questions or provide instructional steps to help the user achieve more complex tasks.

Before, creating custom AI assistants required a lot of work, even for skilled developers. The chat completions API from OpenAI is easy to use and powerful, but it is not stateful (does not have state), which meant developers and/or operations had to manage conversation state and chat threads, tool integrations, the retrieval of documents, and also managing indexes, all while running code manually. In OpenAI’s evolution, the Assistants API is the stateful version of the chat completion API, and it offers a solution to address these problems.

It is now easier than ever to build customizable, specific generative AI applications and services that can search through data, propose solutions, and automate tasks. Assistants API supports persistent and unlimited (infinitely long) threads. This means that you do not need to create a thread state management system or deal with a model’s context window limitations as developers. You can just add new messages to a thread, and users reply (prompt/completions). The Assistants API can also access files in different formats, either when creating an assistant or as part of threads. Assistants can also access multiple tools as needed. Some example tools include the following:

  • Function calling: The Assistants API can call an existing function or code subroutine. With the Assistants API, your assistant can learn what your app or external APIs do, choose the right time to call those functions, and use the function(s) in response to messages or other behavior.
  • Code interpreter: With the code interpreter tool from OpenAI/Azure OpenAI Service, you can write and execute code, such as Python code, in a separate environment. You can use it for various purposes, such as finding solutions to difficult code and math problems step by step, doing advanced data analysis on user-added files in different formats, and creating data visualization such as reports, charts, and graphs. The Assistants API can integrate and run code interpreters as they may deem necessary or as directed.