Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

api_refs[minor]: Hide all properties and non whitelisted methods of chat models #6456

Closed
wants to merge 2 commits into from
Closed
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
103 changes: 103 additions & 0 deletions docs/api_refs/typedoc_plugins/hide_underscore_lc.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,28 @@ const {
const fs = require("fs");
const path = require("path");

const WHITELISTED_CHAT_MODEL_INHERITED_METHODS = [
"invoke",
"stream",
"batch",
"streamLog",
"streamEvents",
"bind",
"bindTools",
"asTool",
"pipe",
"withConfig",
"withRetry",
"assign",
"getNumTokens",
"getGraph",
"pick",
"withFallbacks",
"withStructuredOutput",
"withListeners",
"transform",
];

const PATH_TO_LANGCHAIN_PKG_JSON = "../../langchain/package.json";
const BASE_OUTPUT_DIR = "./public";
const SCRIPT_HTML = `<script>
Expand All @@ -27,6 +49,82 @@ const VERSION_DROPDOWN_HTML = `<div class="version-select">
</select>
</div>`;

/**
* Checks if the reflection is a property of a chat model class,
* and returns true (to hide the reflection) if it is.
*
* @param {DeclarationReflection} reflection
* @returns {boolean} Whether or not to hide the reflection
*/
function hideChatModelProperties(reflection) {
if (
reflection.kind === ReflectionKind.Property &&
reflection?.parent &&
reflection.parent.kind === ReflectionKind.Class &&
reflection.parent.name.includes("Chat")
) {
return true;
}
return false;
}

/**
* Checks if the reflection is a method on a chat model class,
* and returns true (to hide the reflection) if it is.
*
* @param {DeclarationReflection} reflection
* @returns {boolean} Whether or not to hide the reflection
*/
function hideChatModelMethods(reflection) {
if (
reflection.kind === ReflectionKind.Method &&
reflection?.parent &&
reflection.parent.kind === ReflectionKind.Class &&
reflection.parent.name.includes("Chat")
) {
if (
!WHITELISTED_CHAT_MODEL_INHERITED_METHODS.find(
(n) => n === reflection.name
)
) {
return true;
}
}
return false;
}

/**
* Checks if the reflection is an accessor and is named `callKeys`,
* and returns true (to hide the reflection) if it is.
*
* @param {DeclarationReflection} reflection
* @returns {boolean} Whether or not to hide the reflection
*/
function hideChatModelAccessors(reflection) {
if (
reflection.kind === ReflectionKind.Accessor &&
reflection.name === "callKeys"
) {
return true;
}
return false;
}

/**
* Check if the reflection should be hidden. If it should, it
* returns true.
*
* @param {DeclarationReflection} reflection
* @returns {boolean} Whether or not to hide the reflection
*/
function hideChatModelReflection(reflection) {
return (
hideChatModelProperties(reflection) ||
hideChatModelMethods(reflection) ||
hideChatModelAccessors(reflection)
);
}

/**
* @param {string | undefined} deprecationText
* @returns {string}
Expand Down Expand Up @@ -113,6 +211,11 @@ function load(application) {
*/
function resolveReflection(_context, reflection) {
const reflectionKind = reflection.kind;

if (hideChatModelReflection(reflection)) {
reflectionsToHide.push(reflection);
}

if (reflectionKindsToHide.includes(reflectionKind)) {
if (
reflection.name.startsWith("_") ||
Expand Down
Loading