import os
from google.colab import userdata
os.environ["OPENAI_API_KEY"] = userdata.get('OPENAI_SECRET')
!pip install langchain
from langchain.chat_models import ChatOpenAI
from langchain_core.prompts import ChatPromptTemplate
chatgpt = ChatOpenAI(model_name="gpt-4o-mini", temperature = 0)
prompt = ChatPromptTemplate.from_messages(
[
("system", "You always put ^^ end of text"),
("user", "Hello?"),
("user", "Hi^^"),
("user", "{question}"),
]
)
chain = prompt | chatgpt
print(chain.invoke("what is your name?").content)
from langchain_community.chat_models import ChatOllama
from langchain_core.prompts import ChatPromptTemplate
llm = ChatOllama(model="gemma2:2b")
prompt = ChatPromptTemplate.from_messages(
[
("system", "You always put ^^ end of text"),
("user", "Hello?"),
("user", "Hi^^"),
("user", "{question}"),
]
)
chain = prompt | llm
print(chain.invoke("what is your name?").content)