You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* updates AI API reference
* adds model providers and meta
* fills out env vars
* adds some details
---------
Co-authored-by: Michael Irvine <[email protected]>
Copy file name to clipboardExpand all lines: docs/pages/product/apis-integrations/ai-api.mdx
+80Lines changed: 80 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -138,3 +138,83 @@ One way of handling this is to pass the error message back into the AI API; it m
138
138
#### 3. Continue wait
139
139
140
140
When using `"runQuery": true`, you might sometimes receive a query result containing `{ "error": "Continue wait" }`. If this happens, you should use `/load` ([described above](#2-load)) instead of `runQuery` to run the query, and handle retries as described in the [REST API documentation](/product/apis-integrations/rest-api#continue-wait).
141
+
142
+
## Advanced Usage
143
+
144
+
<InfoBox>
145
+
The advanced features discussed here are available on Cube version 1.1.7 and above.
146
+
</InfoBox>
147
+
148
+
### Custom prompts
149
+
150
+
You can prompt the AI API with custom instructions. For example, you may want it to always
151
+
respond in a particular language, or to refer to itself by a name matching your brand.
152
+
Custom prompts also allow you to give the model more context on your company and data model,
153
+
for example if it should usually prefer a particular view.
154
+
155
+
To use a custom prompt, set the `CUBE_CLOUD_AI_API_PROMPT` environment variable in your deployment.
156
+
157
+
<InfoBox>
158
+
Custom prompts add to, rather than overwrite, the AI API's existing prompting, so you
159
+
do not need to re-write instructions around how to generate the query itself.
160
+
</InfoBox>
161
+
162
+
### Meta tags
163
+
164
+
The AI API can read [meta tags](/reference/data-model/view#meta) on your dimensions, measures,
165
+
segments, and views.
166
+
167
+
Use the `ai` meta tag to give context that is specific to AI and goes beyond what is
168
+
included in the description. This can have any keys that you want. For example, you can use it
169
+
to give the AI context on possible values in a categorical dimension:
170
+
```yaml
171
+
- name: status
172
+
sql: status
173
+
type: string
174
+
meta:
175
+
ai:
176
+
values:
177
+
- shipped
178
+
- processing
179
+
- completed
180
+
```
181
+
182
+
### Other LLM providers
183
+
184
+
<InfoBox>
185
+
These environment variables also apply to the [AI Assistant](/product/workspace/ai-assistant),
186
+
if it is enabled on your deployment.
187
+
</InfoBox>
188
+
189
+
If desired, you may "bring your own" LLM model by providing a model and API credentials
190
+
for a supported model provider. Do this by setting environment variables in your Cube
191
+
deployment. See below for required variables by provider (required unless noted):
192
+
193
+
#### AWS Bedrock
194
+
195
+
<WarningBox>
196
+
The AI API currently supports only Anthropic Claude models on AWS Bedrock. Other
197
+
models may work but are not fully supported.
198
+
</WarningBox>
199
+
200
+
- `CUBE_BEDROCK_MODEL_ID` - A supported [AWS Bedrock chat model](https://docs.aws.amazon.com/bedrock/latest/userguide/models-supported.html), for example `anthropic.claude-3-5-sonnet-20241022-v2:0`
201
+
- `CUBE_BEDROCK_ACCESS_KEY`- An access key for an IAM user with `InvokeModelWithResponseStream` permissions on the desired region/model.
202
+
- `CUBE_BEDROCK_ACCESS_SECRET`- The corresponding access secret
203
+
- `CUBE_BEDROCK_REGION_ID`- A supported AWS Bedrock region, for example `us-west-2`
204
+
205
+
#### GCP Vertex
206
+
207
+
<WarningBox>
208
+
The AI API currently supports only Anthropic Claude models on GCP Vertex. Other
209
+
models may work but are not fully supported.
210
+
</WarningBox>
211
+
212
+
- `CUBE_VERTEX_MODEL_ID`- A supported GCP Vertex chat model, for example `claude-3-5-sonnet@20240620`
213
+
- `CUBE_VERTEX_PROJECT_ID`- The GCP project the model is deployed in
214
+
- `CUBE_VERTEX_REGION`- The GCP region the model is deployed in, for example `us-east5`
215
+
- `CUBE_VERTEX_CREDENTIALS`- The private key for a service account with permissions to run the chosen model
216
+
217
+
#### OpenAI
218
+
219
+
- `OPENAI_MODEL`- An OpenAI chat model ID, for example `gpt-4o`
220
+
- `OPENAI_API_KEY`- An OpenAI API key (we recommend creating a service account for the AI API)
0 commit comments