Skip to content

Conversation

@m-nash
Copy link
Collaborator

@m-nash m-nash commented Jun 27, 2024

There are 3 reasons we can't remove more custom code for model AssistantModificationOptions

  • namespace difference
  • custom xml doc
  • property type changes

Potential option to reduce custom code for the above issues.

For namespace we could add another decorator like this. The value of this is it can be shared across languages and since it is an identifier for the type it makes sense to know this before the files are created.

@@clientSubNamespace(ModifyAssistantRequest, "Assistants", "csharp");

We could then add 2 new CodeGen attributes.

  • CodeGenPropertyType - This will take the name of a property and the type to replace
  • CodeGenDoc - This will take the name of the property, the xml tag to replace / add, and the lines of text to use. This will allow us to write custom xml docs without needing to duplicate the property definition

Example of resulting custom code for AssistantModificationOptions

namespace OpenAI.Assistants;

[CodeGenPropertyType(nameof(ToolResources), typeof(ToolResources))]
[CodeGenPropertyType(nameof(ResponseFormat), typeof(AssistantResponseFormat))]
[CodeGenDoc(XmlDocTag.Summary, "Represents additional options available when modifying an existing <see cref=\"Assistant\"/>.")]
[CodeGenDoc(nameof(Model), XmlDocTag.Summary, "The replacement model that the assistant should use.")]
[CodeGenDoc(nameof(DefaultTools), XmlDocTag.Summary,
[
    "<para>",
    "A list of tool enabled on the assistant.",
    "</para>",
    "There can be a maximum of 128 tools per assistant. Tools can be of types `code_interpreter`, `file_search`, or `function`."
])]
[CodeGenDoc(nameof(NucleusSamplingFactor), XmlDocTag.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.",
    string.Empty,
    "We generally recommend altering this or temperature but not both."
])]
public partial class AssistantModificationOptions { }

Alternatively we could also consider some custom docs in tsp directly, but would need to come up with a format / syntax for special tags like <see cref="Foo" />

Before any changes from this PR or proposed the customized file looked like this for reference.

using System.Collections.Generic;

namespace OpenAI.Assistants;

/// <summary>
/// Represents additional options available when modifying an existing <see cref="Assistant"/>.
/// </summary>
[CodeGenModel("ModifyAssistantRequest")]
public partial class AssistantModificationOptions
{
    /// <summary>
    /// The replacement model that the assistant should use.
    /// </summary>
    public string Model { get; init; }

    /// <summary>
    /// <para>
    /// A list of tool enabled on the assistant.
    /// </para>
    /// There can be a maximum of 128 tools per assistant. Tools can be of types `code_interpreter`, `file_search`, or `function`.
    /// </summary>
    [CodeGenMember("Tools")]
    public IList<ToolDefinition> DefaultTools { get; init; } = new ChangeTrackingList<ToolDefinition>();

    // CUSTOM: reuse common request/response models for tool resources. Note that modification operations use the
    //          response models (which do not contain resource initialization helpers).

    /// <inheritdoc cref="ToolResources"/>
    [CodeGenMember("ToolResources")]
    public ToolResources ToolResources { get; init; }

    /// <inheritdoc cref="AssistantResponseFormat"/>
    [CodeGenMember("ResponseFormat")]
    public AssistantResponseFormat ResponseFormat { get; init; }

    /// <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>
    [CodeGenMember("TopP")]
    public float? NucleusSamplingFactor { get; init; }
}

@m-nash m-nash marked this pull request as draft June 27, 2024 03:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants