https://python.langchain.com/api_reference/reference.html
Claude.ai
https://github.com/langchain-ai/langchain/tree/master/libs/partners/anthropic
# pip install -U langchain-anthropic
from langchain_anthropic import ChatAnthropic
from langchain_core.messages import AIMessage, HumanMessage
model = ChatAnthropic(model="claude-3-5-sonnet-latest", temperature=0, max_tokens=1024)
Ollama - llama3
https://github.com/langchain-ai/langchain/tree/master/libs/partners/ollama
# pip install -U langchain-ollama
____
from langchain_ollama import ChatOllama
llm = ChatOllama(model="llama3-groq-tool-use")
llm.invoke("Sing a ballad of LangChain.")
____
from langchain_ollama import OllamaEmbeddings
embeddings = OllamaEmbeddings(model="llama3")
embeddings.embed_query("What is the meaning of life?")
____
from langchain_ollama import OllamaLLM
llm = OllamaLLM(model="llama3")
llm.invoke("The meaning of life is")
OpenAI
https://github.com/langchain-ai/langchain/tree/master/libs/partners/openai
# pip install langchain-openai
from langchain_openai import OpenAI
#from langchain_openai import AzureOpenAI # for Azure
llm = OpenAI()
llm.invoke("Hello how are you?")
from langchain_core.prompts import PromptTemplate
prompt = PromptTemplate.from_template("How to say {input} in {output_language}:\n")
chain = prompt | llm
chain.invoke(
{
"output_language": "German",
"input": "I love programming.",
}
)
___
from langchain_openai import ChatOpenAI
#from langchain_openai import AzureChatOpenAI # for Azure
llm = ChatOpenAI(
model="gpt-4o",
temperature=0,
max_tokens=None,
timeout=None,
max_retries=2,
# api_key="...", # if you prefer to pass api key in directly instaed of using env vars
# base_url="...",
# organization="...",
# other params...
)
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
print(ai_msg.content)
___
from langchain_openai import OpenAIEmbeddings
#from langchain_openai import AzureOpenAIEmbeddings # for Azure
_
반응형