Updated LLM config and added read_webpage
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import {Anthropic as anthropic} from '@anthropic-ai/sdk';
|
||||
import {findByProp, objectMap, JSONSanitize, JSONAttemptParse, deepCopy} from '@ztimson/utils';
|
||||
import {findByProp, objectMap, JSONSanitize, JSONAttemptParse} from '@ztimson/utils';
|
||||
import {AbortablePromise, Ai} from './ai.ts';
|
||||
import {LLMMessage, LLMRequest} from './llm.ts';
|
||||
import {LLMProvider} from './provider.ts';
|
||||
@@ -51,16 +51,16 @@ export class Anthropic extends LLMProvider {
|
||||
ask(message: string, options: LLMRequest = {}): AbortablePromise<LLMMessage[]> {
|
||||
const controller = new AbortController();
|
||||
const response = new Promise<any>(async (res, rej) => {
|
||||
let history = this.fromStandard([...options.history || [], {role: 'user', content: message, timestamp: Date.now()}]);
|
||||
const original = deepCopy(history);
|
||||
let history = [...options.history || [], {role: 'user', content: message, timestamp: Date.now()}];
|
||||
if(options.compress) history = await this.ai.language.compressHistory(<any>history, options.compress.max, options.compress.min, options);
|
||||
history = this.fromStandard(<any>history);
|
||||
|
||||
const tools = options.tools || this.ai.options.tools || [];
|
||||
const tools = options.tools || this.ai.options.llm?.tools || [];
|
||||
const requestParams: any = {
|
||||
model: options.model || this.model,
|
||||
max_tokens: options.max_tokens || this.ai.options.max_tokens || 4096,
|
||||
system: options.system || this.ai.options.system || '',
|
||||
temperature: options.temperature || this.ai.options.temperature || 0.7,
|
||||
max_tokens: options.max_tokens || this.ai.options.llm?.max_tokens || 4096,
|
||||
system: options.system || this.ai.options.llm?.system || '',
|
||||
temperature: options.temperature || this.ai.options.llm?.temperature || 0.7,
|
||||
tools: tools.map(t => ({
|
||||
name: t.name,
|
||||
description: t.description,
|
||||
@@ -117,7 +117,6 @@ export class Anthropic extends LLMProvider {
|
||||
const toolCalls = resp.content.filter((c: any) => c.type === 'tool_use');
|
||||
if(toolCalls.length && !controller.signal.aborted) {
|
||||
history.push({role: 'assistant', content: resp.content});
|
||||
original.push({role: 'assistant', content: resp.content});
|
||||
const results = await Promise.all(toolCalls.map(async (toolCall: any) => {
|
||||
const tool = tools.find(findByProp('name', toolCall.name));
|
||||
if(options.stream) options.stream({tool: toolCall.name});
|
||||
|
||||
Reference in New Issue
Block a user