AIApi
.NET SDK: the AI - Artificial Intelligence operations, 1 method, each with its parameters, result and a complete example.
.NET SDK · BIMworks.Sdk.Api · class · 1 method
Natural-language calls, for example to turn a sentence into a BQL query, a BVL visualisation or a BCL check
Construct it with the client of the connect step: client.GetRequiredService<IAIApi>(). Each method is one operation of the API part, where it runs on its page.
| Method | Operation | Description |
|---|---|---|
TextToActionAsync | TextToAction | Turn a sentence into a BIM.works action (BQL, BVL or BCL) |
TextToActionAsync#
Task<ITextToActionApiResponse> TextToActionAsync(TextToActionRequest textToActionRequest, CancellationToken cancellationToken = default)Turn a sentence into a BIM.works action (BQL, BVL or BCL). Sends the text to the language model the instance is configured with (the account's default text-to-action model, else the server's ai.default_text_to_action) and returns the action it wrote: a BQL query, a BVL visualisation or a BCL check. The server parses and formats the code before it answers; code that does not parse goes back to the model once with the parser's error, and fails with 502 when the second answer does not parse either.
| Operation | TextToAction · POST /openapi/ai/TextToAction |
|---|---|
| Scope | ai:use |
Parameters#
| Name | Type | Description |
|---|---|---|
textToActionRequest | TextToActionRequestrequired | The request: its properties are those of the model, its JSON that of TextToAction's request body. |
Returns#
TextToActionResult — The action
Example#
using System.Text.Json;
using BIMworks.Sdk.Api;
using BIMworks.Sdk.Client;
using BIMworks.Sdk.Extensions;
using BIMworks.Sdk.Model;
using Microsoft.Extensions.DependencyInjection;
// 1. Connect to BIM.works and log in with your API token
IServiceProvider Connect(string bearer)
{
var services = new ServiceCollection();
services.AddApi(options =>
{
options.AddTokens(new BearerToken(bearer));
options.AddApiHttpClients(http =>
{
http.BaseAddress = new Uri("https://bim.works" + "/openapi");
http.Timeout = Timeout.InfiniteTimeSpan;
});
});
return services.BuildServiceProvider();
}
var login = await Connect("").GetRequiredService<IAuthApi>().LoginWithApiTokenAsync(new LoginWithApiTokenRequest("<your API token>"));
var auth = login.Ok()?.Auth ?? throw new HttpRequestException(login.RawContent, null, login.StatusCode);
var client = Connect(auth.Base64);
var json = client.GetRequiredService<JsonSerializerOptionsProvider>().Options;
// 2. The request
var request = JsonSerializer.Deserialize<TextToActionRequest>("""
{
"input": "Show the external walls in red",
"models": [
{
"type": "VersionModelIdentifier",
"uuid": "<version uuid of the first demo model>"
}
]
}
""", json);
// 3. The call
var response = await client.GetRequiredService<IAIApi>().TextToActionAsync(request);
// 4. The result
var result = response.Ok() ?? throw new HttpRequestException(response.RawContent, null, response.StatusCode);
Console.WriteLine(JsonSerializer.Serialize(result, json));