mirror of
https://github.com/logancyang/obsidian-copilot.git
synced 2026-07-22 07:50:24 +00:00
29 lines
902 B
TypeScript
29 lines
902 B
TypeScript
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
import { ChatOpenAI } from "langchain/chat_models/openai";
|
|
import { OpenAIEmbeddings } from "langchain/embeddings/openai";
|
|
import OpenAI from "openai";
|
|
|
|
// Migrated to OpenAI v4 client from v3: https://github.com/openai/openai-node/discussions/217
|
|
export class ProxyChatOpenAI extends ChatOpenAI {
|
|
constructor(fields?: any) {
|
|
super(fields ?? {});
|
|
|
|
// Reinitialize the client with the updated clientConfig
|
|
this["client"] = new OpenAI({
|
|
...this["clientConfig"],
|
|
baseURL: fields.openAIProxyBaseUrl,
|
|
});
|
|
}
|
|
}
|
|
|
|
export class ProxyOpenAIEmbeddings extends OpenAIEmbeddings {
|
|
constructor(fields?: any) {
|
|
super(fields ?? {});
|
|
|
|
// Reinitialize the client with the updated clientConfig
|
|
this["client"] = new OpenAI({
|
|
...this["clientConfig"],
|
|
baseURL: fields.openAIEmbeddingProxyBaseUrl,
|
|
});
|
|
}
|
|
}
|