Skip to content
This repository was archived by the owner on Oct 8, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export interface ModelFactory {
export abstract class Model<TInput extends object, TOutput extends object> {
protected constructor(
public readonly info: ModelInfo,
private invoker: ModelInvoker,
protected invoker: ModelInvoker,
) {}

debug: boolean = false;
Expand All @@ -42,6 +42,6 @@ export abstract class Model<TInput extends object, TOutput extends object> {
console.debug(`Received output: ${outputJson}`);
}

return JSON.parse<TOutput>(outputJson, true);
return JSON.parse<TOutput>(outputJson);
}
}
3 changes: 3 additions & 0 deletions src/models/meta/llama.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class LlamaInput {
*
* Default: 0.6
*/
@omitif("this.temperature == 0.6")
temperature: f64 = 0.6;

/**
Expand All @@ -38,6 +39,7 @@ class LlamaInput {
*
* Default: 0.9
*/
@omitif("this.topP == 0.9")
@alias("top_p")
topP: f64 = 0.9;

Expand All @@ -46,6 +48,7 @@ class LlamaInput {
*
* Default: 512
*/
@omitif("this.maxGenLen == 512")
@alias("max_gen_len")
maxGenLen: i32 = 512;
}
Expand Down
57 changes: 49 additions & 8 deletions src/models/openai/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,53 +20,80 @@ class ChatCompletionInput {


@alias("frequency_penalty")
@omitif("this.frequencyPenalty == 0.0")
frequencyPenalty: f64 = 0.0;


@alias("logit_bias")
@omitnull()
logitBias: Map<string, f64> | null = null;


@omitif("this.logprobs == false")
logprobs: bool = false;

// @alias("top_logprobs")
// topLogprobs: i32 = 0; // TODO: only send when logprobs is true

@alias("top_logprobs")
@omitif("this.logprobs == false")
topLogprobs: i32 = 0;


@alias("max_tokens")
maxTokens: i32 = 4096;
@omitif("this.maxTokens == 4096")
maxTokens: i32 = 4096; // TODO: make this an `i32 | null` when supported


@omitif("this.n == 1")
n: i32 = 1;


@alias("presence_penalty")
@omitif("this.presencePenalty == 0.0")
presencePenalty: f64 = 0.0;


@alias("response_format")
@omitif("this.responseFormat.type == 'text'")
responseFormat: ResponseFormat = ResponseFormat.Text;

// seed: i32 | null = null; // TODO: we need a true Nullable<i32> type for this to work

@omitif("this.seed == -1")
seed: i32 = -1; // TODO: make this an `i32 | null` when supported


@omitnull()
stop: string[] | null = null;

// stream: bool = false;

// @omitif("this.stream == false")
// @alias("stream_options")
// streamOptions: StreamOptions | null = null;

@omitif("this.temperature == 1.0")
temperature: f64 = 1.0;


@alias("top_p")
@omitif("this.topP == 1.0")
topP: f64 = 1.0;


@omitnull()
tools: Tool[] | null = null;


@alias("tool_choice")
@omitnull()
toolChoice: string | null = null; // TODO: verify this works

// @alias("parallel_tool_calls")
// parallelToolCalls: bool = true; // TODO: omit this when no tools

@alias("user")
@alias("parallel_tool_calls")
@omitif("this.parallelToolCalls == true || !this.tools || this.tools!.length == 0")
parallelToolCalls: bool = true;


@omitnull()
user: string | null = null;
}

Expand Down Expand Up @@ -98,6 +125,7 @@ export class ResponseFormat {
// @json
// export class StreamOptions {

// @omitif("this.includeUsage == false")
// @alias("include_usage")
// includeUsage: bool = false;
// }
Expand All @@ -111,8 +139,14 @@ export class Tool {

@json
export class FunctionDefinition {
description: string | null = null;
name!: string;


@omitnull()
description: string | null = null;


@omitnull()
parameters: string | null = null; // TODO: verify this works
}

Expand Down Expand Up @@ -212,6 +246,8 @@ export class SystemMessage extends Message {
super("system", content);
}


@omitnull()
name: string | null = null;
}

Expand All @@ -222,6 +258,8 @@ export class UserMessage extends Message {
super("user", content);
}


@omitnull()
name: string | null = null;
}

Expand All @@ -232,10 +270,13 @@ export class AssistantMessage extends Message {
super("assistant", content);
}


@omitnull()
name: string | null = null;


@alias("tool_calls")
@omitif("this.toolCalls.length == 0")
toolCalls: ToolCall[] = [];
}

Expand Down
14 changes: 11 additions & 3 deletions src/models/openai/embeddings.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// import { Box } from "as-container/assembly";
import { Model } from "../..";

// Reference: https://platform.openai.com/docs/api-reference/embeddings
Expand All @@ -18,9 +17,18 @@ export default class EmbeddingsModel extends Model<
class EmbeddingsInput {
input!: string; // todo: support other types of input (arrays, etc.)
model!: string;


@omitif("this.encodingFormat.type == 'float'")
encodingFormat: EncodingFormat = EncodingFormat.Float;
// dimensions: Box<i32> | null = null;
user: string = "";


@omitif("this.dimensions == -1")
dimensions: i32 = -1; // TODO: make this an `i32 | null` when supported


@omitnull()
user: string | null = null;
}


Expand Down
Loading