Interview Bank
  • Interview Bank
  • Web
    • Persistent Connection and Non Persistent
    • CDN
    • Code Review
    • JWT
      • JWT vs Session Based Authentication
      • JWT Challenge
      • JWE
      • JWS
    • Content Security Policy (CSP)
    • Same-origin Policy (SOP)
    • Cross-Origin Resource Sharing (CORS)
      • Exploiting CORS
    • HTTP Strict Transport Security (HSTS)
    • SQL Injection (SQLi)
    • Password Encryption in Login APIs
    • API Security
      • API Principles
    • Simple bypass PHP
    • Server-side Template Injection (SSTI)
    • Javascript Object and Inheritance
    • HTTP/2
    • Cookie vs Local vs session Storage
    • XML External Entity (XXE)
    • What happened when enter domain name in browser
    • Prototype Pollution - Part 1
    • Prototype Pollution - Part 2
    • Nginx vs Apache
  • OT Security
    • Securing Operational Technology: Understanding OT Security
  • Quantum Computing
    • Quantum Computing: Unveiling the Cryptographic Paradigm Shift
    • Quantum Obfuscation: Shielding Code in the Quantum Era
  • DevSecOps
    • Continuous Integration/Continuous Deployment Pipeline Security
    • Chaos Engineering Overview
      • Security Chaos Engineering
    • Mysql VS redis
    • Kubernetes (k8s)
    • How MySQL executes query
    • REDIS
    • Difference between cache and buffer
  • Windows
    • Pentesting Active Directory - Active Directory 101
    • Pentesting Active Directory - Kerberos (Part 1)
    • Pentesting Active Directory - Kerberos (Part 2)
    • AD vs Kerberos vs LDAP
    • Active Directory Certificate Services Part 1
    • Unconstrained Delegation
    • AS-REP Roasting
    • NTLM Relay via SMB
    • LLMRN
    • Windows lateral movement
    • Constrained Delegation
    • Resource-Based Constrained Delegation
    • IFEO (lmage File Execution Options) Hijacking
  • UNIX
    • Setuid
  • Large Language Models (LLMs)
    • Tokens
    • LangChain
    • Integration and Security
  • Android
    • Keystore
  • Red team development
    • Secure C2 Infrastructure
    • P Invoke in c#
    • D Invoke
    • ExitProcess vs ExitThread
  • Blue Team
    • Indicators of Compromise
    • Methods to prevent Email domain spoofing
    • Windows Prefetching
  • CVE
    • XZ Outbreak CVE-2024-3094
    • Log4J Vulnerability (CVE-2021-44228)
    • SolarWinds Hack (CVE-2020-10148)
    • PHP CGI RCE (CVE-2024-4577)
    • Windows Recall
  • Software Architecture
    • Microservices
    • KVM
  • Docker
    • Overview
    • Daemon Socket
    • Tips to reduce docker size
  • Blockchain
    • Overview
    • Smart Contract
  • Business Acumen
    • Market Research Reports and Perception
    • Understanding Acquisitions
    • Cybersecurity as a Business Strategy
  • Cyber Teams
    • Introduction to Purple Teaming
  • Malware
    • Dynamic Sandbox Limitations
Powered by GitBook
On this page
  • Introduction
  • Communication with LLMs
  • Importance of LangChain
  • Agents in LangChain
  • Memory in LLM
  • Interview Questions
  • Author
  • References
  • Future Todos
  1. Large Language Models (LLMs)

LangChain

PreviousTokensNextIntegration and Security

Last updated 1 year ago

Introduction

Large Language Models (LLMs) are on the rise today due to how accurate and precise they can generate and output based on user's input. Furthermore, it could help with auto completion of words or assistance in coding and many more capabilities. Security now becomes a concern due to exposure of new attack vectors and exploits within the LLM model system.

Communication with LLMs

The most common way to interact with the model is to use the web interface of LLM (e.g. ChatGPT), followed by using the API endpoints of the models and lastly, using library to combine with the API to have more control with query and response.

# By Avikumar in The Modern Scientist
# insert an openai key below parameter
import os
from langchain.chat_models import ChatOpenAI
from langchain.chains.question_answering import load_qa_chain
os.environ["OPENAI_API_KEY"] = "YOUR-OPENAI-KEY"

# load the LLM model
model_name = "gpt-3.5-turbo"
llm = ChatOpenAI(model_name=model_name)


# Using q&a chain to get the answer for our query
chain = load_qa_chain(llm, chain_type="stuff",verbose=True)

# write your query and perform similarity search to generate an answer
query = "What are the emotional benefits of owning a pet?"
matching_docs = db.similarity_search(query)
answer =  chain.run(input_documents=matching_docs, question=query)
print(answer)

-----------------------------------[Results]---------------------------------
'Owning a pet can provide numerous emotional benefits. Pets offer
 companionship and can help reduce feelings of loneliness and isolation. 
They provide unconditional love and support, which can boost mood and overall
 well-being. Interacting with pets, such as petting or playing with them, 
has been shown to decrease levels of stress hormones and increase the
 release of oxytocin, a hormone associated with bonding and relaxation. 
Pets also offer a sense of purpose and responsibility, as taking care of 
them can give a sense of fulfillment and provide a distraction from daily 
stressors. Additionally, the bond between pets and their owners can provide
 a sense of stability and consistency during times of personal or societal 
stress.'

Importance of LangChain

LLM is a new ecosystem just like the rapid rise of blockchains and smart contracts for ethereum (and based networks) have developed. LangChain has became a popular tooling for developer to test prompt chaining, logging, callbacks and memory connections to different data sources. One of the most important feature is the ability to integrate with different LLM providers.

Agents in LangChain

Used by LLMs to recreate programming entity to execute given tasks which may be a specified sequence of actions to take. Especially useful to allow more development options and creativeness dependent on the support the LLM provider offers. They are used as reasoning engine to aid in automation of question answering, querying tabular data, summarization and evaluation.

Agents can also be further enhanced and integrated with additional tools to perform web scraping, retrieval of information, data processing, applying additional machine learning algorithms, integration and customization of proprietary systems.

Memory in LLM

Ways to retain context for further query prompts by the user is to pass previous context messages or use vector database (embed text to numerical values). LangChain offers memory module to ease context passing during development and supports different LLMs to ease chat history management.

Interview Questions

  • What are the various methods to communicate with LLMs?

  • What are the benefits of using LangChain over LLM provider APIs?

  • Explain how to manage context passing when querying to LLMs?

Author

References

Future Todos

ChatGPT rolled out memory on 13 Feb 2024, which helps in managing context passing of chats or specific prompts to combine as context for the users' next few queries. Benefit of using memory is removing the need to pass full chat history as context, but rather specific chat messages to retain enough context and ultimately, reduce usage.

🍞

LangChain
token
Zheng Jie
Logankil - LangChain for development
OpenAI - Memory in ChatGPT
LangChain - API docs
Comet - Implementing LangChain Agents
LangChain Plugins