langchain-ai / langchain

🦜🔗 Build context-aware reasoning applications
https://python.langchain.com
MIT License
89.28k stars 14.07k forks source link

Standardize ChatModel docstrings and integration docs #22296

Open baskaryan opened 1 month ago

baskaryan commented 1 month ago

Issue

To make our chat model integrations as easy to use as possible we need to make sure the docs for them are thorough and standardized. There are two parts to this: updating the chat model docstrings and updating the actual integration docs.

This needs to be done for each ChatModel integration, ideally with one PR per ChatModel.

Related to broader issues #21983 and #22005.

Docstrings

Each ChatModel class docstring should have the sections shown in the Appendix below. The sections should have input and output code blocks when relevant. See ChatOpenAI docstrings and corresponding API reference for an example.

To build a preview of the API docs for the package you're working on run (from root of repo):

make api_docs_clean; make api_docs_quick_preview API_PKG=openai

where API_PKG= should be the parent directory that houses the edited package (e.g. community, openai, anthropic, huggingface, together, mistralai, groq, fireworks, etc.). This should be quite fast for all the partner packages.

Doc pages

Each ChatModel docs page should follow this template. See ChatOpenAI for an example.

You can use the langchain-cli to quickly get started with a new chat model integration docs page (run from root of repo):

poetry run pip install -e libs/cli
poetry run langchain-cli integration create-doc --name "foo-bar" --name-class FooBar --destination-dir ./docs/docs/integrations/chat/

where --name is the integration package name without the "langchain-" prefix and --name-class is the class name without the "Chat" prefix. This will create a template doc with some autopopulated fields at docs/docs/integrations/chat/foo_bar.ipynb.

To build a preview of the docs you can run (from root):

make docs_clean
make docs_build
cd docs/build/output-new
yarn
yarn start

Appendix

Expected sections for the ChatModel class docstring.

    """__ModuleName__ chat model integration.

    Setup:
      ...

    Key init args — completion params:
      ...

    Key init args — client params:
      ...

    See full list of supported init args and their descriptions in the params section.

    Instantiate:
      ...

    Invoke:
      ...

    # Delete if token-level streaming not supported.
    Stream:
      ...

    # TODO: Delete if native async isn't supported.
    Async:
      ...

    # TODO: Delete if .bind_tools() isn't supported.
    Tool calling:
      ...

      See ``Chat__ModuleName__.bind_tools()`` method for more.

    # TODO: Delete if .with_structured_output() isn't supported.
    Structured output:
      ...

      See ``Chat__ModuleName__.with_structured_output()`` for more.

    # TODO: Delete if JSON mode response format isn't supported.
    JSON mode:
      ...

    # TODO: Delete if image inputs aren't supported.
    Image input:
      ...

    # TODO: Delete if audio inputs aren't supported.
    Audio input:
      ...

    # TODO: Delete if video inputs aren't supported.
    Video input:
      ...

    # TODO: Delete if token usage metadata isn't supported.
    Token usage:
      ...

    # TODO: Delete if logprobs aren't supported.
    Logprobs:
      ...

    Response metadata
      ...

    """  # noqa: E501
chaityacshah commented 1 month ago

hi @baskaryan, i'm interested in this. where would I find more info for the fields in Doc pages that aren't autopopulated?

anilkumarKanasani commented 1 month ago

Hi @chaityacshah, I am interested to contribute to this issue. I am doing open source contribution for the first time. Can we both together take up this task ?