AzureOpenAILLM¶
AzureOpenAILLM
¶
Bases: OpenAILLM
Azure OpenAI LLM implementation running the async API client.
Attributes:
Name | Type | Description |
---|---|---|
model |
the model name to use for the LLM i.e. the name of the Azure deployment. |
|
base_url |
Optional[RuntimeParameter[str]]
|
the base URL to use for the Azure OpenAI API can be set with |
api_key |
Optional[RuntimeParameter[SecretStr]]
|
the API key to authenticate the requests to the Azure OpenAI API. Defaults to |
api_version |
Optional[RuntimeParameter[str]]
|
the API version to use for the Azure OpenAI API. Defaults to |
Icon
:simple-microsoftazure:
Examples:
Generate text:
```python
from distilabel.llms import AzureOpenAILLM
llm = AzureOpenAILLM(model="gpt-4-turbo", api_key="api.key")
llm.load()
# Synchrounous request
output = llm.generate(inputs=[[{"role": "user", "content": "Hello world!"}]])
# Asynchronous request
output = await llm.agenerate(input=[{"role": "user", "content": "Hello world!"}])
```
Generate text from a custom endpoint following the OpenAI API:
```python
from distilabel.llms import AzureOpenAILLM
llm = AzureOpenAILLM(
model="prometheus-eval/prometheus-7b-v2.0",
base_url=r"http://localhost:8080/v1"
)
llm.load()
# Synchronous request
output = llm.generate(inputs=[[{"role": "user", "content": "Hello world!"}]])
# Asynchronous request
output = await llm.agenerate(input=[{"role": "user", "content": "Hello world!"}])
```
Generate structured data:
```python
from pydantic import BaseModel
from distilabel.llms import AzureOpenAILLM
class User(BaseModel):
name: str
last_name: str
id: int
llm = AzureOpenAILLM(
model="gpt-4-turbo",
api_key="api.key",
structured_output={"schema": User}
)
llm.load()
output = llm.generate(inputs=[[{"role": "user", "content": "Create a user profile for the following marathon"}]])
```
Source code in src/distilabel/llms/azure.py
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 |
|
load()
¶
Loads the AsyncAzureOpenAI
client to benefit from async requests.