Skip to content

Commit a187301

Browse files
feat: add support of IBM models to AI API (box/box-openapi#522) (#475)
1 parent a53cff5 commit a187301

File tree

5 files changed

+128
-26
lines changed

5 files changed

+128
-26
lines changed

.codegen.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{ "engineHash": "c2a365c", "specHash": "6a332e7", "version": "1.9.0" }
1+
{ "engineHash": "c2a365c", "specHash": "4e677e3", "version": "1.9.0" }

Box.Sdk.Gen/Schemas/AiAgentBasicTextToolBase/AiAgentBasicTextToolBase.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,8 @@ public class AiAgentBasicTextToolBase : ISerializable {
1818
[JsonPropertyName("num_tokens_for_completion")]
1919
public long? NumTokensForCompletion { get; init; }
2020

21-
/// <summary>
22-
/// The parameters for the LLM endpoint specific to OpenAI / Google models.
23-
/// </summary>
2421
[JsonPropertyName("llm_endpoint_params")]
25-
public AiLlmEndpointParamsAwsOrAiLlmEndpointParamsGoogleOrAiLlmEndpointParamsOpenAi? LlmEndpointParams { get; init; }
22+
public AiLlmEndpointParams? LlmEndpointParams { get; init; }
2623

2724
public AiAgentBasicTextToolBase() {
2825

Original file line numberDiff line numberDiff line change
@@ -6,54 +6,66 @@
66
using Box.Sdk.Gen.Internal;
77

88
namespace Box.Sdk.Gen.Schemas {
9-
[JsonConverter(typeof(AiLlmEndpointParamsAwsOrAiLlmEndpointParamsGoogleOrAiLlmEndpointParamsOpenAiConverter))]
10-
public class AiLlmEndpointParamsAwsOrAiLlmEndpointParamsGoogleOrAiLlmEndpointParamsOpenAi : OneOf<AiLlmEndpointParamsAws, AiLlmEndpointParamsGoogle, AiLlmEndpointParamsOpenAi> {
11-
public AiLlmEndpointParamsAws? AiLlmEndpointParamsAws => _val0;
9+
[JsonConverter(typeof(AiLlmEndpointParamsConverter))]
10+
public class AiLlmEndpointParams : OneOf<AiLlmEndpointParamsOpenAi, AiLlmEndpointParamsGoogle, AiLlmEndpointParamsAws, AiLlmEndpointParamsIbm> {
11+
public AiLlmEndpointParamsOpenAi? AiLlmEndpointParamsOpenAi => _val0;
1212

1313
public AiLlmEndpointParamsGoogle? AiLlmEndpointParamsGoogle => _val1;
1414

15-
public AiLlmEndpointParamsOpenAi? AiLlmEndpointParamsOpenAi => _val2;
15+
public AiLlmEndpointParamsAws? AiLlmEndpointParamsAws => _val2;
1616

17-
public AiLlmEndpointParamsAwsOrAiLlmEndpointParamsGoogleOrAiLlmEndpointParamsOpenAi(AiLlmEndpointParamsAws value) : base(value) {}
17+
public AiLlmEndpointParamsIbm? AiLlmEndpointParamsIbm => _val3;
1818

19-
public AiLlmEndpointParamsAwsOrAiLlmEndpointParamsGoogleOrAiLlmEndpointParamsOpenAi(AiLlmEndpointParamsGoogle value) : base(value) {}
19+
public AiLlmEndpointParams(AiLlmEndpointParamsOpenAi value) : base(value) {}
2020

21-
public AiLlmEndpointParamsAwsOrAiLlmEndpointParamsGoogleOrAiLlmEndpointParamsOpenAi(AiLlmEndpointParamsOpenAi value) : base(value) {}
21+
public AiLlmEndpointParams(AiLlmEndpointParamsGoogle value) : base(value) {}
2222

23-
public static implicit operator AiLlmEndpointParamsAwsOrAiLlmEndpointParamsGoogleOrAiLlmEndpointParamsOpenAi(AiLlmEndpointParamsAws value) => new AiLlmEndpointParamsAwsOrAiLlmEndpointParamsGoogleOrAiLlmEndpointParamsOpenAi(value);
23+
public AiLlmEndpointParams(AiLlmEndpointParamsAws value) : base(value) {}
2424

25-
public static implicit operator AiLlmEndpointParamsAwsOrAiLlmEndpointParamsGoogleOrAiLlmEndpointParamsOpenAi(AiLlmEndpointParamsGoogle value) => new AiLlmEndpointParamsAwsOrAiLlmEndpointParamsGoogleOrAiLlmEndpointParamsOpenAi(value);
25+
public AiLlmEndpointParams(AiLlmEndpointParamsIbm value) : base(value) {}
2626

27-
public static implicit operator AiLlmEndpointParamsAwsOrAiLlmEndpointParamsGoogleOrAiLlmEndpointParamsOpenAi(AiLlmEndpointParamsOpenAi value) => new AiLlmEndpointParamsAwsOrAiLlmEndpointParamsGoogleOrAiLlmEndpointParamsOpenAi(value);
27+
public static implicit operator AiLlmEndpointParams(AiLlmEndpointParamsOpenAi value) => new AiLlmEndpointParams(value);
2828

29-
class AiLlmEndpointParamsAwsOrAiLlmEndpointParamsGoogleOrAiLlmEndpointParamsOpenAiConverter : JsonConverter<AiLlmEndpointParamsAwsOrAiLlmEndpointParamsGoogleOrAiLlmEndpointParamsOpenAi> {
30-
public override AiLlmEndpointParamsAwsOrAiLlmEndpointParamsGoogleOrAiLlmEndpointParamsOpenAi Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) {
29+
public static implicit operator AiLlmEndpointParams(AiLlmEndpointParamsGoogle value) => new AiLlmEndpointParams(value);
30+
31+
public static implicit operator AiLlmEndpointParams(AiLlmEndpointParamsAws value) => new AiLlmEndpointParams(value);
32+
33+
public static implicit operator AiLlmEndpointParams(AiLlmEndpointParamsIbm value) => new AiLlmEndpointParams(value);
34+
35+
class AiLlmEndpointParamsConverter : JsonConverter<AiLlmEndpointParams> {
36+
public override AiLlmEndpointParams Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) {
3137
using var document = JsonDocument.ParseValue(ref reader);
3238
var discriminant0Present = document.RootElement.TryGetProperty("type", out var discriminant0);
3339
if (discriminant0Present) {
3440
switch (discriminant0.ToString()){
35-
case "aws_params":
36-
return JsonSerializer.Deserialize<AiLlmEndpointParamsAws>(document) ?? throw new Exception($"Could not deserialize {document} to AiLlmEndpointParamsAws");
37-
case "google_params":
38-
return JsonSerializer.Deserialize<AiLlmEndpointParamsGoogle>(document) ?? throw new Exception($"Could not deserialize {document} to AiLlmEndpointParamsGoogle");
3941
case "openai_params":
4042
return JsonSerializer.Deserialize<AiLlmEndpointParamsOpenAi>(document) ?? throw new Exception($"Could not deserialize {document} to AiLlmEndpointParamsOpenAi");
43+
case "google_params":
44+
return JsonSerializer.Deserialize<AiLlmEndpointParamsGoogle>(document) ?? throw new Exception($"Could not deserialize {document} to AiLlmEndpointParamsGoogle");
45+
case "aws_params":
46+
return JsonSerializer.Deserialize<AiLlmEndpointParamsAws>(document) ?? throw new Exception($"Could not deserialize {document} to AiLlmEndpointParamsAws");
47+
case "ibm_params":
48+
return JsonSerializer.Deserialize<AiLlmEndpointParamsIbm>(document) ?? throw new Exception($"Could not deserialize {document} to AiLlmEndpointParamsIbm");
4149
}
4250
}
4351
throw new Exception($"Discriminant not found in json payload {document.RootElement} while try to converting to type {typeToConvert}");
4452
}
4553

46-
public override void Write(Utf8JsonWriter writer, AiLlmEndpointParamsAwsOrAiLlmEndpointParamsGoogleOrAiLlmEndpointParamsOpenAi? value, JsonSerializerOptions options) {
47-
if (value?.AiLlmEndpointParamsAws != null) {
48-
JsonSerializer.Serialize(writer, value.AiLlmEndpointParamsAws, options);
54+
public override void Write(Utf8JsonWriter writer, AiLlmEndpointParams? value, JsonSerializerOptions options) {
55+
if (value?.AiLlmEndpointParamsOpenAi != null) {
56+
JsonSerializer.Serialize(writer, value.AiLlmEndpointParamsOpenAi, options);
4957
return;
5058
}
5159
if (value?.AiLlmEndpointParamsGoogle != null) {
5260
JsonSerializer.Serialize(writer, value.AiLlmEndpointParamsGoogle, options);
5361
return;
5462
}
55-
if (value?.AiLlmEndpointParamsOpenAi != null) {
56-
JsonSerializer.Serialize(writer, value.AiLlmEndpointParamsOpenAi, options);
63+
if (value?.AiLlmEndpointParamsAws != null) {
64+
JsonSerializer.Serialize(writer, value.AiLlmEndpointParamsAws, options);
65+
return;
66+
}
67+
if (value?.AiLlmEndpointParamsIbm != null) {
68+
JsonSerializer.Serialize(writer, value.AiLlmEndpointParamsIbm, options);
5769
return;
5870
}
5971
}
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
using Box.Sdk.Gen;
2+
using System.Text.Json.Serialization;
3+
using Box.Sdk.Gen.Internal;
4+
using System.Collections.Generic;
5+
6+
namespace Box.Sdk.Gen.Schemas {
7+
public class AiLlmEndpointParamsIbm : ISerializable {
8+
[JsonInclude]
9+
[JsonPropertyName("_istemperatureSet")]
10+
protected bool _isTemperatureSet { get; set; }
11+
12+
[JsonInclude]
13+
[JsonPropertyName("_istop_pSet")]
14+
protected bool _isTopPSet { get; set; }
15+
16+
[JsonInclude]
17+
[JsonPropertyName("_istop_kSet")]
18+
protected bool _isTopKSet { get; set; }
19+
20+
protected double? _temperature { get; set; }
21+
22+
protected double? _topP { get; set; }
23+
24+
protected double? _topK { get; set; }
25+
26+
/// <summary>
27+
/// The type of the AI LLM endpoint params object for IBM.
28+
/// This parameter is **required**.
29+
/// </summary>
30+
[JsonPropertyName("type")]
31+
[JsonConverter(typeof(StringEnumConverter<AiLlmEndpointParamsIbmTypeField>))]
32+
public StringEnum<AiLlmEndpointParamsIbmTypeField> Type { get; }
33+
34+
/// <summary>
35+
/// What sampling temperature to use, between 0 and 1. Higher values like 0.8 will make the output more random,
36+
/// while lower values like 0.2 will make it more focused and deterministic.
37+
/// We generally recommend altering this or `top_p` but not both.
38+
/// </summary>
39+
[JsonPropertyName("temperature")]
40+
public double? Temperature { get => _temperature; init { _temperature = value; _isTemperatureSet = true; } }
41+
42+
/// <summary>
43+
/// An alternative to sampling with temperature, called nucleus sampling, where the model considers the results
44+
/// of the tokens with `top_p` probability mass. So 0.1 means only the tokens comprising the top 10% probability
45+
/// mass are considered. We generally recommend altering this or temperature but not both.
46+
/// </summary>
47+
[JsonPropertyName("top_p")]
48+
public double? TopP { get => _topP; init { _topP = value; _isTopPSet = true; } }
49+
50+
/// <summary>
51+
/// `Top-K` changes how the model selects tokens for output. A `top-K` of 1 means the next selected token is
52+
/// the most probable among all tokens in the model's vocabulary (also called greedy decoding),
53+
/// while a `top-K` of 3 means that the next token is selected from among the three most probable tokens by using temperature.
54+
/// </summary>
55+
[JsonPropertyName("top_k")]
56+
public double? TopK { get => _topK; init { _topK = value; _isTopKSet = true; } }
57+
58+
public AiLlmEndpointParamsIbm(AiLlmEndpointParamsIbmTypeField type = AiLlmEndpointParamsIbmTypeField.IbmParams) {
59+
Type = type;
60+
}
61+
62+
[JsonConstructorAttribute]
63+
internal AiLlmEndpointParamsIbm(StringEnum<AiLlmEndpointParamsIbmTypeField> type) {
64+
Type = AiLlmEndpointParamsIbmTypeField.IbmParams;
65+
}
66+
internal string? RawJson { get; set; } = default;
67+
68+
void ISerializable.SetJson(string json) {
69+
RawJson = json;
70+
}
71+
72+
string? ISerializable.GetJson() {
73+
return RawJson;
74+
}
75+
76+
/// <summary>
77+
/// Returns raw json response returned from the API.
78+
/// </summary>
79+
public Dictionary<string, object?>? GetRawData() {
80+
return SimpleJsonSerializer.GetAllFields(this);
81+
}
82+
83+
}
84+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
using System.ComponentModel;
2+
using Box.Sdk.Gen.Internal;
3+
4+
namespace Box.Sdk.Gen.Schemas {
5+
public enum AiLlmEndpointParamsIbmTypeField {
6+
[Description("ibm_params")]
7+
IbmParams
8+
}
9+
}

0 commit comments

Comments
 (0)