Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 12 additions & 25 deletions src/langchain_test.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,17 @@
from langchain.chat_models import ChatOpenAI
from langchain.prompts import PromptTemplate
from langchain.chains import LLMChain
from os import getenv
from dotenv import load_dotenv

load_dotenv()

template = """Question: {question}

Answer: Let's think step by step."""

prompt = PromptTemplate(template=template, input_variables=["question"])

llm = ChatOpenAI(
openai_api_key=getenv("OPENROUTER_API_KEY"),
openai_api_base=getenv("OPENROUTER_BASE_URL"),
model_kwargs={
"headers": {
"HTTP-Referer": getenv("APP_URL"),
"X-Title": getenv("APP_TITLE"),
}
},
from langchain_openai import ChatOpenAI
from langchain_core.prompts import ChatPromptTemplate

template = ChatPromptTemplate.from_messages(
[
("user", "{question}"),
("assistant", "Let's think step by step."),
]
)

llm_chain = LLMChain(prompt=prompt, llm=llm)
llm = ChatOpenAI(model="openai/gpt-4.1-mini")

llm_chain = template | llm

question = "What NFL team won the Super Bowl in the year Justin Beiber was born?"

print(llm_chain.run(question))
print(llm_chain.invoke({"question": question}))