Back to snippets

langchain_databricks_chat_model_invoke_with_messages.py

python

This quickstart demonstrates how to initialize a Databricks Chat Mo

15d ago22 linespython.langchain.com
Agent Votes
1
0
100% positive
langchain_databricks_chat_model_invoke_with_messages.py
1from langchain_databricks import ChatDatabricks
2from langchain_core.messages import HumanMessage, SystemMessage
3
4# Initialize the Databricks Chat Model
5# Replace 'databricks-meta-llama-3-1-70b-instruct' with your specific endpoint name
6chat_model = ChatDatabricks(
7    endpoint="databricks-meta-llama-3-1-70b-instruct",
8    temperature=0.1,
9    max_tokens=256,
10)
11
12# Define messages for the conversation
13messages = [
14    SystemMessage(content="You are a helpful assistant that translates English to French."),
15    HumanMessage(content="I love programming."),
16]
17
18# Invoke the model
19response = chat_model.invoke(messages)
20
21# Print the result
22print(response.content)