@Bao, Jeremy (Cognizant) To use RAG with the REST API for Azure OpenAI, you can follow the steps below:
- First, you need to create a deployment for your RAG model in the Azure OpenAI service. You can do this using the Azure portal or the Azure CLI. Once you have created the deployment, you can get the deployment ID, which you will need to use in your API requests.
- To use RAG with the REST API, you need to send a POST request to the
/openai/v1.0/generations
endpoint. In the request body, you need to include the prompt for the RAG model, as well as any additional parameters you want to use. Here is an example request body:
In this example, we are using the{ "model": "text-davinci-002", "prompt": "What is the capital of France?", "temperature": 0.5, "max_tokens": 50, "top_p": 1, "frequency_penalty": 0, "presence_penalty": 0, "stop": "\n" }
text-davinci-002
model, and asking the model to generate a response to the prompt "What is the capital of France?" We are also setting some additional parameters, such as thetemperature
,max_tokens
,top_p
,frequency_penalty
, andpresence_penalty
. - In the request header, you need to include your Azure OpenAI API key. Here is an example header:
Replace{ "Content-Type": "application/json", "Authorization": "Bearer <your-api-key>" }
<your-api-key>
with your actual API key. - Send the POST request to the
/openai/v1.0/generations
endpoint, and you should receive a response from the RAG model.
Regarding your questions about the request body, the data_sources
field is not needed for RAG. The vector_profile
and vector_field
fields are also not needed for RAG. Instead, you should include the model
field in the request body, which specifies the name of the RAG model you want to use.
When it comes to authentication, you should include your Azure OpenAI API key in the Authorization
header of your API request. The authentication
field is not needed for RAG.
For the role_information
field, this field is used to specify the role of each message in a conversation. The first message in the array should have a role
of "system"
, which indicates that it is a system message. The subsequent messages should have a role
of "user"
, which indicates that they are user messages.
Lastly, for DeploymentNameVectorizationSource
and EndpointVectorizationSource
fields, these fields are used to specify the source of the embeddings used by the RAG model. If your RAG model and your embedding model are both deployed in the same Azure OpenAI service, you can use the DeploymentNameVectorizationSource
field to specify the name of the deployment for the embedding model. If your RAG model and your embedding model are deployed in different services, you can use the EndpointVectorizationSource
field to specify the endpoint for the embedding service.