Skip to content

Commit db25aac

Browse files
authored
Update llama-index.md
1 parent d5fe4f4 commit db25aac

File tree

1 file changed

+30
-5
lines changed

1 file changed

+30
-5
lines changed

articles/ai-studio/how-to/develop/llama-index.md

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ author: eric-urban
1313

1414
# Develop applications with LlamaIndex and Azure AI studio
1515

16-
In this article, you learn how to use [LlamaIndex](https://github.com/run-llama/llama_index) with models deployed from the Azure AI model catalog deployed to Azure AI studio.
16+
In this article, you learn how to use [LlamaIndex](https://github.com/run-llama/llama_index) with models deployed from the Azure AI model catalog in Azure AI studio.
1717

1818
Models deployed to Azure AI studio can be used with LlamaIndex in two ways:
1919

@@ -49,7 +49,7 @@ To run this tutorial, you need:
4949

5050
## Configure the environment
5151

52-
To use LLMs deployed in Azure AI studio, you need the endpoint and credentials to connect to it. The parameter `model_name` is not required for endpoints serving a single model, like Managed Online Endpoints. Follow these steps to get the information you need from the model you want to use:
52+
To use LLMs deployed in Azure AI studio, you need the endpoint and credentials to connect to it. Follow these steps to get the information you need from the model you want to use:
5353

5454
1. Go to the [Azure AI studio](https://ai.azure.com/).
5555
2. Go to deployments and select the model you deployed as indicated in the prerequisites.
@@ -79,10 +79,15 @@ llm = AzureAICompletionsModel(
7979
)
8080
```
8181
82+
> [!TIP]
83+
> The parameter `model_name` in the constructor is not required for endpoints serving a single model, like serverless endpoints).
84+
8285
Alternatively, if your endpoint support Microsoft Entra ID, you can use the following code to create the client:
8386
8487
```python
88+
import os
8589
from azure.identity import DefaultAzureCredential
90+
from llama_index.llms.azure_inference import AzureAICompletionsModel
8691
8792
llm = AzureAICompletionsModel(
8893
endpoint=os.environ["AZURE_INFERENCE_ENDPOINT"],
@@ -91,14 +96,15 @@ llm = AzureAICompletionsModel(
9196
```
9297
9398
> [!NOTE]
94-
> > Note: When using Microsoft Entra ID, make sure that the endpoint was deployed with that authentication method and that you have the required permissions to invoke it.
99+
> When using Microsoft Entra ID, make sure that the endpoint was deployed with that authentication method and that you have the required permissions to invoke it.
95100
96101
If you are planning to use asynchronous calling, it's a best practice to use the asynchronous version for the credentials:
97102

98103
```python
99104
from azure.identity.aio import (
100105
DefaultAzureCredential as DefaultAzureCredentialAsync,
101106
)
107+
from llama_index.llms.azure_inference import AzureAICompletionsModel
102108
103109
llm = AzureAICompletionsModel(
104110
endpoint=os.environ["AZURE_INFERENCE_ENDPOINT"],
@@ -132,7 +138,7 @@ llm = AzureAICompletionsModel(
132138

133139
## Use LLMs models
134140

135-
Use the `chat` endpoint for chat instruction models. The `complete` method is still available for model of type `chat-completions`. On those cases, your input text is converted to a message with `role="user"`.
141+
You can use the client directly or [#configure-the-models-used-by-your-code](Configure the models used by your code) in LlamaIndex. To use the model directly, use the `chat` method for chat instruction models:
136142

137143
```python
138144
from llama_index.core.llms import ChatMessage
@@ -156,9 +162,11 @@ for r in response:
156162
print(r.delta, end="")
157163
```
158164
165+
The `complete` method is still available for model of type `chat-completions`. On those cases, your input text is converted to a message with `role="user"`.
166+
159167
## Use embeddings models
160168
161-
In the same way you create an LLM client, you can connect to an embedding model. In the following example, we are setting again the environment variable to now point to an embeddings model:
169+
In the same way you create an LLM client, you can connect to an embeddings model. In the following example, we are setting the environment variable to now point to an embeddings model:
162170
163171
```bash
164172
export AZURE_INFERENCE_ENDPOINT="<your-model-endpoint-goes-here>"
@@ -176,6 +184,21 @@ embed_model = AzureAIEmbeddingsModel(
176184
)
177185
```
178186
187+
The following example shows a simple test to verify it works:
188+
189+
```python
190+
from llama_index.core.schema import TextNode
191+
192+
nodes = [
193+
TextNode(
194+
text="Before college the two main things I worked on, "
195+
"outside of school, were writing and programming."
196+
)
197+
]
198+
response = embed_model(nodes=nodes)
199+
print(response[0].embedding)
200+
```
201+
179202
## Configure the models used by your code
180203
181204
You can use the LLM or embeddings model client individually in the code you develop with LlamaIndex or you can configure the entire session using the `Settings` options. Configuring the session has the advantage of all your code using the same models for all the operations.
@@ -200,3 +223,5 @@ In general, you use a combination of both strategies.
200223
## Related content
201224
202225
* [How to get started with Azure AI SDKs](sdk-overview.md)
226+
* [Reference for LlamaIndex Embeddings Integration](https://llamahub.ai/l/embeddings/llama-index-embeddings-azure-inference)
227+
* [Reference for LlamaIndex LLMs Integration](https://llamahub.ai/l/llms/llama-index-llms-azure-inference)

0 commit comments

Comments
 (0)