Skip to content

Commit

Permalink
feat(adapters): extends OpenAI embedding options
Browse files Browse the repository at this point in the history
Ref: #176
Signed-off-by: Tomas Dvorak <toomas2d@gmail.com>
  • Loading branch information
Tomas2D committed Dec 13, 2024
1 parent d3c9364 commit ff96251
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/adapters/openai/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import type {
ChatCompletionUserMessageParam,
ChatCompletionAssistantMessageParam,
ChatModel,
EmbeddingCreateParams,
} from "openai/resources/index";

type Parameters = Omit<ChatCompletionCreateParams, "stream" | "messages" | "model">;
Expand Down Expand Up @@ -104,6 +105,9 @@ interface Input {
}

export type OpenAIChatLLMEvents = ChatLLMGenerateEvents<OpenAIChatLLMOutput>;
export interface OpenAIEmbeddingOptions
extends EmbeddingOptions,
Omit<EmbeddingCreateParams, "input" | "model"> {}

export class OpenAIChatLLM extends ChatLLM<OpenAIChatLLMOutput> {
public readonly emitter = Emitter.root.child<OpenAIChatLLMEvents>({
Expand Down Expand Up @@ -165,9 +169,13 @@ export class OpenAIChatLLM extends ChatLLM<OpenAIChatLLMOutput> {
};
}

async embed(input: BaseMessage[][], options?: EmbeddingOptions): Promise<EmbeddingOutput> {
async embed(
input: BaseMessage[][],
options: OpenAIEmbeddingOptions = {},
): Promise<EmbeddingOutput> {
const response = await this.client.embeddings.create(
{
...options,
model: this.modelId,
input: input.flatMap((messages) => messages).flatMap((msg) => msg.text),
},
Expand Down

0 comments on commit ff96251

Please sign in to comment.