-
Notifications
You must be signed in to change notification settings - Fork 319
/
anthropic.ts
38 lines (34 loc) · 1.12 KB
/
anthropic.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import { Settings } from "../Settings.js";
import type {
ChatEngineParamsNonStreaming,
ChatEngineParamsStreaming,
EngineResponse,
} from "../index.edge.js";
import { Anthropic } from "../llm/anthropic.js";
import { LLMAgent, LLMAgentWorker, type LLMAgentParams } from "./llm.js";
export type AnthropicAgentParams = LLMAgentParams;
export class AnthropicAgentWorker extends LLMAgentWorker {}
export class AnthropicAgent extends LLMAgent {
constructor(params: AnthropicAgentParams) {
const llm =
params.llm ??
(Settings.llm instanceof Anthropic
? (Settings.llm as Anthropic)
: new Anthropic());
super({
...params,
llm,
});
}
async chat(params: ChatEngineParamsNonStreaming): Promise<EngineResponse>;
async chat(params: ChatEngineParamsStreaming): Promise<never>;
override async chat(
params: ChatEngineParamsNonStreaming | ChatEngineParamsStreaming,
) {
if (params.stream) {
// Anthropic does support this, but looks like it's not supported in the LITS LLM
throw new Error("Anthropic does not support streaming");
}
return super.chat(params);
}
}