Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions bun.lock
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
{
"lockfileVersion": 1,
"configVersion": 0,
"workspaces": {
"": {
"name": "judgeval",
"dependencies": {
"@opentelemetry/api": "^1.9.0",
"@opentelemetry/context-async-hooks": "^2.2.0",
"@opentelemetry/core": "^2.2.0",
"@opentelemetry/exporter-trace-otlp-http": "^0.207.0",
"@opentelemetry/resources": "^2.2.0",
Expand Down
14 changes: 4 additions & 10 deletions examples/simple_chat/instrumentation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,10 @@ import { Judgeval, type NodeTracer } from "judgeval";

export const client = Judgeval.create();

const initPromise = client.nodeTracer
.create({
projectName: "auto_instrumentation_example",
enableEvaluation: true,
enableMonitoring: true,
instrumentations: [new OpenAIInstrumentation()],
})
.then((t: NodeTracer) => {
return t;
});
const initPromise = client.nodeTracer.create({
projectName: "auto_instrumentation_example",
instrumentations: [new OpenAIInstrumentation()],
});

export async function getTracer(): Promise<NodeTracer> {
return await initPromise;
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "judgeval",
"version": "0.7.2",
"version": "0.7.3",
"description": "JavaScript/TypeScript client for Judgment evaluation platform",
"main": "./dist/index.cjs",
"module": "./dist/index.mjs",
Expand All @@ -26,7 +26,7 @@
"lint:fix": "eslint src/**/*.ts --fix --no-warn-ignored",
"format": "prettier --write \"src/**/*.ts\"",
"generate-client": "bunx tsx scripts/generate-client.ts && bun run format",
"test": "bun test",
"test": "bun test --coverage",
"clean": "rimraf dist",
"prepublishOnly": "bun run clean && bun run build",
"example": "bun scripts/run-example.ts"
Expand All @@ -48,6 +48,7 @@
},
"dependencies": {
"@opentelemetry/api": "^1.9.0",
"@opentelemetry/context-async-hooks": "^2.2.0",
"@opentelemetry/core": "^2.2.0",
"@opentelemetry/exporter-trace-otlp-http": "^0.207.0",
"@opentelemetry/resources": "^2.2.0",
Expand Down
6 changes: 1 addition & 5 deletions src/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,9 @@ export const JUDGMENT_API_URL = getEnvVar(
"JUDGMENT_API_URL",
"https://api.judgmentlabs.ai",
);
export const JUDGMENT_LLM_PROXY_URL = getEnvVar(
"JUDGMENT_LLM_PROXY_URL",
"https://api.judgmentlabs.ai/llm/proxy/v1",
);
export const JUDGMENT_DEFAULT_GPT_MODEL = getEnvVar(
"JUDGMENT_DEFAULT_GPT_MODEL",
"gpt-4.1",
"gpt-5-mini",
);
export const JUDGMENT_ENABLE_MONITORING = getEnvVar(
"JUDGMENT_ENABLE_MONITORING",
Expand Down
4 changes: 3 additions & 1 deletion src/scorers/promptScorer/PromptScorer.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { ScorerConfig } from "../../internal/api/models";
import { APIScorerType } from "../../data/APIScorerType";
import type { ScorerConfig } from "../../internal/api/models";
import { BaseScorer } from "../BaseScorer";

export interface PromptScorerConfig {
Expand Down Expand Up @@ -91,9 +91,11 @@ export class PromptScorer extends BaseScorer {
if (this._options) {
kwargs.options = this._options;
}

if (this._model) {
kwargs.model = this._model;
}

if (this._description) {
kwargs.description = this._description;
}
Expand Down
43 changes: 14 additions & 29 deletions src/scorers/promptScorer/PromptScorerFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import type {
FetchPromptScorersRequest,
FetchPromptScorersResponse,
} from "../../internal/api/models";
import { PromptScorer, type PromptScorerConfig } from "./PromptScorer";
import { Logger } from "../../utils";
import { PromptScorer } from "./PromptScorer";

export class PromptScorerFactory {
private readonly client: JudgmentApiClient;
Expand All @@ -17,12 +18,12 @@ export class PromptScorerFactory {
this.isTrace = isTrace;
}

async get(name: string): Promise<PromptScorer> {
async get(name: string): Promise<PromptScorer | null> {
const cacheKey = this.getCacheKey(name);
const cached = PromptScorerFactory.cache.get(cacheKey);

if (cached) {
return this.createFromModel(cached, name);
return this._create(cached, name);
}

try {
Expand Down Expand Up @@ -51,34 +52,18 @@ export class PromptScorerFactory {
}

PromptScorerFactory.cache.set(cacheKey, scorer);
return this.createFromModel(scorer, name);
return this._create(scorer, name);
} catch (error) {
if (error instanceof Error) {
throw error;
}
throw new Error(`Failed to fetch prompt scorer '${name}': ${error}`);
}
}

create(config: PromptScorerConfig): PromptScorer {
if (!config.name) {
throw new Error("Name is required");
}
if (!config.prompt) {
throw new Error("Prompt is required");
Logger.error(`Failed to fetch prompt scorer '${name}': ${error}`);
return null;
}

return new PromptScorer({
...config,
isTrace: this.isTrace,
});
}

private createFromModel(model: APIPromptScorer, name: string): PromptScorer {
private _create(scorer: APIPromptScorer, name: string): PromptScorer {
let options: Record<string, number> | undefined;
if (model.options && typeof model.options === "object") {
if (scorer.options && typeof scorer.options === "object") {
options = {};
for (const [key, value] of Object.entries(model.options)) {
for (const [key, value] of Object.entries(scorer.options)) {
if (typeof value === "number") {
options[key] = value;
}
Expand All @@ -87,11 +72,11 @@ export class PromptScorerFactory {

return new PromptScorer({
name,
prompt: model.prompt,
threshold: model.threshold,
prompt: scorer.prompt,
threshold: scorer.threshold,
options: options ?? {},
model: model.model ?? JUDGMENT_DEFAULT_GPT_MODEL,
description: model.description ?? "",
model: scorer.model ?? JUDGMENT_DEFAULT_GPT_MODEL,
description: scorer.description ?? "",
isTrace: this.isTrace,
});
}
Expand Down
Loading
Loading