mirror of
https://github.com/langchain-ai/langchain.git
synced 2026-10-05 17:35:28 +03:00
Big docs refactor! Motivation is to make it easier for people to find resources they are looking for. To accomplish this, there are now three main sections: - Getting Started: steps for getting started, walking through most core functionality - Modules: these are different modules of functionality that langchain provides. Each part here has a "getting started", "how to", "key concepts" and "reference" section (except in a few select cases where it didnt easily fit). - Use Cases: this is to separate use cases (like summarization, question answering, evaluation, etc) from the modules, and provide a different entry point to the code base. There is also a full reference section, as well as extra resources (glossary, gallery, etc) Co-authored-by: Shreya Rajpal <ShreyaR@users.noreply.github.com>
4.1 KiB
4.1 KiB
In [1]:
from langchain.chains.conversation.memory import ConversationBufferMemory
from langchain import OpenAI, LLMChain, PromptTemplateIn [2]:
template = """You are a chatbot having a conversation with a human.
{chat_history}
Human: {human_input}
Chatbot:"""
prompt = PromptTemplate(
input_variables=["chat_history", "human_input"],
template=template
)
memory = ConversationBufferMemory(memory_key="chat_history")In [3]:
llm_chain = LLMChain(
llm=OpenAI(),
prompt=prompt,
verbose=True,
memory=memory,
)In [4]:
llm_chain.predict(human_input="Hi there my friend")Out [4]:
[1m> Entering new LLMChain chain...[0m Prompt after formatting: [32;1m[1;3mYou are a chatbot having a conversation with a human. Human: Hi there my friend Chatbot:[0m [1m> Finished LLMChain chain.[0m
' Hi there, how are you doing today?'
In [5]:
llm_chain.predict(human_input="Not to bad - how are you?")Out [5]:
[1m> Entering new LLMChain chain...[0m Prompt after formatting: [32;1m[1;3mYou are a chatbot having a conversation with a human. Human: Hi there my friend AI: Hi there, how are you doing today? Human: Not to bad - how are you? Chatbot:[0m [1m> Finished LLMChain chain.[0m
" I'm doing great, thank you for asking!"
In [ ]: