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

docs[patch]: Fix Code in Managing Conversation History #6252

Merged
merged 5 commits into from
Jul 29, 2024

Conversation

sarangan12
Copy link
Contributor

Please refer #6246 for the details. The code mentioned in the site gives build error. The code change in this PR fixes the issue.

@dosubot dosubot bot added the size:XS This PR changes 0-9 lines, ignoring generated files. label Jul 29, 2024
Copy link

vercel bot commented Jul 29, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
langchainjs-api-refs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 29, 2024 10:28pm
langchainjs-docs ✅ Ready (Inspect) Visit Preview Jul 29, 2024 10:28pm

@dosubot dosubot bot added the auto:documentation Changes to documentation and examples, like .md, .rst, .ipynb files. Changes to the docs/ folder label Jul 29, 2024
Copy link
Member

@bracesproul bracesproul left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

docs/core_docs/docs/tutorials/chatbot.ipynb Outdated Show resolved Hide resolved
@@ -526,7 +526,8 @@
"import type { BaseMessage } from \"@langchain/core/messages\";\n",
"import { RunnablePassthrough, RunnableSequence } from \"@langchain/core/runnables\";\n",
"\n",
"const filterMessages = ({ chat_history }: { chat_history: BaseMessage[]; }) => {\n",
"const filterMessages = (input: Record<string, unknown>) => {\n",
" const { chat_history } = input as { chat_history: BaseMessage[] };\n",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
" const { chat_history } = input as { chat_history: BaseMessage[] };\n",
" const { chat_history }: { chat_history: BaseMessage[] } = input;\n",

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bracesproul The previous suggestion (from unknown to any) will work fine. But, this line will cause the same issue.

Property 'chat_history' is missing in type 'Record<string, any>' but required in type '{ chat_history: BaseMessage[]; }'.ts(2741)
tutorial2_updated.ts(31, 31): 'chat_history' is declared here.

So, I believe we should have it as:

const { chat_history } = input as { chat_history: BaseMessage[] };

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Jeez you're right, that's annoying. I pushed a commit doing this, which is a little more concise and does not throw any type errors const filterMessages = (input: { chat_history: BaseMessage[] }) => input.chat_history.slice(-10);

Copy link
Contributor Author

@sarangan12 sarangan12 Jul 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bracesproul Actually, even with the new line, the code will still cause build error. But, in a different place. If you add the new line, it will error out in the following lines:

const filterMessages = (input: { chat_history: BaseMessage[] }) => input.chat_history.slice(-10);

  const chain = RunnableSequence.from([
    RunnablePassthrough.assign({
      chat_history: filterMessages,
    }),
    prompt,
    model,
]).pipe(parser);

The following error will be reported:

Type '(input: { chat_history: BaseMessage[]; }) => BaseMessage[]' is not assignable to type 'RunnableLike<Record<string, unknown>, BaseMessage[]>'.
  Type '(input: { chat_history: BaseMessage[]; }) => BaseMessage[]' is not assignable to type 'RunnableFunc<Record<string, unknown>, BaseMessage[]>'.
    Types of parameters 'input' and 'input' are incompatible.
      Property 'chat_history' is missing in type 'Record<string, unknown>' but required in type '{ chat_history: BaseMessage[]; }'.ts(2322)
tutorial2_updated.ts(30, 36): 'chat_history' is declared here.
tutorial2_updated.ts(34, 7): The expected type comes from property 'chat_history' which is declared here on type 'RunnableMapLike<Record<string, unknown>, { chat_history: BaseMessage[]; }>'

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for notifying me of this. I'll just push a larger commit adding proper types throughout this entire doc. Give me a few min to do so.

@dosubot dosubot bot added the lgtm PRs that are ready to be merged as-is label Jul 29, 2024
@bracesproul bracesproul changed the title [Docs] Fix Code in Managing Conversation History docs[patch]: Fix Code in Managing Conversation History Jul 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto:documentation Changes to documentation and examples, like .md, .rst, .ipynb files. Changes to the docs/ folder lgtm PRs that are ready to be merged as-is size:M This PR changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants