import { BaseLLM } from "../index.js";
class CustomLLMClass extends BaseLLM {
    get providerName() {
        return "custom";
    }
    customStreamCompletion;
    customStreamChat;
    constructor(custom) {
        super(custom.options || { model: "custom" });
        this.customStreamCompletion = custom.streamCompletion;
        this.customStreamChat = custom.streamChat;
    }
    async *_streamChat(messages, options) {
        if (this.customStreamChat) {
            for await (const content of this.customStreamChat(messages, options, (...args) => this.fetch(...args))) {
                yield { role: "assistant", content };
            }
        }
        else {
            for await (const update of super._streamChat(messages, options)) {
                yield update;
            }
        }
    }
    async *_streamComplete(prompt, options) {
        if (this.customStreamCompletion) {
            for await (const content of this.customStreamCompletion(prompt, options, (...args) => this.fetch(...args))) {
                yield content;
            }
        }
        else if (this.customStreamChat) {
            for await (const content of this.customStreamChat([{ role: "user", content: prompt }], options, (...args) => this.fetch(...args))) {
                yield content;
            }
        }
        else {
            throw new Error("Either streamCompletion or streamChat must be defined in a custom LLM in config.ts");
        }
    }
}
export default CustomLLMClass;
