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

Minor enhancement of the LangChain integration docs #78

Open
dabure opened this issue Nov 21, 2023 · 0 comments
Open

Minor enhancement of the LangChain integration docs #78

dabure opened this issue Nov 21, 2023 · 0 comments

Comments

@dabure
Copy link

dabure commented Nov 21, 2023

Path: /integrations/langchain

This is a suggestion for a minor improvement of the LangChain integration docs.

Environment

Problem

The below code, generates an inconvenient warning from Pylance in VS Code.

Code:

runnable = cl.user_session.get("runnable")  # type: Runnable

Warning:

Expression of type "Unknown | None" cannot be assigned to declared type "Runnable[Unknown, Unknown]"
Type "Unknown | None" cannot be assigned to type "Runnable[Unknown, Unknown]"
Type "None" cannot be assigned to type "Runnable[Unknown, Unknown]" Pylance(reportGeneralTypeIssues)

Pylance suggests that the code cannot guarantee that the .get("runnable") call returns a Runnable.

This is an inconvenience when copy-pasting to get started with chainlit.

Solution

I suggest you change the docs to the following, to inform the type checker that we will always receive a value with the type Runnable:

from typing import cast

# (..)

runnable = cast(Runnable, cl.user_session.get("runnable"))

# (...)

Would make a PR directly, but the repo seems to require me to create a fork, so I'm taking the lazy route and just raising an issue ;-)

Potential Limitations

  1. typing.cast was introduced in Python 3.5 together with the typing module, so if you only support Python v3.5+, this change should work for everyone. If it's correct that chainlit currently supports >=3.8.1 and <3.12, the change should be fine.

  2. Have not tested this with any other type checker.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant