Skip to content

Commit ce0a2d6

Browse files
authored
chore(langchain/v1): patch changes (#9171)
1 parent f212784 commit ce0a2d6

File tree

8 files changed

+618
-92
lines changed

8 files changed

+618
-92
lines changed

libs/langchain-classic/src/chains/openai_functions/openapi.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,9 +189,10 @@ export function convertOpenAPISchemaToJSONSchema(
189189
);
190190
}
191191
if (schema.type === "array") {
192+
const openAPIItems = spec.getSchema(schema.items ?? {});
192193
return {
193194
type: "array",
194-
items: convertOpenAPISchemaToJSONSchema(schema.items ?? {}, spec),
195+
items: convertOpenAPISchemaToJSONSchema(openAPIItems, spec),
195196
minItems: schema.minItems,
196197
maxItems: schema.maxItems,
197198
} as JsonSchema7ArrayType;

libs/langchain-classic/src/chains/openai_functions/tests/openapi.test.ts

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { test, expect } from "vitest";
1+
import { test, expect } from "@jest/globals";
22

33
import { OpenAPIV3, OpenAPIV3_1 } from "openapi-types";
44
import {
@@ -69,6 +69,21 @@ test("Test convert OpenAPI params to JSON Schema", async () => {
6969
},
7070
},
7171
},
72+
{
73+
name: "refParam",
74+
in: "query",
75+
schema: {
76+
$ref: "#/components/schemas/RefObject",
77+
},
78+
},
79+
{
80+
name: "refArrayParam",
81+
in: "query",
82+
schema: {
83+
type: "array",
84+
items: { $ref: "#/components/schemas/RefObject" },
85+
},
86+
},
7287
{
7388
name: "nestedObjectInArrayParam",
7489
in: "query",
@@ -147,6 +162,21 @@ test("Test convert OpenAPI params to JSON Schema", async () => {
147162
},
148163
},
149164
},
165+
components: {
166+
schemas: {
167+
RefObject: {
168+
type: "object",
169+
properties: {
170+
foo: {
171+
type: "string",
172+
},
173+
bar: {
174+
type: "number",
175+
},
176+
},
177+
},
178+
},
179+
},
150180
});
151181

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

258+
const refParamSchema = convertOpenAPISchemaToJSONSchema(
259+
getParamSchema(createWidget, "refParam"),
260+
spec
261+
);
262+
const typedRefParamSchema = expectType("object", refParamSchema);
263+
expectType("string", typedRefParamSchema.properties.foo);
264+
expectType("number", typedRefParamSchema.properties.bar);
265+
266+
const refArrayParamSchema = convertOpenAPISchemaToJSONSchema(
267+
getParamSchema(createWidget, "refArrayParam"),
268+
spec
269+
);
270+
const typedRefArrayParamSchema = expectType("array", refArrayParamSchema);
271+
const typedRefArrayParamSchemaItems = expectType(
272+
"object",
273+
typedRefArrayParamSchema.items
274+
);
275+
expectType("string", typedRefArrayParamSchemaItems.properties.foo);
276+
expectType("number", typedRefArrayParamSchemaItems.properties.bar);
277+
228278
const nestedObjectInArrayParamSchema = convertOpenAPISchemaToJSONSchema(
229279
getParamSchema(createWidget, "nestedObjectInArrayParam"),
230280
spec

libs/langchain-core/src/callbacks/manager.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1248,12 +1248,18 @@ export class CallbackManager
12481248
if (tracingV2Enabled) {
12491249
const tracerV2 = new LangChainTracer();
12501250
callbackManager.addHandler(tracerV2, true);
1251-
1252-
// handoff between langchain and langsmith/traceable
1253-
// override the parent run ID
1254-
callbackManager._parentRunId =
1255-
LangChainTracer.getTraceableRunTree()?.id ??
1256-
callbackManager._parentRunId;
1251+
}
1252+
}
1253+
if (tracingV2Enabled) {
1254+
// handoff between langchain and langsmith/traceable
1255+
// override the parent run ID
1256+
const implicitRunTree = LangChainTracer.getTraceableRunTree();
1257+
if (implicitRunTree && callbackManager._parentRunId === undefined) {
1258+
callbackManager._parentRunId = implicitRunTree.id;
1259+
const tracerV2 = callbackManager.handlers.find(
1260+
(handler) => handler.name === "langchain_tracer"
1261+
) as LangChainTracer | undefined;
1262+
tracerV2?.updateFromRunTree(implicitRunTree);
12571263
}
12581264
}
12591265
}

0 commit comments

Comments
 (0)