Welcome to this comprehensive guide on Azure OpenAI. We'll delve into the practical applications of
this groundbreaking technology. All the cases have been tested throughly on Azure. Feel free to use it
as the blueprint of your project.
Azure OpenAI Service provides REST API access to OpenAI's powerful language models including the
GPT-4, GPT-4 Turbo with Vision, GPT-3.5-Turbo, and Embeddings model series. In addition, the new GPT-4
and GPT-3.5-Turbo model series have now reached general availability. These models can be easily
adapted to your specific task including but not limited to content generation, summarization, image
understanding, semantic search, and natural language to code translation. Users can access the service
through REST APIs, Python SDK, or our web-based interface in the Azure OpenAI Studio.
Hello Azure OpenAI
This application serves as a 'Hello World' example, verifying that all necessary requirements are fulfilled and that the environment is configured correctly.
To run it, we need setup AZURE_OPENAI_API_KEY (not openai_api_key, not start with sk-), AZURE_OPENAI_ENDPOINT, and AZURE_DEPLOYMENT in local PC's environment.
Basically, we are using Azure as a gateway to access OpenAI. We are responsible to deliver information to Azure, and Azure will handle all the communication with OpenAI. Azure is a middle man.
If using .env to store these credentionals, need use dotenv to replace os.environ.get().
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
After running it, you will get the right answer.
This has been tested with OpenAI 0.9.1.
RAG
Organizations of all sizes have amassed a plethora of documents over time. While generative AI, such as ChatGPT, can provide answers about general knowledge and historical events with reasonable accuracy, they can also be tailored to answer questions based on a company's internal documents.
Accuracy in Generative AI Large Language Models (LLMs), like the ones powering ChatGPT, aren't designed for high-precision answers. They may produce "hallucinations", offering responses that seem authoritative but are actually incorrect. It's crucial to inform users that the responses are AI-generated. In this workshop, we'll explore how to generate answers that link to their information sources — this is what we call grounding — enabling users to verify the accuracy of the AI's responses.
We'll build a chat application that generates responses based on your documents and deploy it to Azure. We'll touch on many different topics, but we'll take it one step at a time.
The RAG process involves the following steps:
Embedding Computation: Converts a user's prompt into an embedding for similarity comparisons.
Document Retrieval: Finds the most relevant documents using the prompt's embedding. This is where systems like Azure AI Search come into play, allowing for efficient vector similarity searches.
Contextual Augmentation: Enhances the user prompt with information from retrieved documents. This step is crucial as it provides additional context and information to the generator.
Response Generation: Use the model to generate a response using the augmented prompt. The model uses the additional context provided by the retrieved documents to produce a more informed and accurate output.
Milestones:
Create a knowledge base using a vector database.
Ingest documents in a vector database.
Create a Web API with Fastify.
Use OpenAI models and LangChain to generate answers based on a prompt.
Query a vector database and augment a prompt to generate responses.
Connect your Web API to a ChatGPT-like website.
Deploy your application on Azure.
One Hundred 3 Years of Solitude by Gabriel García Márquez
Our story begins with Colonel Aureliano Buendía reflecting on the early years of Macondo, a secluded
village founded by his father, José Arcadio Buendía. Macondo is isolated from the outside world, only
occasionally visited by gypsies bringing technological marvels that captivate its inhabitants. José
Arcadio Buendía, fascinated by these innovations, immerses himself in scientific study with supplies
from Melquíades, the gypsies' leader. He becomes increasingly solitary in his quest for knowledge.
Meanwhile, his wife, Úrsula Iguarán, is more practical and is frustrated by her husband's obsession.