Skip to content

Commit

Permalink
fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
isahers1 committed Dec 11, 2024
1 parent 39ef31f commit e36175e
Show file tree
Hide file tree
Showing 3 changed files with 276 additions and 55 deletions.
6 changes: 3 additions & 3 deletions js/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import {
ExampleUpdateWithAttachments,
UpdateExamplesResponse,
RawExample,
AttachmentInfo
AttachmentInfo,
} from "./schemas.js";
import {
convertLangChainMessageToExample,
Expand Down Expand Up @@ -2817,7 +2817,7 @@ export class Client implements LangSmithTracingClientInterface {
params.append("filter", filter);
}
if (includeAttachments === true) {
["attachment_urls", "outputs", "metadata"].forEach(field =>
["attachment_urls", "outputs", "metadata"].forEach((field) =>
params.append("select", field)
);
}
Expand Down Expand Up @@ -4103,7 +4103,7 @@ export class Client implements LangSmithTracingClientInterface {
{
method: "PATCH",
body: JSON.stringify(payload),
headers: {
headers: {
...this.headers,
"Content-Type": "application/json",
},
Expand Down
79 changes: 43 additions & 36 deletions js/src/evaluation/_runner.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
import { Client, RunTree, RunTreeConfig } from "../index.js";
import { AttachmentInfo, BaseRun, Example, KVMap, Run, TracerSession } from "../schemas.js";
import {
AttachmentInfo,
BaseRun,
Example,
KVMap,
Run,
TracerSession,
} from "../schemas.js";
import { traceable } from "../traceable.js";
import { getDefaultRevisionId, getGitInfo } from "../utils/_git.js";
import { assertUuid } from "../utils/_uuid.js";
Expand All @@ -22,7 +29,10 @@ import {
ComparativeEvaluator,
} from "./evaluate_comparative.js";

export type TargetConfigT = KVMap & { attachments?: Record<string, AttachmentInfo>, callbacks?: any }
export type TargetConfigT = KVMap & {
attachments?: Record<string, AttachmentInfo>;
callbacks?: any;
};
type StandardTargetT<TInput = any, TOutput = KVMap> =
| ((input: TInput, config?: TargetConfigT) => Promise<TOutput>)
| ((input: TInput, config?: TargetConfigT) => TOutput)
Expand Down Expand Up @@ -282,12 +292,10 @@ export class _ExperimentManager {
if (!this._data) {
throw new Error("Data not provided in this experiment.");
}
const unresolvedData = _resolveData(
this._data,
{
client: this.client,
includeAttachments: this._includeAttachments
});
const unresolvedData = _resolveData(this._data, {
client: this.client,
includeAttachments: this._includeAttachments,
});
if (!this._examples) {
this._examples = [];
}
Expand Down Expand Up @@ -956,7 +964,6 @@ async function _evaluate(
client
);


let manager = await new _ExperimentManager({
data: Array.isArray(standardFields.data) ? undefined : standardFields.data,
examples: Array.isArray(standardFields.data)
Expand Down Expand Up @@ -998,7 +1005,7 @@ async function _forward(
experimentName: string,
metadata: KVMap,
client: Client,
includeAttachments?: boolean,
includeAttachments?: boolean
): Promise<_ForwardResults> {
let run: BaseRun | null = null;

Expand All @@ -1023,31 +1030,31 @@ async function _forward(
const wrappedFn =
"invoke" in fn
? traceable(async (inputs) => {
let langChainCallbacks;
try {
// TODO: Deprecate this and rely on interop on 0.2 minor bump.
const { getLangchainCallbacks } = await import("../langchain.js");
langChainCallbacks = await getLangchainCallbacks();
} catch {
// no-op
}
// Issue with retrieving LangChain callbacks, rely on interop
if (langChainCallbacks === undefined && !includeAttachments) {
return await fn.invoke(inputs);
} else if (langChainCallbacks === undefined && includeAttachments) {
return await fn.invoke(inputs, {
attachments: example.attachments,
});
} else if (!includeAttachments) {
return await fn.invoke(inputs, { callbacks: langChainCallbacks });
} else {
return await fn.invoke(inputs, {
attachments: example.attachments,
callbacks: langChainCallbacks
});
}
}, options)
: traceable(fn, options);
let langChainCallbacks;
try {
// TODO: Deprecate this and rely on interop on 0.2 minor bump.
const { getLangchainCallbacks } = await import("../langchain.js");
langChainCallbacks = await getLangchainCallbacks();
} catch {
// no-op
}
// Issue with retrieving LangChain callbacks, rely on interop
if (langChainCallbacks === undefined && !includeAttachments) {
return await fn.invoke(inputs);
} else if (langChainCallbacks === undefined && includeAttachments) {
return await fn.invoke(inputs, {
attachments: example.attachments,
});
} else if (!includeAttachments) {
return await fn.invoke(inputs, { callbacks: langChainCallbacks });
} else {
return await fn.invoke(inputs, {
attachments: example.attachments,
callbacks: langChainCallbacks,
});
}
}, options)
: traceable(fn, options);

try {
if (includeAttachments && !("invoke" in fn)) {
Expand Down Expand Up @@ -1237,4 +1244,4 @@ function _isCallable(
typeof target === "function" ||
("invoke" in target && typeof target.invoke === "function")
);
}
}
Loading

0 comments on commit e36175e

Please sign in to comment.