## 🦜🔗 Develop AI Application through Langchain and LLM's
## About me - Prototyping, Researching - Mobile apps, cloud apps, real-time - Feel free to contact me; > https://github.com/dipeshdulal
## LLM, LangChain, GPT? - Heard of them? - Using it in any way?
## LLM, GPT - LLM, large language models - Trained on large corpus of text, able to generalize, and generate text. - GPT, generative, pre-trained, transformer - Generative, create it's own text - Pre-trained, trained on large corpus of text - Transformer, a type of neural network architecture
## What's langchain - Framework to develop applications using LLM's - Combine LLM with external sources of computation and data. - Allow agentic communication.
Frameworks in
## Some components | Component | Description | | --- | --- | | Schema | Basic data types of langchain, Text, ChatMessages, Examples, Document | | Models | LLM's, Chat Models, Text Embedding Models |
## Some components | Component | Description | | --- | --- | | Prompts | Way to program models, `PromptTemplate` responsible for construction of inputs | | Indexes | Way to structure documents, Document Loaders, Text Splitters, Vector Stores, Retrievers | - Other components; such as; Chains, Agents, Memory etc.
## Hello Langchain 🙋 ```python # choose a type of LLM llm = OpenAI(openai_api_key=...) # give it a prompt text = "What's NSOK?" # run prompt against llm print(llm.predict(text=text)) ```
## Combining them 🔗 ```python # system prompt template = """You are a helpful assistant.""" system_prompt = SystemMessagePromptTemplate .from_template(template) # human prompt human_prompt_template = """Give me 5 {things}?""" human_prompt = HumanMessagePromptTemplate .from_template(human_prompt_template) # make chat prompt chat_prompt = ChatPromptTemplate .from_messages([ template, human_prompt ]) # build a chain chain = LLMChain( llm=llm, prompt=chat_prompt, output_key="items" ) # run the chain print(chain.run("programming languages")) ```
## Combining chains
like previous example we can combine multiple chains
```python # ... final_prompt = PromptTemplate.from_template(""" Give me description of the items given. {items} """) chain_two = LLMChain(llm=llm, prompt=final_prompt) combined_chain = SequentialChain( chains=[chain, chain_two] ) combined_chain.run("programming languages") ```
## Combining chains
like previous example we can combine multiple chains
```python # ... final_prompt = PromptTemplate.from_template(""" Give me description of the items given. {items} """) chain_two = LLMChain(llm=llm, prompt=final_prompt) combined_chain = SequentialChain( chains=[chain, chain_two] ) combined_chain.run("programming languages") ```
## Agents - Choose a sequence of actions. - Chains, hardcode sequence of actions. - But in agents, - they choose the actions to take. - We provide tools.
## Agents Demo 🤖 let's write agent that writes code for us and performs some task.
## Any Questions