Files
TREK/server/tests/unit/nest/llm-parse/llm-client.factory.test.ts
T
Maurice 7a40225852 feat(llm-parse): read bookings on a ChatGPT plan
A ChatGPT sign-in only ever ran the assistant: parsing's clients call an
endpoint with a key, and a plan has none. AI connections now lends the plan
as a reader. Each document is one Responses call with the schema as the one
tool the model has to call (tool_choice required). The token is read and
refreshed per call by ChatgptAuthService, and a sign-in that has to be
renewed lends nothing.

- ResolvedLlmConfig is a union: ApiLlmConfig (what an admin configures) or
  PlanLlmConfig (provider chatgpt, a read function, never stored).
- ConnectionReadClient sends the text plus photo or scanned pages, and reads
  the filled shape, or the shape written as text; prose is unreadable.
- AiChatClientService.chatgptPlan is the one place that builds the plan's
  client, for the assistant and for parsing.
- Wiki: a ChatGPT sign-in reads bookings on its plan.
2026-11-13 20:49:08 +01:00

36 lines
1.6 KiB
TypeScript

import { AnthropicClient } from '../../../../src/nest/llm-parse/clients/anthropic.client';
import { ConnectionReadClient } from '../../../../src/nest/llm-parse/clients/connection-read.client';
import { OpenAiCompatibleClient } from '../../../../src/nest/llm-parse/clients/openai-compatible.client';
import { createLlmClient } from '../../../../src/nest/llm-parse/llm-client.factory';
import type { ResolvedLlmConfig } from '../../../../src/nest/llm-parse/llm-config';
import { describe, it, expect } from 'vitest';
const cfg = (provider: string): ResolvedLlmConfig =>
({ provider, model: 'm', baseUrl: 'http://x', multimodal: false }) as unknown as ResolvedLlmConfig;
describe('createLlmClient', () => {
it('returns the Anthropic client for the anthropic provider', () => {
expect(createLlmClient(cfg('anthropic'))).toBeInstanceOf(AnthropicClient);
});
it('returns the OpenAI-compatible client for openai and local', () => {
expect(createLlmClient(cfg('openai'))).toBeInstanceOf(OpenAiCompatibleClient);
expect(createLlmClient(cfg('local'))).toBeInstanceOf(OpenAiCompatibleClient);
});
it('reads a ChatGPT plan through the reader its connection lends', () => {
const plan: ResolvedLlmConfig = {
provider: 'chatgpt',
model: 'gpt-x',
vision: 'auto',
read: async () => ({ text: '' }),
};
expect(createLlmClient(plan)).toBeInstanceOf(ConnectionReadClient);
});
it('falls back to the OpenAI-compatible client for an unknown provider', () => {
expect(createLlmClient(cfg('something-else'))).toBeInstanceOf(OpenAiCompatibleClient);
});
});