import { ChatLogs } from '../index.js';
export class LlmQuery {
    llm;
    tokenizer;
    logs;
    constructor(llm, tokenizer, logs = new ChatLogs()) {
        this.llm = llm;
        this.tokenizer = tokenizer;
        this.logs = logs;
    }
    async content(opts) {
        const response = await this.response(opts);
        return response?.content ?? '';
    }
    async response(opts) {
        const response = await this.llm.getResponse(this.logs, undefined, opts);
        if (!response || !response.content) {
            throw new Error('No response from LLM');
        }
        this.logs.add('temporary', [{ role: response.role, content: response.content }], [this.tokenizer.encode(response.content).length]);
        return response;
    }
    async ask(question, opts) {
        this.logs.add('temporary', [{ role: 'user', content: question }], [this.tokenizer.encode(question).length]);
        const response = await this.llm.getResponse(this.logs, undefined, { max_tokens: opts?.maxResponseTokens, model: opts?.model });
        if (!response || !response.content) {
            throw new Error('No response from LLM');
        }
        this.logs.add('temporary', [{ role: response.role, content: response.content }], [this.tokenizer.encode(response.content).length]);
        return response?.content ?? '';
    }
}
