Skip to content

support-enum-member-in-modular #2092

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,19 @@ export interface AzureChatExtensionsMessageContext {
// @public
export type AzureChatExtensionType = string;

// @public
export interface AzureCognitiveSearchIndexFieldMappingOptions {
contentFieldNames?: string[];
contentFieldSeparator?: string;
filepathField?: string;
titleField?: string;
urlField?: string;
vectorFields?: string[];
}

// @public
export type AzureCognitiveSearchQueryType = string;

// @public
export type AzureOpenAIOperationState = string;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ export {
ImageGenerationOptions,
ImageSize,
ImageGenerationResponseFormat,
AzureCognitiveSearchIndexFieldMappingOptions,
AzureCognitiveSearchQueryType,
GetEmbeddingsOptions,
GetCompletionsOptions,
GetChatCompletionsOptions,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ export {
ImageGenerationOptions,
ImageSize,
ImageGenerationResponseFormat,
AzureCognitiveSearchIndexFieldMappingOptions,
AzureCognitiveSearchQueryType,
} from "./models.js";
export {
GetEmbeddingsOptions,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -610,3 +610,23 @@ export type ImageSize = string;
/** The format in which the generated images are returned. */
/** "url", "b64_json" */
export type ImageGenerationResponseFormat = string;

/** Optional settings to control how fields are processed when using a configured Azure Cognitive Search resource. */
export interface AzureCognitiveSearchIndexFieldMappingOptions {
/** The name of the index field to use as a title. */
titleField?: string;
/** The name of the index field to use as a URL. */
urlField?: string;
/** The name of the index field to use as a filepath. */
filepathField?: string;
/** The names of index fields that should be treated as content. */
contentFieldNames?: string[];
/** The separator pattern that content fields should use. */
contentFieldSeparator?: string;
/** The names of fields that represent vector data. */
vectorFields?: string[];
}

/** The type of Azure Cognitive Search retrieval query that should be executed when using it as an Azure OpenAI chat extension. */
/** "simple", "semantic", "vector", "vectorSimpleHybrid", "vectorSemanticHybrid" */
export type AzureCognitiveSearchQueryType = string;
30 changes: 24 additions & 6 deletions packages/typespec-test/test/openai_modular/spec/client.tsp
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,33 @@ using Azure.ClientGenerator.Core;

// Azure-specific long-running operations should be treated as implementation details that are wrapped into
// appropriately merged public surface.
@@internal(Azure.OpenAI.beginAzureBatchImageGeneration);
@@internal(Azure.OpenAI.getAzureBatchImageGenerationOperationStatus);
@@access(Azure.OpenAI.beginAzureBatchImageGeneration, Access.internal);
@@access(Azure.OpenAI.getAzureBatchImageGenerationOperationStatus,
Access.internal
);

// Azure-specific Chat Completions with extensions should be handled by clients as a conditional selection within the
// shared Chat Completions route, with the selection gated by the presence or non-presence of additional child
// configuration options on the request payload options model.
@@internal(Azure.OpenAI.getChatCompletionsWithAzureExtensions);
@@access(Azure.OpenAI.getChatCompletionsWithAzureExtensions, Access.internal);

// Some models from routes with suppressed visibility are still desired for custom public surface.
@@include(Azure.OpenAI.ImageGenerationOptions);
@@include(Azure.OpenAI.ImageLocation);
@@include(Azure.OpenAI.ImageGenerations);
@@access(Azure.OpenAI.ImageGenerationOptions, Access.public);
@@access(Azure.OpenAI.ImageLocation, Access.public);
@@access(Azure.OpenAI.ImageGenerations, Access.public);
@@access(Azure.OpenAI.ImageSize, Access.public);

@@access(Azure.OpenAI.AzureCognitiveSearchIndexFieldMappingOptions,
Access.public
);
@@usage(Azure.OpenAI.AzureCognitiveSearchIndexFieldMappingOptions, Usage.input);

@@access(Azure.OpenAI.AzureCognitiveSearchQueryType, Access.public);
@@usage(Azure.OpenAI.AzureCognitiveSearchQueryType, Usage.input);

@@access(Azure.OpenAI.AzureCognitiveSearchChatExtensionConfiguration,
Access.public
);
@@usage(Azure.OpenAI.AzureCognitiveSearchChatExtensionConfiguration,
Usage.input
);
14 changes: 9 additions & 5 deletions packages/typespec-ts/src/modular/buildCodeModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1028,12 +1028,13 @@ function emitEnum(program: Program, type: Enum): Record<string, any> {
values: enumValues,
isFixed: isFixed(program, type)
};
function enumMemberType(member: EnumMember) {
if (typeof member.value === "number") {
return intOrFloat(member.value);
}
return "string";
}

function enumMemberType(member: EnumMember) {
if (typeof member.value === "number") {
return intOrFloat(member.value);
}
return "string";
}

function constantType(value: any, valueType: string): Record<string, any> {
Expand Down Expand Up @@ -1342,6 +1343,7 @@ function getNonNullOptions(type: Union) {

function emitEnumMember(type: any): Record<string, any> {
return {
type: enumMemberType(type),
name: type.name ? enumName(type.name) : undefined,
value: type.value,
description: type.doc
Expand Down Expand Up @@ -1399,6 +1401,8 @@ function emitType(context: SdkContext, type: EmitterType): Record<string, any> {
return {};
case "Enum":
return emitEnum(context.program, type);
case "EnumMember":
return emitEnumMember(type);
default:
throw Error(`Not supported ${type.kind}`);
}
Expand Down
1 change: 1 addition & 0 deletions packages/typespec-ts/src/modular/modularCodeModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ export interface Type {
| "float"
| "duration"
| "enum"
| "enummember"
| "integer"
| "float"
| "boolean"
Expand Down