messages = [ ("system", "You are a helpful assistant with access to real-time web information."), ("human", "What are the latest developments in AI?"),]ai_msg = llm.invoke(messages)print(ai_msg.content)
from langchain_core.prompts import ChatPromptTemplateprompt = ChatPromptTemplate( [ ( "system", "You are a research assistant with access to real-time web information. " "Answer questions about {topic} using current sources.", ), ("human", "{question}"), ])chain = prompt | llmchain.invoke( { "topic": "artificial intelligence", "question": "What are the most significant AI breakthroughs in 2026?", })
from pydantic import BaseModel, Fieldclass Founder(BaseModel): name: str = Field(description="Full name of the founder") company: str = Field(description="Company they founded")structured = ChatParallel(model="lite").with_structured_output(Founder)parsed = structured.invoke([("human", "Who founded SpaceX?")])print(parsed)
structured = ChatParallel(model="lite").with_structured_output(Founder, include_raw=True)res = structured.invoke([("human", "Who founded SpaceX?")])res["parsed"] # Founder(...) or Noneres["parsing_error"] # Exception or Noneres["raw"] # original AIMessage
cited = ChatParallel(model="lite").invoke([ ("human", "Who is the current CEO of OpenAI? One sentence."),])print(cited.content)print("\nbasis:", cited.response_metadata.get("basis"))print("interaction_id:", cited.response_metadata.get("interaction_id"))
from langchain.messages import HumanMessage, SystemMessage# Consecutive system messages are automatically merged before the API call.messages = [ SystemMessage("You are a helpful assistant."), SystemMessage("Always be polite and concise."), HumanMessage("What is the weather like today?"),]response = llm.invoke(messages)