Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: langchain-ai/langchainjs
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 765b057113fc3ebf897c3ec9ab2823250a7f7bd4
Choose a base ref
...
head repository: langchain-ai/langchainjs
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: e325f4c039c4fe0205fdfaffd47978bcd85c5bad
Choose a head ref
  • 12 commits
  • 70 files changed
  • 7 contributors

Commits on Jan 24, 2025

  1. release(core): 0.3.34 (#7584)

    bracesproul authored Jan 24, 2025

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    3671e26 View commit details

Commits on Jan 25, 2025

  1. feat(langchain): Add hub entrypoint with automatic dynamic entrypoint…

    … of models (#7583)
    jacoblee93 authored Jan 25, 2025

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    88c75e9 View commit details
  2. chore(ollama): Export OllamaEmbeddingsParams interface (#7574)

    gurisko authored Jan 25, 2025

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    86fa0d5 View commit details
  3. docs: Clarify tool creation process in structured outputs documentati…

    …on (#7578)
    
    Co-authored-by: Sahar Shemesh <sahar.shemesh@zoominfo.com>
    Co-authored-by: jacoblee93 <jacoblee93@gmail.com>
    3 people authored Jan 25, 2025
    Copy the full SHA
    7326a63 View commit details
  4. fix(community): Set awaitHandlers to true in upstash ratelimit (#7571)

    Co-authored-by: Jacob Lee <jacoblee93@gmail.com>
    CahidArda and jacoblee93 authored Jan 25, 2025
    Copy the full SHA
    a71067d View commit details
  5. fix(core): Fix trim messages mutation (#7585)

    jacoblee93 authored Jan 25, 2025
    Copy the full SHA
    93862f4 View commit details
  6. feat(openai): Make only AzureOpenAI respect Azure env vars, remove cl…

    …ass defaults, update withStructuredOutput defaults (#7535)
    jacoblee93 authored Jan 25, 2025
    Copy the full SHA
    90b06fa View commit details
  7. fix(community): Make postgresConnectionOptions optional in PostgresRe…

    …cordManager (#7580)
    
    Co-authored-by: jacoblee93 <jacoblee93@gmail.com>
    JonathanVelkeneers and jacoblee93 authored Jan 25, 2025
    Copy the full SHA
    4a44ca3 View commit details
  8. release(community): 0.3.27 (#7586)

    jacoblee93 authored Jan 25, 2025
    Copy the full SHA
    259bf7a View commit details
  9. release(ollama): 0.1.5 (#7587)

    jacoblee93 authored Jan 25, 2025
    Copy the full SHA
    5693683 View commit details
  10. Release 0.3.13 (#7588)

    jacoblee93 authored Jan 25, 2025
    Copy the full SHA
    264c300 View commit details
  11. release(openai): 0.4.0 (#7589)

    jacoblee93 authored Jan 25, 2025
    Copy the full SHA
    e325f4c View commit details
Showing with 937 additions and 1,730 deletions.
  1. +9 βˆ’3 docs/core_docs/docs/concepts/structured_outputs.mdx
  2. +1 βˆ’1 docs/core_docs/docs/how_to/graph_constructing.ipynb
  3. +2 βˆ’2 docs/core_docs/docs/how_to/query_high_cardinality.ipynb
  4. +99 βˆ’1 docs/core_docs/docs/integrations/chat/openai.ipynb
  5. +0 βˆ’49 examples/src/chains/multi_prompt.ts
  6. +0 βˆ’93 examples/src/chains/multi_retrieval_qa.ts
  7. +1 βˆ’1 examples/src/embeddings/cache_backed_in_memory.ts
  8. +1 βˆ’1 examples/src/embeddings/cache_backed_redis.ts
  9. +1 βˆ’1 examples/src/embeddings/convex/cache_backed_convex.ts
  10. +0 βˆ’99 examples/src/guides/evaluation/agent_trajectory/trajectory.ts
  11. +0 βˆ’17 examples/src/llms/openai-chat.ts
  12. +1 βˆ’1 examples/src/models/chat/integration_openai_wsa_json_schema.ts
  13. +1 βˆ’1 examples/src/models/chat/integration_openai_wsa_zod.ts
  14. +1 βˆ’1 examples/src/models/chat/token_usage_tracking.ts
  15. +1 βˆ’1 examples/src/models/chat/token_usage_tracking_callback.ts
  16. +0 βˆ’11 examples/src/models/llm/openai_basePath.ts
  17. +0 βˆ’40 examples/src/tools/duckduckgo_search_agent.ts
  18. +1 βˆ’15 examples/src/tools/webbrowser.ts
  19. +1 βˆ’1 langchain-core/package.json
  20. +35 βˆ’1 langchain-core/src/messages/tests/message_utils.test.ts
  21. +27 βˆ’10 langchain-core/src/messages/transformers.ts
  22. +4 βˆ’0 langchain/.gitignore
  23. +18 βˆ’1 langchain/langchain.config.js
  24. +15 βˆ’2 langchain/package.json
  25. +1 βˆ’1 langchain/src/agents/tests/create_openai_functions_agent.int.test.ts
  26. +1 βˆ’1 langchain/src/agents/tests/create_openai_tools_agent.int.test.ts
  27. +1 βˆ’1 langchain/src/agents/tests/create_react_agent.int.test.ts
  28. +1 βˆ’1 langchain/src/agents/tests/create_structured_chat_agent.int.test.ts
  29. +1 βˆ’1 langchain/src/agents/tests/create_tool_calling_agent.int.test.ts
  30. +2 βˆ’2 langchain/src/agents/tests/create_xml_agent.int.test.ts
  31. +0 βˆ’57 langchain/src/chains/router/tests/multi_prompt.int.test.ts
  32. +2 βˆ’2 langchain/src/chains/router/tests/multi_retrieval_qa.int.test.ts
  33. +4 βˆ’4 langchain/src/chains/sql_db/sql_db_chain.ts
  34. +2 βˆ’1 langchain/src/chat_models/tests/universal.int.test.ts
  35. +1 βˆ’0 langchain/src/chat_models/universal.ts
  36. +42 βˆ’76 langchain/src/{hub.ts β†’ hub/base.ts}
  37. +67 βˆ’0 langchain/src/hub/index.ts
  38. +62 βˆ’0 langchain/src/hub/node.ts
  39. +90 βˆ’0 langchain/src/hub/tests/hub.int.test.ts
  40. +1 βˆ’0 langchain/src/load/import_constants.ts
  41. +16 βˆ’1 langchain/src/load/import_map.ts
  42. +1 βˆ’0 langchain/src/load/index.ts
  43. +94 βˆ’8 langchain/src/load/tests/__snapshots__/load.test.ts.snap
  44. +27 βˆ’1 langchain/src/load/tests/load.test.ts
  45. +3 βˆ’3 langchain/src/memory/tests/summary.int.test.ts
  46. +0 βˆ’41 langchain/src/tests/hub.int.test.ts
  47. +2 βˆ’2 libs/langchain-community/package.json
  48. +2 βˆ’0 libs/langchain-community/src/callbacks/handlers/upstash_ratelimit.ts
  49. +7 βˆ’2 libs/langchain-community/src/indexes/postgres.ts
  50. +1 βˆ’1 libs/langchain-ollama/package.json
  51. +1 βˆ’1 libs/langchain-ollama/src/embeddings.ts
  52. +1 βˆ’1 libs/langchain-openai/package.json
  53. +60 βˆ’14 libs/langchain-openai/src/azure/chat_models.ts
  54. +41 βˆ’18 libs/langchain-openai/src/azure/embeddings.ts
  55. +64 βˆ’13 libs/langchain-openai/src/azure/llms.ts
  56. +29 βˆ’121 libs/langchain-openai/src/chat_models.ts
  57. +25 βˆ’107 libs/langchain-openai/src/embeddings.ts
  58. +0 βˆ’473 libs/langchain-openai/src/legacy.ts
  59. +33 βˆ’136 libs/langchain-openai/src/llms.ts
  60. +0 βˆ’18 libs/langchain-openai/src/tests/azure/chat_models.int.test.ts
  61. +1 βˆ’25 libs/langchain-openai/src/tests/azure/chat_models.standard.int.test.ts
  62. +14 βˆ’3 libs/langchain-openai/src/tests/azure/chat_models.test.ts
  63. +0 βˆ’18 libs/langchain-openai/src/tests/azure/embeddings.int.test.ts
  64. +1 βˆ’19 libs/langchain-openai/src/tests/azure/llms.int.test.ts
  65. +3 βˆ’1 libs/langchain-openai/src/tests/chat_models.test.ts
  66. +8 βˆ’8 libs/langchain-openai/src/tests/chat_models_structured_output.int.test.ts
  67. +0 βˆ’169 libs/langchain-openai/src/tests/legacy.int.test.ts
  68. +1 βˆ’10 libs/langchain-openai/src/tests/llms.int.test.ts
  69. +2 βˆ’13 libs/langchain-openai/src/types.ts
  70. +3 βˆ’3 yarn.lock
12 changes: 9 additions & 3 deletions docs/core_docs/docs/concepts/structured_outputs.mdx
Original file line number Diff line number Diff line change
@@ -79,7 +79,7 @@ Several more powerful methods that utilizes native features in the model provide

Many [model providers support](/docs/integrations/chat/) tool calling, a concept discussed in more detail in our [tool calling guide](/docs/concepts/tool_calling/).
In short, tool calling involves binding a tool to a model and, when appropriate, the model can _decide_ to call this tool and ensure its response conforms to the tool's schema.
With this in mind, the central concept is straightforward: _simply bind our schema to a model as a tool!_
With this in mind, the central concept is straightforward: _create a tool with our schema and bind it to the model!_
Here is an example using the `ResponseFormatter` schema defined above:

```typescript
@@ -90,8 +90,14 @@ const model = new ChatOpenAI({
temperature: 0,
});

// Bind ResponseFormatter schema as a tool to the model
const modelWithTools = model.bindTools([ResponseFormatter]);
// Create a tool with ResponseFormatter as its schema.
const responseFormatterTool = tool(async () => {}, {
name: "responseFormatter",
schema: ResponseFormatter,
});

// Bind the created tool to the model
const modelWithTools = model.bindTools([responseFormatterTool]);

// Invoke the model
const aiMsg = await modelWithTools.invoke(
2 changes: 1 addition & 1 deletion docs/core_docs/docs/how_to/graph_constructing.ipynb
Original file line number Diff line number Diff line change
@@ -102,7 +102,7 @@
"\n",
"const model = new ChatOpenAI({\n",
" temperature: 0,\n",
" model: \"gpt-4-turbo-preview\",\n",
" model: \"gpt-4o-mini\",\n",
"});\n",
"\n",
"const llmGraphTransformer = new LLMGraphTransformer({\n",
4 changes: 2 additions & 2 deletions docs/core_docs/docs/how_to/query_high_cardinality.ipynb
Original file line number Diff line number Diff line change
@@ -392,7 +392,7 @@
"metadata": {},
"source": [
"```{=mdx}\n",
"<ChatModelTabs customVarName=\"llmLong\" openaiParams={`{ model: \"gpt-4-turbo-preview\" }`} />\n",
"<ChatModelTabs customVarName=\"llmLong\" openaiParams={`{ model: \"gpt-4o-mini\" }`} />\n",
"```"
]
},
@@ -635,4 +635,4 @@
},
"nbformat": 4,
"nbformat_minor": 5
}
}
100 changes: 99 additions & 1 deletion docs/core_docs/docs/integrations/chat/openai.ipynb
Original file line number Diff line number Diff line change
@@ -625,7 +625,7 @@
"id": "045668fe",
"metadata": {},
"source": [
"### Structured output\n",
"## Structured output\n",
"\n",
"We can also pass `strict: true` to the [`.withStructuredOutput()`](https://js.langchain.com/docs/how_to/structured_output/#the-.withstructuredoutput-method). Here's an example:"
]
@@ -664,6 +664,104 @@
"}]);"
]
},
{
"cell_type": "markdown",
"id": "0194ec1f",
"metadata": {},
"source": [
"### Reasoning models\n",
"\n",
"```{=mdx}\n",
":::caution Compatibility\n",
"\n",
"The below points apply to `@langchain/openai>=0.4.0`. Please see here for a [guide on upgrading](/docs/how_to/installation/#installing-integration-packages).\n",
"\n",
":::\n",
"```\n",
"\n",
"When using reasoning models like `o1`, the default method for `withStructuredOutput` is OpenAI's built-in method for structured output (equivalent to passing `method: \"jsonSchema\"` as an option into `withStructuredOutput`). JSON schema mostly works the same as other models, but with one important caveat: when defining schema, `z.optional()` is not respected, and you should instead use `z.nullable()`.\n",
"\n",
"Here's an example:"
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "d2a04807",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{ color: 'No color mentioned' }\n"
]
}
],
"source": [
"import { z } from \"zod\";\n",
"import { ChatOpenAI } from \"@langchain/openai\";\n",
"\n",
"// Will not work\n",
"const reasoningModelSchemaOptional = z.object({\n",
" color: z.optional(z.string()).describe(\"A color mentioned in the input\"),\n",
"});\n",
"\n",
"const reasoningModelOptionalSchema = new ChatOpenAI({\n",
" model: \"o1\",\n",
"}).withStructuredOutput(reasoningModelSchemaOptional, {\n",
" name: \"extract_color\",\n",
"});\n",
"\n",
"await reasoningModelOptionalSchema.invoke([{\n",
" role: \"user\",\n",
" content: `I am 6'5\" tall and love fruit.`\n",
"}]);"
]
},
{
"cell_type": "markdown",
"id": "69854ed4",
"metadata": {},
"source": [
"And here's an example with `z.nullable()`:"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "5f4bb1bc",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{ color: null }\n"
]
}
],
"source": [
"import { z } from \"zod\";\n",
"import { ChatOpenAI } from \"@langchain/openai\";\n",
"\n",
"// Will not work\n",
"const reasoningModelSchemaNullable = z.object({\n",
" color: z.nullable(z.string()).describe(\"A color mentioned in the input\"),\n",
"});\n",
"\n",
"const reasoningModelNullableSchema = new ChatOpenAI({\n",
" model: \"o1\",\n",
"}).withStructuredOutput(reasoningModelSchemaNullable, {\n",
" name: \"extract_color\",\n",
"});\n",
"\n",
"await reasoningModelNullableSchema.invoke([{\n",
" role: \"user\",\n",
" content: `I am 6'5\" tall and love fruit.`\n",
"}]);"
]
},
{
"cell_type": "markdown",
"id": "af20e756",
49 changes: 0 additions & 49 deletions examples/src/chains/multi_prompt.ts

This file was deleted.

93 changes: 0 additions & 93 deletions examples/src/chains/multi_retrieval_qa.ts

This file was deleted.

2 changes: 1 addition & 1 deletion examples/src/embeddings/cache_backed_in_memory.ts
Original file line number Diff line number Diff line change
@@ -13,7 +13,7 @@ const cacheBackedEmbeddings = CacheBackedEmbeddings.fromBytesStore(
underlyingEmbeddings,
inMemoryStore,
{
namespace: underlyingEmbeddings.modelName,
namespace: underlyingEmbeddings.model,
}
);

2 changes: 1 addition & 1 deletion examples/src/embeddings/cache_backed_redis.ts
Original file line number Diff line number Diff line change
@@ -20,7 +20,7 @@ const cacheBackedEmbeddings = CacheBackedEmbeddings.fromBytesStore(
underlyingEmbeddings,
redisStore,
{
namespace: underlyingEmbeddings.modelName,
namespace: underlyingEmbeddings.model,
}
);

2 changes: 1 addition & 1 deletion examples/src/embeddings/convex/cache_backed_convex.ts
Original file line number Diff line number Diff line change
@@ -17,7 +17,7 @@ export const ask = action({
underlyingEmbeddings,
new ConvexKVStore({ ctx }),
{
namespace: underlyingEmbeddings.modelName,
namespace: underlyingEmbeddings.model,
}
);

Loading