Files
langchain/libs/cli/langchain_cli/integration_template/docs/chat.ipynb
T
ccurme 1bf6576709 cli[patch]: fix anchor links in templates (#29178)
These are outdated and can break docs builds.
2025-01-13 18:28:18 +00:00

8.1 KiB

Cell:
[Cell type raw - unsupported, skipped]

Chat__ModuleName__

  • TODO: Make sure API reference link is correct.

This will help you getting started with ModuleName chat models. For detailed documentation of all Chat__ModuleName__ features and configurations head to the API reference.

Overview

Integration details

  • TODO: Fill in table features.
  • TODO: Remove JS support link if not relevant, otherwise ensure link is correct.
  • TODO: Make sure API reference links are correct.
Class Package Local Serializable JS support Package downloads Package latest
Chat__ModuleName__ package_name ✅/❌ beta/❌ ✅/❌ PyPI - Downloads PyPI - Version

Model features

Tool calling Structured output JSON mode Image input Audio input Video input Token-level streaming Native async Token usage Logprobs
✅/❌ ✅/❌ ✅/❌ ✅/❌ ✅/❌ ✅/❌ ✅/❌ ✅/❌ ✅/❌ ✅/❌

Setup

  • TODO: Update with relevant info.

To access ModuleName models you'll need to create a/an ModuleName account, get an API key, and install the __package_name__ integration package.

Credentials

  • TODO: Update with relevant info.

Head to (TODO: link) to sign up to ModuleName and generate an API key. Once you've done this set the __MODULE_NAME___API_KEY environment variable:

In [ ]:
import getpass
import os

if not os.getenv("__MODULE_NAME___API_KEY"):
    os.environ["__MODULE_NAME___API_KEY"] = getpass.getpass("Enter your __ModuleName__ API key: ")

If you want to get automated tracing of your model calls you can also set your LangSmith API key by uncommenting below:

In [ ]:
# os.environ["LANGSMITH_TRACING"] = "true"
# os.environ["LANGSMITH_API_KEY"] = getpass.getpass("Enter your LangSmith API key: ")

Installation

The LangChain ModuleName integration lives in the __package_name__ package:

In [ ]:
%pip install -qU __package_name__

Instantiation

Now we can instantiate our model object and generate chat completions:

  • TODO: Update model instantiation with relevant params.
In [ ]:
from __module_name__ import Chat__ModuleName__

llm = Chat__ModuleName__(
    model="model-name",
    temperature=0,
    max_tokens=None,
    timeout=None,
    max_retries=2,
    # other params...
)

Invocation

  • TODO: Run cells so output can be seen.
In [ ]:
messages = [
    (
        "system",
        "You are a helpful assistant that translates English to French. Translate the user sentence.",
    ),
    ("human", "I love programming."),
]
ai_msg = llm.invoke(messages)
ai_msg
In [ ]:
print(ai_msg.content)

Chaining

We can chain our model with a prompt template like so:

  • TODO: Run cells so output can be seen.
In [ ]:
from langchain_core.prompts import ChatPromptTemplate

prompt = ChatPromptTemplate(
    [
        (
            "system",
            "You are a helpful assistant that translates {input_language} to {output_language}.",
        ),
        ("human", "{input}"),
    ]
)

chain = prompt | llm
chain.invoke(
    {
        "input_language": "English",
        "output_language": "German",
        "input": "I love programming.",
    }
)

TODO: Any functionality specific to this model provider

E.g. creating/using finetuned models via this provider. Delete if not relevant.

API reference

For detailed documentation of all Chat__ModuleName__ features and configurations head to the API reference: https://api.python.langchain.com/en/latest/chat_models/module_name.chat_models.Chat__ModuleName__.html