halkyon/packages/halkyon_llm/test/endpoint_test.dart

82 lines
2.2 KiB
Dart
Raw Normal View History

import 'package:halkyon_llm/halkyon_llm.dart';
import 'package:test/test.dart';
LlmEndpoint _at(String baseUrl) => LlmEndpoint(
protocol: LlmProtocol.openai,
model: 'm',
apiKey: '',
baseUrl: baseUrl,
);
void main() {
test("takes the protocol's own address where none is given", () {
final endpoint = LlmEndpoint(
protocol: LlmProtocol.anthropic,
model: 'm',
apiKey: 'k',
);
expect(endpoint.host, 'api.anthropic.com');
expect(endpoint.onThisMachine, isFalse);
});
test('refuses http beyond the same machine or network', () {
expect(() => _at('http://example.com/v1'), throwsFormatException);
expect(_at('http://192.168.1.20:11434/v1').host, '192.168.1.20');
});
test('knows a model on this machine: a loopback address or localhost '
'(ADR 0021, D9)', () {
for (final url in [
'http://127.0.0.1:11434/v1',
'http://127.8.0.1/v1',
'http://[::1]:8080/v1',
'http://localhost:11434/v1',
'http://ollama.localhost/v1',
'https://LOCALHOST/v1',
]) {
expect(_at(url).onThisMachine, isTrue, reason: url);
}
});
test('takes nothing else for this machine: the network may be shared', () {
for (final url in [
'http://192.168.1.20:11434/v1',
'http://10.0.0.2/v1',
'http://[fd00::2]/v1',
'http://ollama/v1',
'http://gpu.local/v1',
'https://localhost.example.com/v1',
'https://api.openai.com/v1',
]) {
expect(_at(url).onThisMachine, isFalse, reason: url);
}
});
group('effort (D63)', () {
test('runs from low to max, by name', () {
expect(LlmEffort.values.map((effort) => effort.key), [
'low',
'medium',
'high',
'xhigh',
'max',
]);
expect(LlmEffort.named('xhigh'), LlmEffort.xhigh);
expect(LlmEffort.named('XHIGH'), isNull);
expect(LlmEffort.named('minimal'), isNull);
});
test('leaves more room for output the higher it is: what the model thinks '
'counts towards the ceiling', () {
expect(LlmEffort.values.map((effort) => effort.outputCeiling), [
8192,
12288,
16384,
32768,
65536,
]);
expect(LlmEffort.defaultOutputCeiling, LlmEffort.high.outputCeiling);
});
});
}