Skip to content

Commit 2310455

Browse files
committed
refactor: implement unified client overloading system
- Create new unified `overloadClient` function that handles both log and call methods - Simplify client initialization by directly overloading parent class instances - Replace SyncClient with direct FileSyncer instance for cleaner file handling - Standardize tracing context, local file handling, and evaluation context across all client types
1 parent efa682b commit 2310455

3 files changed

Lines changed: 233 additions & 136 deletions

File tree

src/humanloop.client.ts

Lines changed: 9 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,6 @@ import { OpenAIInstrumentation } from "@traceloop/instrumentation-openai";
88
import { HumanloopClient as BaseHumanloopClient } from "./Client";
99
import { ChatMessage } from "./api";
1010
import { Evaluations as BaseEvaluations } from "./api/resources/evaluations/client/Client";
11-
import { Evaluators } from "./api/resources/evaluators/client/Client";
12-
import { Flows } from "./api/resources/flows/client/Client";
13-
import { Prompts } from "./api/resources/prompts/client/Client";
14-
import { Tools } from "./api/resources/tools/client/Client";
1511
import { ToolKernelRequest } from "./api/types/ToolKernelRequest";
1612
import { flowUtilityFactory } from "./decorators/flow";
1713
import { promptDecoratorFactory } from "./decorators/prompt";
@@ -28,8 +24,8 @@ import {
2824
} from "./evals/types";
2925
import { HumanloopSpanExporter } from "./otel/exporter";
3026
import { HumanloopSpanProcessor } from "./otel/processor";
31-
import { overloadCall, overloadLog } from "./overload";
32-
import { SyncClient } from "./sync";
27+
import { overloadClient } from "./overload";
28+
import { FileSyncer } from "./sync";
3329
import { SDK_VERSION } from "./version";
3430

3531
const RED = "\x1b[91m";
@@ -235,16 +231,12 @@ export interface HumanloopClientOptions extends BaseHumanloopClient.Options {
235231

236232
export class HumanloopClient extends BaseHumanloopClient {
237233
protected readonly _evaluations: ExtendedEvaluations;
238-
protected readonly _prompts_overloaded: Prompts;
239-
protected readonly _flows_overloaded: Flows;
240-
protected readonly _tools_overloaded: Tools;
241-
protected readonly _evaluators_overloaded: Evaluators;
242234
protected readonly instrumentProviders: {
243235
OpenAI?: any;
244236
Anthropic?: any;
245237
CohereAI?: any;
246238
};
247-
protected readonly _syncClient: SyncClient;
239+
protected readonly _fileSyncer: FileSyncer;
248240
protected readonly useLocalFiles: boolean;
249241

250242
protected get opentelemetryTracer(): Tracer {
@@ -292,21 +284,17 @@ export class HumanloopClient extends BaseHumanloopClient {
292284
);
293285
}
294286

295-
this._syncClient = new SyncClient(this, {
287+
this._fileSyncer = new FileSyncer(this, {
296288
baseDir: options.localFilesDirectory || "humanloop",
297289
cacheSize: options.cacheSize,
298290
});
299291

300292
this.instrumentProviders = options.instrumentProviders || {};
301293

302-
this._prompts_overloaded = overloadLog(super.prompts);
303-
this._prompts_overloaded = overloadCall(this._prompts_overloaded);
304-
305-
this._tools_overloaded = overloadLog(super.tools);
306-
307-
this._flows_overloaded = overloadLog(super.flows);
308-
309-
this._evaluators_overloaded = overloadLog(super.evaluators);
294+
overloadClient(super.prompts, this._fileSyncer, this.useLocalFiles);
295+
overloadClient(super.flows, this._fileSyncer, this.useLocalFiles);
296+
overloadClient(super.tools, this._fileSyncer, this.useLocalFiles);
297+
overloadClient(super.evaluators, this._fileSyncer, this.useLocalFiles);
310298

311299
this._evaluations = new ExtendedEvaluations(options, this);
312300

@@ -652,26 +640,10 @@ ${RESET}`,
652640
path?: string,
653641
environment?: string,
654642
): Promise<[string[], string[]]> {
655-
return this._syncClient.pull(path, environment);
643+
return this._fileSyncer.pull(path, environment);
656644
}
657645

658646
public get evaluations(): ExtendedEvaluations {
659647
return this._evaluations;
660648
}
661-
662-
public get prompts(): Prompts {
663-
return this._prompts_overloaded;
664-
}
665-
666-
public get flows(): Flows {
667-
return this._flows_overloaded;
668-
}
669-
670-
public get tools(): Tools {
671-
return this._tools_overloaded;
672-
}
673-
674-
public get evaluators(): Evaluators {
675-
return this._evaluators_overloaded;
676-
}
677649
}

0 commit comments

Comments
 (0)