Skip to content

Commit 0483c9d

Browse files
mjirvMichael Irvine
andauthored
docs: ai api updates (#8997)
* updates AI API reference * adds model providers and meta * fills out env vars * adds some details --------- Co-authored-by: Michael Irvine <[email protected]>
1 parent f37c000 commit 0483c9d

File tree

3 files changed

+135
-1
lines changed

3 files changed

+135
-1
lines changed

docs/pages/product/apis-integrations/ai-api.mdx

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,3 +138,83 @@ One way of handling this is to pass the error message back into the AI API; it m
138138
#### 3. Continue wait
139139

140140
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)

docs/pages/product/workspace/ai-assistant.mdx

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,49 @@ The query will automatically run in the sidebar and can be opened in the [Playgr
5858

5959
<Screenshot src="https://ucarecdn.com/4249ff1e-fae1-42c8-ad3a-b9e406ea2022/Screenshot20240624at34327PM.png" />
6060

61+
## Advanced Usage
62+
63+
<InfoBox>
64+
The advanced features discussed here are available on Cube version 1.1.7 and above.
65+
</InfoBox>
66+
67+
### Custom prompts
68+
69+
You can prompt the AI Assistant with custom instructions. For example, you may want it to always
70+
respond in a particular language, or to refer to itself by a name matching your brand.
71+
Custom prompts also allow you to give the model more context on your company and data model,
72+
for example if it should usually prefer a particular view.
73+
74+
To use a custom prompt, set the `CUBE_CLOUD_AI_ASSISTANT_PROMPT` environment variable in your deployment.
75+
76+
<InfoBox>
77+
Custom prompts add to, rather than overwrite, the AI Assistant's existing prompting.
78+
</InfoBox>
79+
80+
### Meta tags
81+
82+
The AI Assistant can read [meta tags](/reference/data-model/view#meta) on your dimensions, measures,
83+
segments, and views.
84+
85+
Use the `ai` meta tag to give context that is specific to AI and goes beyond what is
86+
included in the description. This can have any keys that you want. For example, you can use it
87+
to give the AI context on possible values in a categorical dimension:
88+
```yaml
89+
- name: status
90+
sql: status
91+
type: string
92+
meta:
93+
ai:
94+
values:
95+
- shipped
96+
- processing
97+
- completed
98+
```
99+
100+
### Other LLM providers
101+
102+
See the [AI API's documentation][ref-ai-api-providers] for information on how to "bring your own" LLM.
103+
61104
## FAQ and limitations
62105
63106
### 1. What language model(s) does the AI Assistant use?
@@ -83,3 +126,4 @@ The query will automatically run in the sidebar and can be opened in the [Playgr
83126
[ref-catalog]: /product/workspace/semantic-catalog
84127
[ref-playground]: /product/workspace/playground
85128
[ref-catalog-downstream]: /product/workspace/semantic-catalog#connecting-downstream-tools
129+
[ref-ai-api-providers]: /product/apis-integrations/ai-api#other-llm-providers

docs/pages/reference/ai-api.mdx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,21 @@ Generate a Cube query that can be used to answer a user's question, and (optiona
1111
| `messages` | ✅ Yes | An array of messages in the format: `{ "role": "user" \| "assistant", "content": "string" }` |
1212
| `views` | | An array of view names (used to limit the views that the AI API can use to generate its answer) |
1313
| `runQuery` | | Boolean (true or false) whether to run the query and return its results |
14+
| `options` | | An object in the format `{ "chart": true \| false }`
1415

1516
Response
1617

1718
- `message` - A message from the AI assistant describing the query, how it was chosen, why it could not generate the requested query, etc.
1819
- `cube_query` - A Cube [Query](/product/apis-integrations/rest-api/query-format) that could be used to answer the given question
20+
- `chart` - If the `chart` option is set to `true`, an object containing a chart spec for the generated query in the following format:
21+
```json
22+
{
23+
"type": "bar" | "line" | "pie" | "table" | "area" | "scatter",
24+
"x": string,
25+
"y": string[],
26+
"pivot": string // optional; the field to pivot by, if any
27+
}
28+
```
1929

2030
### Examples
2131

@@ -28,7 +38,7 @@ curl \
2838
-X POST \
2939
-H "Content-Type: application/json" \
3040
-H "Authorization: EXAMPLE-API-TOKEN" \
31-
--data '{ "messages": [{ "role": "user", "content": "What cities have the highest aov this year?" }]}' \
41+
--data '{ "messages": [{ "role": "user", "content": "What cities have the highest aov this year?", "views": ["orders_view"] }]}' \
3242
https://YOUR_CUBE_API/cubejs-api/v1/ai/query/completions
3343
```
3444

0 commit comments

Comments
 (0)