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
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,10 @@ export function convertOpenAPISchemaToJSONSchema(
);
}
if (schema.type === "array") {
const openAPIItems = spec.getSchema(schema.items ?? {});
return {
type: "array",
items: convertOpenAPISchemaToJSONSchema(schema.items ?? {}, spec),
items: convertOpenAPISchemaToJSONSchema(openAPIItems, spec),
minItems: schema.minItems,
maxItems: schema.maxItems,
} as JsonSchema7ArrayType;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { test, expect } from "vitest";
import { test, expect } from "@jest/globals";

import { OpenAPIV3, OpenAPIV3_1 } from "openapi-types";
import {
Expand Down Expand Up @@ -69,6 +69,21 @@ test("Test convert OpenAPI params to JSON Schema", async () => {
},
},
},
{
name: "refParam",
in: "query",
schema: {
$ref: "#/components/schemas/RefObject",
},
},
{
name: "refArrayParam",
in: "query",
schema: {
type: "array",
items: { $ref: "#/components/schemas/RefObject" },
},
},
{
name: "nestedObjectInArrayParam",
in: "query",
Expand Down Expand Up @@ -147,6 +162,21 @@ test("Test convert OpenAPI params to JSON Schema", async () => {
},
},
},
components: {
schemas: {
RefObject: {
type: "object",
properties: {
foo: {
type: "string",
},
bar: {
type: "number",
},
},
},
},
},
});

const createWidget = spec.getOperation(
Expand Down Expand Up @@ -225,6 +255,26 @@ test("Test convert OpenAPI params to JSON Schema", async () => {
expect(typedStringArrayParamSchema.items).not.toBeUndefined();
expectType("string", typedStringArrayParamSchema.items);

const refParamSchema = convertOpenAPISchemaToJSONSchema(
getParamSchema(createWidget, "refParam"),
spec
);
const typedRefParamSchema = expectType("object", refParamSchema);
expectType("string", typedRefParamSchema.properties.foo);
expectType("number", typedRefParamSchema.properties.bar);

const refArrayParamSchema = convertOpenAPISchemaToJSONSchema(
getParamSchema(createWidget, "refArrayParam"),
spec
);
const typedRefArrayParamSchema = expectType("array", refArrayParamSchema);
const typedRefArrayParamSchemaItems = expectType(
"object",
typedRefArrayParamSchema.items
);
expectType("string", typedRefArrayParamSchemaItems.properties.foo);
expectType("number", typedRefArrayParamSchemaItems.properties.bar);

const nestedObjectInArrayParamSchema = convertOpenAPISchemaToJSONSchema(
getParamSchema(createWidget, "nestedObjectInArrayParam"),
spec
Expand Down
18 changes: 12 additions & 6 deletions libs/langchain-core/src/callbacks/manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1251,12 +1251,18 @@ export class CallbackManager
if (tracingV2Enabled) {
const tracerV2 = new LangChainTracer();
callbackManager.addHandler(tracerV2, true);

// handoff between langchain and langsmith/traceable
// override the parent run ID
callbackManager._parentRunId =
LangChainTracer.getTraceableRunTree()?.id ??
callbackManager._parentRunId;
}
}
if (tracingV2Enabled) {
// handoff between langchain and langsmith/traceable
// override the parent run ID
const implicitRunTree = LangChainTracer.getTraceableRunTree();
if (implicitRunTree && callbackManager._parentRunId === undefined) {
callbackManager._parentRunId = implicitRunTree.id;
const tracerV2 = callbackManager.handlers.find(
(handler) => handler.name === "langchain_tracer"
) as LangChainTracer | undefined;
tracerV2?.updateFromRunTree(implicitRunTree);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { traceable } from "langsmith/traceable";
import { RunnableLambda } from "../../runnables/base.js";
import { BaseMessage, HumanMessage } from "../../messages/index.js";
import { awaitAllCallbacks } from "../../singletons/callbacks.js";
import { LangChainTracer } from "../tracer_langchain.js";

test("traceables double nested within runnables with batching", async () => {
const aiGreet = traceable(
Expand All @@ -27,3 +28,67 @@ test("traceables double nested within runnables with batching", async () => {

await awaitAllCallbacks();
});

test("deep nesting with manual tracer passed", async () => {
const aiGreet = traceable(
async (msg: BaseMessage) => {
const child = RunnableLambda.from(async () => {
const grandchild = RunnableLambda.from(async () => {
const greatGrandchild = traceable(
async () => {
const greatGreatGrandchild = RunnableLambda.from(async () => {
return [
new HumanMessage({ content: "From great great grandchild!" }),
];
}).withConfig({ runName: "greatGreatGrandchild" });
return greatGreatGrandchild.invoke({});
},
{ name: "greatGrandchild", tracingEnabled: true }
);
return greatGrandchild({});
}).withConfig({ runName: "grandchild" });
return grandchild.invoke({});
}).withConfig({ runName: "child" });
return child.invoke([msg]);
},
{ name: "aiGreet", tracingEnabled: true }
);

const parent = RunnableLambda.from(async () => {
return aiGreet(new HumanMessage({ content: "Hello!" }));
}).withConfig({ runName: "parent" });

await parent.invoke(
{},
{
callbacks: [new LangChainTracer()],
}
);

await awaitAllCallbacks();
});

test("runnable nested within a traceable with manual tracer passed", async () => {
const child = RunnableLambda.from(async () => {
const grandchild = RunnableLambda.from(async () => {
return [new HumanMessage({ content: "From grandchild!" })];
}).withConfig({ runName: "grandchild" });
return grandchild.invoke({});
}).withConfig({ runName: "child" });

const parent = traceable(
async () => {
return child.invoke(
{},
{
callbacks: [new LangChainTracer()],
}
);
},
{ name: "parent", tracingEnabled: true }
);

await parent();

await awaitAllCallbacks();
});
Loading