Skip to content

Commit 5d7c0f3

Browse files
committed
feat: rome is rising
1 parent f04c35f commit 5d7c0f3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

83 files changed

+3801
-1130
lines changed

src/ax/ai/balance.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ export class AxBalancer implements AxAIService {
1818
private services: AxAIService[];
1919
private currentServiceIndex: number = 0;
2020
private currentService: AxAIService;
21-
private serviceMap: Record<string, AxAIService> = {};
2221

2322
constructor(services: readonly AxAIService[]) {
2423
if (services.length === 0) {

src/ax/db/cloudflare.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ export class AxDBCloudflare extends AxDBBase {
6262

6363
override _upsert = async (
6464
req: Readonly<AxDBUpsertRequest>,
65-
update?: boolean,
65+
_update?: boolean,
6666
options?: Readonly<AxDBCloudflareOpOptions>
6767
): Promise<AxDBUpsertResponse> => {
6868
const res = (await apiCall(

src/ax/db/weaviate.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ export class AxDBWeaviate extends AxDBBase {
196196

197197
const matches = resMatches.map((match) => {
198198
return {
199-
id: match.id as string,
199+
id: match['id'] as string,
200200
score: 1,
201201
metadata: match
202202
};

src/ax/docs/manager.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,9 @@ export class AxDBManager {
9494
values: embedding,
9595
metadata: { text: batch[index] ?? '' }
9696
}))
97-
.filter((v) => v.metadata?.text && v.metadata?.text.length > 0);
97+
.filter(
98+
(v) => v.metadata?.['text'] && v.metadata?.['text'].length > 0
99+
);
98100

99101
// Batch upsert embeddings
100102
await this.db.batchUpsert(embeddings);
@@ -135,8 +137,11 @@ export class AxDBManager {
135137

136138
for (const { matches } of queryResults) {
137139
const m = matches
138-
.filter((v) => v.metadata?.text && v.metadata?.text.length > 0)
139-
.map(({ score, metadata }) => ({ score, text: metadata?.text ?? '' }));
140+
.filter((v) => v.metadata?.['text'] && v.metadata?.['text'].length > 0)
141+
.map(({ score, metadata }) => ({
142+
score,
143+
text: metadata?.['text'] ?? ''
144+
}));
140145

141146
const tp = topPercent && topPercent > 1 ? topPercent / 100 : topPercent;
142147
const resultItems = tp ? getTopInPercent(m, tp) : m;

src/ax/dsp/generate.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -354,9 +354,9 @@ export class AxGenerate<
354354
span?: AxSpan
355355
): Promise<OUT> {
356356
const ai = options?.ai ?? this.ai;
357-
const maxRetries = this.options?.maxRetries ?? options?.maxRetries ?? 5;
358-
const maxSteps = this.options?.maxSteps ?? options?.maxSteps ?? 10;
359-
const mem = this.options?.mem ?? options?.mem ?? new AxMemory();
357+
const maxRetries = options?.maxRetries ?? this.options?.maxRetries ?? 5;
358+
const maxSteps = options?.maxSteps ?? this.options?.maxSteps ?? 10;
359+
const mem = options?.mem ?? this.options?.mem ?? new AxMemory();
360360
const canStream = ai.getFeatures().streaming;
361361

362362
let err: ValidationError | AxAssertionError | undefined;
@@ -521,14 +521,14 @@ function parseFunctions(
521521
// typeof f.args === 'object' ? JSON.stringify(f.args) : f.args;
522522
// }
523523
return funcs;
524-
} else if (values.functionName) {
524+
} else if (values['functionName']) {
525525
const { functionName, functionArguments } = values as {
526526
functionName: string;
527527
functionArguments: string;
528528
other: object;
529529
};
530-
delete values.functionName;
531-
delete values.functionArguments;
530+
delete values['functionName'];
531+
delete values['functionArguments'];
532532

533533
return [
534534
{

src/ax/dsp/router.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ export class AxRoute {
2828

2929
export class AxRouter {
3030
private readonly ai: AxAIService;
31-
private routes: AxRoute[] = [];
3231

3332
private db: AxDBMemory;
3433
private debug?: boolean;

src/ax/funcs/code.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,16 @@ export enum AxJSInterpreterPermission {
1616
PROCESS = 'process'
1717
}
1818

19+
type Context = {
20+
console: Console;
21+
fs: unknown;
22+
http: unknown;
23+
https: unknown;
24+
os: unknown;
25+
crypto: unknown;
26+
process: unknown;
27+
};
28+
1929
export class AxJSInterpreter {
2030
private permissions: readonly AxJSInterpreterPermission[];
2131

@@ -28,7 +38,7 @@ export class AxJSInterpreter {
2838
}
2939

3040
private codeInterpreterJavascript(code: string): unknown {
31-
const context: { [key: string]: unknown } = { console };
41+
const context: Partial<Context> = { console };
3242

3343
if (this.permissions.includes(AxJSInterpreterPermission.FS)) {
3444
context.fs = _fs;

src/ax/mem/memory.ts

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
import type { AxChatRequest, AxChatResponseResult } from '../ai/types.js';
22

3-
import type { AxAIMemory } from './types.js';
4-
5-
type Writeable<T> = { -readonly [P in keyof T]: T[P] };
3+
import type { AxAIMemory, AxWritableChatPrompt } from './types.js';
64

75
export class AxMemory implements AxAIMemory {
8-
private data: AxChatRequest['chatPrompt'] = [];
9-
private sdata = new Map<string, AxChatRequest['chatPrompt']>();
6+
private data: AxWritableChatPrompt = [];
7+
private sdata = new Map<string, AxWritableChatPrompt>();
108
private limit: number;
119

1210
constructor(limit = 50) {
@@ -53,9 +51,7 @@ export class AxMemory implements AxAIMemory {
5351
): void {
5452
const items = this.get(sessionId);
5553

56-
const lastItem = items.at(-1) as unknown as Writeable<
57-
AxChatRequest['chatPrompt'][0]
58-
>;
54+
const lastItem = items.at(-1);
5955

6056
if (!lastItem || lastItem.role !== 'assistant') {
6157
this.addResult({ content, name, functionCalls }, sessionId);
@@ -77,10 +73,6 @@ export class AxMemory implements AxAIMemory {
7773
return this.get(sessionId);
7874
}
7975

80-
peek(sessionId?: string): AxChatRequest['chatPrompt'] {
81-
return this.get(sessionId);
82-
}
83-
8476
getLast(sessionId?: string): AxChatRequest['chatPrompt'][0] | undefined {
8577
const d = this.get(sessionId);
8678
return d.at(-1);
@@ -94,7 +86,7 @@ export class AxMemory implements AxAIMemory {
9486
}
9587
}
9688

97-
private get(sessionId?: string): AxChatRequest['chatPrompt'] {
89+
private get(sessionId?: string): AxWritableChatPrompt {
9890
if (!sessionId) {
9991
return this.data;
10092
}

src/ax/mem/types.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import type { AxChatRequest, AxChatResponseResult } from '../ai/index.js';
22

3+
type Writeable<T> = { -readonly [P in keyof T]: T[P] };
4+
export type AxWritableChatPrompt = Writeable<AxChatRequest['chatPrompt'][0]>[];
5+
36
export interface AxAIMemory {
47
add(
58
result: Readonly<
@@ -14,7 +17,6 @@ export interface AxAIMemory {
1417
): void;
1518

1619
history(sessionId?: string): AxChatRequest['chatPrompt'];
17-
peek(sessionId?: string): AxChatRequest['chatPrompt'];
1820
reset(sessionId?: string): void;
1921

2022
getLast(sessionId?: string): AxChatRequest['chatPrompt'][0] | undefined;

src/ax/util/apicall.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export const apiCall = async <TRequest = unknown, TResponse = unknown>(
3535
>,
3636
json: TRequest
3737
): Promise<TResponse | ReadableStream<TResponse>> => {
38-
const baseUrl = new URL(process.env.PROXY ?? api.url);
38+
const baseUrl = new URL(process.env['PROXY'] ?? api.url);
3939
const apiPath = path.join(baseUrl.pathname, api.name ?? '/', baseUrl.search);
4040
const apiUrl = new URL(apiPath, baseUrl);
4141

0 commit comments

Comments
 (0)