Documentation Index
Fetch the complete documentation index at: https://sambanova-systems.mintlify.dev/docs/llms.txt
Use this file to discover all available pages before exploring further.
LangChain is a software framework for developing applications powered by (large language models) LLMs. This guide walks you through using LangChain to interact with SambaNova models.
View the following resources for more information:
Follow the example below to see how you can directly instantiate a ChatSambaNova model from LangChain and prompt it.
Setup
Do the following to access ChatSambaNova models:
- Create a SambaCloud account and get an API key.
- 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 as an environment variable.
import os
sambanova_api_key = "your-sambanova-api-key"
os.environ["SAMBANOVA_API_KEY"] = sambanova_api_key
Instantiation
Now you can instantiate a ChatSambaNova 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 ChatSambaNova
llm = ChatSambaNova(
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 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.