Skip to content

Commit

Permalink
Added Generics to the Contexts in the Typescript SDK models (#73)
Browse files Browse the repository at this point in the history
* added generics to the context

* better name for generic type. object to Record

* prettier formatted
  • Loading branch information
howlowck authored Sep 19, 2024
1 parent 5d138c9 commit 540122f
Showing 1 changed file with 22 additions and 10 deletions.
32 changes: 22 additions & 10 deletions sdk/js/packages/client/src/model/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,38 +5,50 @@ import { ClientOptions, OperationOptions } from "@typespec/ts-http-runtime";

export type AIChatRole = "user" | "assistant" | "system";

type GenericContext = Record<string, unknown>;

export interface AIChatFile {
contentType: string;
data: Uint8Array | File | Buffer;
}

export interface AIChatMessage {
export interface AIChatMessage<
ContextType extends GenericContext = GenericContext,
> {
role: AIChatRole;
content: string;
context?: object;
context?: ContextType;
files?: AIChatFile[];
}

export interface AIChatMessageDelta {
export interface AIChatMessageDelta<
ContextType extends GenericContext = GenericContext,
> {
role?: AIChatRole;
content?: string;
context?: object;
context?: ContextType;
}

export interface AIChatCompletion {
export interface AIChatCompletion<
ContextType extends GenericContext = GenericContext,
> {
message: AIChatMessage;
sessionState?: unknown;
context?: object;
context?: ContextType;
}

export interface AIChatCompletionDelta {
export interface AIChatCompletionDelta<
ContextType extends GenericContext = GenericContext,
> {
delta: AIChatMessageDelta;
sessionState?: unknown;
context?: object;
context?: ContextType;
}

export interface AIChatCompletionOptions {
context?: object;
export interface AIChatCompletionOptions<
ContextType extends GenericContext = GenericContext,
> {
context?: ContextType;
sessionState?: unknown;
}

Expand Down

0 comments on commit 540122f

Please sign in to comment.