İstem şablonları

LangChain ile LLM Uygulamaları Geliştirme

Jonathan Bennion

AI Engineer & LangChain Contributor

İstem şablonları

  • LLM istemlerini tanımlamak için tarifler
  • İçerebilir: yönergeler, örnekler ve ek bağlam

Girdi değişkenleri için yer tutucuları olan bir istem şablonu.

LangChain ile LLM Uygulamaları Geliştirme

İstem şablonları

from langchain_core.prompts import PromptTemplate


template = "Expain this concept simply and concisely: {concept}"
prompt_template = PromptTemplate.from_template( template=template )
prompt = prompt_template.invoke({"concept": "Prompting LLMs"}) print(prompt)
text='Expain this concept simply and concisely: Prompting LLMs'
LangChain ile LLM Uygulamaları Geliştirme
llm = HuggingFacePipeline.from_model_id(
    model_id="meta-llama/Llama-3.3-70B-Instruct",
    task="text-generation"
)

llm_chain = prompt_template | llm
concept = "Prompting LLMs" print(llm_chain.invoke({"concept": concept}))
LLM'lere (Büyük Dil Modelleri) istem vermek, bir modele yanıt üretmesi için
belirli bir girdi veya soru sağlamaktır.
  • LangChain Expression Language (LCEL): | (pipe) işleci
  • Zincir: farklı bileşen çağrılarını bağlar
LangChain ile LLM Uygulamaları Geliştirme

Sohbet modelleri

  • Sohbet rolleri: system, human, ai
from langchain_core.prompts import ChatPromptTemplate


template = ChatPromptTemplate.from_messages( [ ("system", "You are a calculator that responds with math."), ("human", "Answer this math question: What is two plus two?"), ("ai", "2+2=4"), ("human", "Answer this math question: {math}") ] )
LangChain ile LLM Uygulamaları Geliştirme

ChatPromptTemplate'i entegre etme

llm = ChatOpenAI(model="gpt-4o-mini", api_key='<OPENAI_API_TOKEN>')


llm_chain = template | llm
math='What is five times five?'
response = llm_chain.invoke({"math": math}) print(response.content)
5x5=25
LangChain ile LLM Uygulamaları Geliştirme

Hadi pratik yapalım!

LangChain ile LLM Uygulamaları Geliştirme

Preparing Video For Download...