|
| 1 | +# UiPath LLMs and Embeddings |
| 2 | + |
| 3 | +This guide covers the UiPath-integrated Large Language Models (LLMs) and embedding models available in the UiPath LlamaIndex SDK. |
| 4 | + |
| 5 | +## Overview |
| 6 | + |
| 7 | +The UiPath LlamaIndex SDK provides pre-configured LLM and embedding classes that integrate seamlessly with UiPath. These classes handle authentication, routing, and configuration automatically, allowing you to focus on building your agents. |
| 8 | + |
| 9 | +## Prerequisites |
| 10 | + |
| 11 | +Before using these classes, ensure you have: |
| 12 | + |
| 13 | +- Authenticated with UiPath using `uipath auth` |
| 14 | +- Set up your environment variables (automatically configured after authentication) |
| 15 | + |
| 16 | +## UiPathOpenAI |
| 17 | + |
| 18 | +The `UiPathOpenAI` class is a pre-configured Azure OpenAI client that routes requests through UiPath. |
| 19 | + |
| 20 | +### Available Models |
| 21 | + |
| 22 | +The following OpenAI models are available through the `OpenAIModel` enum: |
| 23 | + |
| 24 | +- `GPT_4_1_2025_04_14` |
| 25 | +- `GPT_4_1_MINI_2025_04_14` |
| 26 | +- `GPT_4_1_NANO_2025_04_14` |
| 27 | +- `GPT_4O_2024_05_13` |
| 28 | +- `GPT_4O_2024_08_06` |
| 29 | +- `GPT_4O_2024_11_20` |
| 30 | +- `GPT_4O_MINI_2024_07_18` (default) |
| 31 | +- `O3_MINI_2025_01_31` |
| 32 | +- `TEXT_DAVINCI_003` |
| 33 | + |
| 34 | +### Basic Usage |
| 35 | + |
| 36 | +```python |
| 37 | +from uipath_llamaindex.llms import UiPathOpenAI |
| 38 | +from llama_index.core.llms import ChatMessage |
| 39 | + |
| 40 | +# Create an LLM instance with default settings |
| 41 | +llm = UiPathOpenAI() |
| 42 | + |
| 43 | +# Create chat messages |
| 44 | +messages = [ |
| 45 | + ChatMessage( |
| 46 | + role="system", content="You are a pirate with colorful personality." |
| 47 | + ), |
| 48 | + ChatMessage(role="user", content="Hello"), |
| 49 | +] |
| 50 | + |
| 51 | +# Generate a response |
| 52 | +response = llm.chat(messages) |
| 53 | +print(response) |
| 54 | +``` |
| 55 | + |
| 56 | +### Custom Model Configuration |
| 57 | + |
| 58 | +```python |
| 59 | +from uipath_llamaindex.llms import UiPathOpenAI, OpenAIModel |
| 60 | + |
| 61 | +# Use a specific model |
| 62 | +llm = UiPathOpenAI(model=OpenAIModel.GPT_4O_2024_11_20) |
| 63 | + |
| 64 | +# Or use a model string directly |
| 65 | +llm = UiPathOpenAI(model="gpt-4o-2024-11-20") |
| 66 | +``` |
| 67 | + |
| 68 | +## UiPathOpenAIEmbedding |
| 69 | + |
| 70 | +The `UiPathOpenAIEmbedding` class provides text embedding capabilities using OpenAI's embedding models through UiPath. |
| 71 | + |
| 72 | +### Available Embedding Models |
| 73 | + |
| 74 | +The following embedding models are available through the `OpenAIEmbeddingModel` enum: |
| 75 | + |
| 76 | +- `TEXT_EMBEDDING_ADA_002` (default) |
| 77 | +- `TEXT_EMBEDDING_3_LARGE` |
| 78 | + |
| 79 | +### Basic Usage |
| 80 | + |
| 81 | +```python |
| 82 | +from uipath_llamaindex.embeddings import UiPathOpenAIEmbedding |
| 83 | + |
| 84 | +# Create an embedding model instance |
| 85 | +embed_model = UiPathOpenAIEmbedding() |
| 86 | + |
| 87 | +# Get embeddings for a single text |
| 88 | +result = embed_model.get_text_embedding("the quick brown fox jumps over the lazy dog") |
| 89 | +print(f"Embedding dimension: {len(result)}") |
| 90 | +``` |
| 91 | + |
| 92 | +### Batch Embeddings |
| 93 | + |
| 94 | +```python |
| 95 | +from uipath_llamaindex.embeddings import UiPathOpenAIEmbedding |
| 96 | + |
| 97 | +embed_model = UiPathOpenAIEmbedding() |
| 98 | + |
| 99 | +# Get embeddings for multiple texts |
| 100 | +texts = [ |
| 101 | + "Hello world", |
| 102 | + "How are you?", |
| 103 | + "This is a test" |
| 104 | +] |
| 105 | + |
| 106 | +embeddings = embed_model.get_text_embedding_batch(texts) |
| 107 | +print(f"Number of embeddings: {len(embeddings)}") |
| 108 | +``` |
| 109 | + |
| 110 | + |
| 111 | +## Integration with LlamaIndex |
| 112 | + |
| 113 | +Both classes integrate seamlessly with LlamaIndex components: |
| 114 | + |
| 115 | +### Using with Agents |
| 116 | + |
| 117 | +```python |
| 118 | +from llama_index.core.agent import ReActAgent |
| 119 | +from llama_index.core.tools import FunctionTool |
| 120 | +from uipath_llamaindex.llms import UiPathOpenAI |
| 121 | + |
| 122 | +def multiply(a: int, b: int) -> int: |
| 123 | + """Multiply two integers and returns the result.""" |
| 124 | + return a * b |
| 125 | + |
| 126 | +multiply_tool = FunctionTool.from_defaults(fn=multiply) |
| 127 | + |
| 128 | +# Create agent with UiPath LLM |
| 129 | +agent = ReActAgent.from_tools( |
| 130 | + [multiply_tool], |
| 131 | + llm=UiPathOpenAI(model=OpenAIModel.GPT_4O_2024_11_20) |
| 132 | +) |
| 133 | + |
| 134 | +response = agent.chat("What is 21 multiplied by 2?") |
| 135 | +``` |
| 136 | + |
| 137 | +### Using with VectorStoreIndex |
| 138 | + |
| 139 | +```python |
| 140 | +from llama_index.core import VectorStoreIndex, Document |
| 141 | +from uipath_llamaindex.llms import UiPathOpenAI |
| 142 | +from uipath_llamaindex.embeddings import UiPathOpenAIEmbedding |
| 143 | + |
| 144 | +# Create documents |
| 145 | +documents = [ |
| 146 | + Document(text="This is a sample document about artificial intelligence."), |
| 147 | + Document(text="Machine learning is a subset of AI that focuses on algorithms."), |
| 148 | +] |
| 149 | + |
| 150 | +# Create index with UiPath models |
| 151 | +index = VectorStoreIndex.from_documents( |
| 152 | + documents, |
| 153 | + embed_model=UiPathOpenAIEmbedding() |
| 154 | +) |
| 155 | + |
| 156 | +# Create query engine with UiPath LLM |
| 157 | +query_engine = index.as_query_engine( |
| 158 | + llm=UiPathOpenAI(model=OpenAIModel.GPT_4O_2024_11_20) |
| 159 | +) |
| 160 | + |
| 161 | +response = query_engine.query("What is machine learning?") |
| 162 | +``` |
0 commit comments