> ## Documentation Index
> Fetch the complete documentation index at: https://docs-preprod.sambanova.ai/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# LangChain

LangChain is a software framework for developing applications powered by (large language models) LLMs. This document describes how to use LangChain to interact with SambaNova models.

<Note>
  View the following resources for more information:

  * [ChatSambaNovaCloud document](https://python.langchain.com/docs/integrations/chat/sambanova/)
  * [SambaNova-LangChain document](https://python.langchain.com/docs/integrations/providers/sambanova/)
  * [LangChain official document](https://python.langchain.com/docs/introduction/)
  * [End-to-end code examples using LangChain and SambaNova](https://github.com/sambanova/ai-starter-kit)
  * [SambaNovaCloudEmbeddings document](https://python.langchain.com/docs/integrations/text_embedding/sambanova/)
</Note>

Follow the example below to see how you can directly instantiate a ChatSambaNovaCloud model from LangChain and prompt it.

## Setup

Do the following to access ChatSambaNovaCloud models:

1. Create a [SambaNovaCloud](https://cloud.sambanova.ai/) account and get an API key.
2. Run the command below to install the `langchain-sambanova` integration package.

```
pip install langchain-sambanova
```

## Credentials

Run the commands below to register the API key you received from [cloud.sambanova.ai](https://cloud.sambanova.ai/apis) as an environment variable.

```
import os

sambanova_api_key = "<your-api-key>"
os.environ["SAMBANOVA_API_KEY"] = sambanova_api_key
```

## Instantiation

Now you can instantiate a ChatSambaNovaCloud model object and generate chat completions, as shown in the example below. The example below uses Meta’s Llama 3.3 70B.

```
from langchain_sambanova import ChatSambaNovaCloud

llm = ChatSambaNovaCloud(
    model="Meta-Llama-3.3-70B-Instruct",
    max_tokens=1024,
    temperature=0.7,
    top_p=0.01,
)
```

## Invocation

You can invoke the model using the command below.

```
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)
print(ai_msg.content)
```

You should see an output similar to the one below.

```
J'adore la programmation.
```

## Chaining

You can [chain](https://python.langchain.com/docs/how_to/sequence/) the model with a prompt template, as shown in the example below.

```
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
response = chain.invoke(
    {
        "input_language": "English",
        "output_language": "German",
        "input": "I love programming.",
    }
)
print(response.content)
```

You should see an output similar to the one below.

```
Ich liebe das Programmieren.
```
