Skip to content

Commit

Permalink
feat: add AI LLM endpoint AWS params(box/box-openapi#478) (#291)
Browse files Browse the repository at this point in the history
  • Loading branch information
box-sdk-build authored Oct 29, 2024
1 parent a718979 commit dcb8a20
Show file tree
Hide file tree
Showing 6 changed files with 143 additions and 53 deletions.
2 changes: 1 addition & 1 deletion .codegen.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{ "engineHash": "2efc8ab", "specHash": "e798cb1", "version": "1.3.1" }
{ "engineHash": "2efc8ab", "specHash": "90cf4e4", "version": "1.3.1" }
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class AiAgentBasicTextToolBase : ISerializable {
/// The parameters for the LLM endpoint specific to OpenAI / Google models.
/// </summary>
[JsonPropertyName("llm_endpoint_params")]
public AiLlmEndpointParamsGoogleOrAiLlmEndpointParamsOpenAi? LlmEndpointParams { get; init; }
public AiLlmEndpointParamsAwsOrAiLlmEndpointParamsGoogleOrAiLlmEndpointParamsOpenAi? LlmEndpointParams { get; init; }

public AiAgentBasicTextToolBase() {

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
using Box.Sdk.Gen;
using System.Text.Json.Serialization;
using Box.Sdk.Gen.Internal;
using System.Collections.Generic;

namespace Box.Sdk.Gen.Schemas {
public class AiLlmEndpointParamsAws : ISerializable {
[JsonInclude]
[JsonPropertyName("_istemperatureSet")]
protected bool _isTemperatureSet { get; set; }

[JsonInclude]
[JsonPropertyName("_istop_pSet")]
protected bool _isTopPSet { get; set; }

protected double? _temperature { get; set; }

protected double? _topP { get; set; }

/// <summary>
/// The type of the AI LLM endpoint params object for AWS.
/// This parameter is **required**.
/// </summary>
[JsonPropertyName("type")]
[JsonConverter(typeof(StringEnumConverter<AiLlmEndpointParamsAwsTypeField>))]
public StringEnum<AiLlmEndpointParamsAwsTypeField> Type { get; }

/// <summary>
/// What sampling temperature to use, between 0 and 1. Higher values like 0.8 will make the output more random,
/// while lower values like 0.2 will make it more focused and deterministic.
/// We generally recommend altering this or `top_p` but not both.
/// </summary>
[JsonPropertyName("temperature")]
public double? Temperature { get => _temperature; init { _temperature = value; _isTemperatureSet = true; } }

/// <summary>
/// An alternative to sampling with temperature, called nucleus sampling, where the model considers the results
/// of the tokens with `top_p` probability mass. So 0.1 means only the tokens comprising the top 10% probability
/// mass are considered. We generally recommend altering this or temperature but not both.
/// </summary>
[JsonPropertyName("top_p")]
public double? TopP { get => _topP; init { _topP = value; _isTopPSet = true; } }

public AiLlmEndpointParamsAws(AiLlmEndpointParamsAwsTypeField type = AiLlmEndpointParamsAwsTypeField.AwsParams) {
Type = type;
}

[JsonConstructorAttribute]
internal AiLlmEndpointParamsAws(StringEnum<AiLlmEndpointParamsAwsTypeField> type) {
Type = AiLlmEndpointParamsAwsTypeField.AwsParams;
}
internal string? RawJson { get; set; } = default;

void ISerializable.SetJson(string json) {
RawJson = json;
}

string? ISerializable.GetJson() {
return RawJson;
}

/// <summary>
/// Returns raw json response returned from the API.
/// </summary>
public Dictionary<string, object?>? GetRawData() {
return SimpleJsonSerializer.GetAllFields(this);
}

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using System.ComponentModel;

namespace Box.Sdk.Gen.Schemas {
public enum AiLlmEndpointParamsAwsTypeField {
[Description("aws_params")]
AwsParams
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
using Box.Sdk.Gen;
using System;
using System.Text.Json;
using System.Text.Json.Serialization;
using Box.Sdk.Gen.Schemas;

namespace Box.Sdk.Gen.Schemas {
[JsonConverter(typeof(AiLlmEndpointParamsAwsOrAiLlmEndpointParamsGoogleOrAiLlmEndpointParamsOpenAiConverter))]
public class AiLlmEndpointParamsAwsOrAiLlmEndpointParamsGoogleOrAiLlmEndpointParamsOpenAi : OneOf<AiLlmEndpointParamsAws, AiLlmEndpointParamsGoogle, AiLlmEndpointParamsOpenAi> {
public AiLlmEndpointParamsAws? AiLlmEndpointParamsAws => _val0;

public AiLlmEndpointParamsGoogle? AiLlmEndpointParamsGoogle => _val1;

public AiLlmEndpointParamsOpenAi? AiLlmEndpointParamsOpenAi => _val2;

public AiLlmEndpointParamsAwsOrAiLlmEndpointParamsGoogleOrAiLlmEndpointParamsOpenAi(AiLlmEndpointParamsAws value) : base(value) {}

public AiLlmEndpointParamsAwsOrAiLlmEndpointParamsGoogleOrAiLlmEndpointParamsOpenAi(AiLlmEndpointParamsGoogle value) : base(value) {}

public AiLlmEndpointParamsAwsOrAiLlmEndpointParamsGoogleOrAiLlmEndpointParamsOpenAi(AiLlmEndpointParamsOpenAi value) : base(value) {}

public static implicit operator AiLlmEndpointParamsAwsOrAiLlmEndpointParamsGoogleOrAiLlmEndpointParamsOpenAi(AiLlmEndpointParamsAws value) => new AiLlmEndpointParamsAwsOrAiLlmEndpointParamsGoogleOrAiLlmEndpointParamsOpenAi(value);

public static implicit operator AiLlmEndpointParamsAwsOrAiLlmEndpointParamsGoogleOrAiLlmEndpointParamsOpenAi(AiLlmEndpointParamsGoogle value) => new AiLlmEndpointParamsAwsOrAiLlmEndpointParamsGoogleOrAiLlmEndpointParamsOpenAi(value);

public static implicit operator AiLlmEndpointParamsAwsOrAiLlmEndpointParamsGoogleOrAiLlmEndpointParamsOpenAi(AiLlmEndpointParamsOpenAi value) => new AiLlmEndpointParamsAwsOrAiLlmEndpointParamsGoogleOrAiLlmEndpointParamsOpenAi(value);

class AiLlmEndpointParamsAwsOrAiLlmEndpointParamsGoogleOrAiLlmEndpointParamsOpenAiConverter : JsonConverter<AiLlmEndpointParamsAwsOrAiLlmEndpointParamsGoogleOrAiLlmEndpointParamsOpenAi> {
public override AiLlmEndpointParamsAwsOrAiLlmEndpointParamsGoogleOrAiLlmEndpointParamsOpenAi Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) {
using var document = JsonDocument.ParseValue(ref reader);
var discriminant0Present = document.RootElement.TryGetProperty("type", out var discriminant0);
if (discriminant0Present) {
switch (discriminant0.ToString()){
case "aws_params":
return JsonSerializer.Deserialize<AiLlmEndpointParamsAws>(document) ?? throw new Exception($"Could not deserialize {document} to AiLlmEndpointParamsAws");
case "google_params":
return JsonSerializer.Deserialize<AiLlmEndpointParamsGoogle>(document) ?? throw new Exception($"Could not deserialize {document} to AiLlmEndpointParamsGoogle");
case "openai_params":
return JsonSerializer.Deserialize<AiLlmEndpointParamsOpenAi>(document) ?? throw new Exception($"Could not deserialize {document} to AiLlmEndpointParamsOpenAi");
}
}
throw new Exception($"Discriminant not found in json payload {document.RootElement} while try to converting to type {typeToConvert}");
}

public override void Write(Utf8JsonWriter writer, AiLlmEndpointParamsAwsOrAiLlmEndpointParamsGoogleOrAiLlmEndpointParamsOpenAi? value, JsonSerializerOptions options) {
if (value?.AiLlmEndpointParamsAws != null) {
JsonSerializer.Serialize(writer, value.AiLlmEndpointParamsAws, options);
return;
}
if (value?.AiLlmEndpointParamsGoogle != null) {
JsonSerializer.Serialize(writer, value.AiLlmEndpointParamsGoogle, options);
return;
}
if (value?.AiLlmEndpointParamsOpenAi != null) {
JsonSerializer.Serialize(writer, value.AiLlmEndpointParamsOpenAi, options);
return;
}
}

}

}
}

This file was deleted.

0 comments on commit dcb8a20

Please sign in to comment.