avatarLaxfed Paulacy

Free AI web copilot to create summaries, insights and extended knowledge, download it at here

2582

Abstract

pre><span class="hljs-comment"># Best-in-class debugging experience with LangSmith</span> <span class="hljs-keyword">from</span> langsmith import LangSmith

<span class="hljs-comment"># Create LangSmith instance</span> langsmith = LangSmith()

<span class="hljs-comment"># Log steps, inputs, outputs, and more</span> langsmith.<span class="hljs-built_in">debug</span>(<span class="hljs-string">'Step 1: Processing input data...'</span>) langsmith.<span class="hljs-built_in">debug</span>(<span class="hljs-string">'Step 2: Generating LLM response...'</span>) langsmith.<span class="hljs-built_in">debug</span>(<span class="hljs-string">'Step 3: Analyzing output data...'</span>)</pre></div><h2 id="15b9">Composability</h2><p id="9e70">LangChain Expression Language (LCEL) enables the composition of arbitrary sequences, offering benefits such as batching, parallelization, and fallbacks for LLM workloads.</p><div id="0122"><pre># <span class="hljs-keyword">Using</span> LangChain Expression <span class="hljs-keyword">Language</span> (LCEL) <span class="hljs-keyword">for</span> composition <span class="hljs-keyword">from</span> langchain.expression_language <span class="hljs-keyword">import</span> LCEL

<span class="hljs-keyword">Create</span> a compositional <span class="hljs-keyword">sequence</span>

<span class="hljs-keyword">sequence</span> = LCEL.<span class="hljs-keyword">sequence</span>([ LCEL.batch(process_data1), LCEL.parallelize(process_data2), LCEL.fallback(process_data3, fallback_data) ])</pre></div><h2 id="4907">Output Parsing</h2><p id="9e76">LangChain provides advanced functionality for output parsing, allowing structured format parsing, streaming of partial results, and support for various encoding methods.</p><div id="5b3a"><pre><span class="hljs-comment"># Advanced output parsing with LangChain</span> <span class="hljs-keyword">from</span> langchain.output_parsers <span class="hljs-keyword">import</span> OutputParser

<span class="hljs-comment"># Create an output parser for JSON format</span> json_parser = OutputParser.parse_json(data)

<span class="hljs-comment"># Stream partial results from structured formats</span> <span class="hljs-keyword">for</span> partial_result <span class="hljs-keyword">in</span> json_parser.stream_partial_results(): <span class="hljs-comment"># Process and display partial results</span> <span class="hljs-built_in">print</span>(partial_result)</pre></div><h2 id="0fbd">Retrieval</h2><p id="0757">LangChain offers advanced retrieval strategies, such as FLARE, Hyde, Parent Document, and Self

Options

-Query, for efficient data retrieval and ingestion.</p><div id="eec4"><pre><span class="hljs-comment"># Advanced retrieval with LangChain</span> <span class="hljs-keyword">from</span> langchain.retrieval import AdvancedRetrieval

<span class="hljs-comment"># Create an instance of Hyde retrieval strategy</span> hyde_retrieval = AdvancedRetrieval(<span class="hljs-attribute">strategy</span>=<span class="hljs-string">'hyde'</span>)

<span class="hljs-comment"># Retrieve data using the Hyde strategy</span> retrieved_data = hyde_retrieval.retrieve_data(query)</pre></div><h2 id="6005">Agents</h2><p id="817e">LangChain supports agentic workloads, allowing users to define custom cyclical behavior for LLMs using the newly released <code>langgraph</code> library.</p><div id="88ed"><pre># Creating <span class="hljs-keyword">language</span> agents <span class="hljs-keyword">as</span> graphs <span class="hljs-keyword">with</span> LangGraph <span class="hljs-keyword">from</span> langgraph.graph <span class="hljs-keyword">import</span> Graph, <span class="hljs-keyword">END</span>

Define a workflow <span class="hljs-keyword">for</span> <span class="hljs-keyword">language</span> agents

workflow = Graph() workflow.add_node("agent", agent) workflow.add_node("tools", execute_tools) workflow.set_entry_point("agent") workflow.add_conditional_edges( "agent", should_continue, {"continue": "tools", "exit": <span class="hljs-keyword">END</span>} ) workflow.add_edge(<span class="hljs-string">'tools'</span>, <span class="hljs-string">'agent'</span>) chain = workflow.compile()</pre></div><div id="b00d" class="link-block"> <a href="https://readmedium.com/langchain-pinecone-serverless-0b6f575e7042"> <div> <div> <h2>LANGCHAIN — Pinecone Serverless</h2> <div><h3>The Web does not just connect machines, it connects people. — Tim Berners-Lee</h3></div> <div><p>medium.com</p></div> </div> <div> <div style="background-image: url(https://miro.readmedium.com/v2/resize:fit:320/1*nu7ZXSdSXeo6aCLEJYoZpg.jpeg)"></div> </div> </div> </a> </div><p id="c879">LangChain v0.1.0 represents a major step towards stability, improved functionality, and clear versioning policies. With these changes, LangChain aims to address the needs of developers and the community, and the upcoming 0.2 release is anticipated to bring additional features, new chains, and enhanced production capabilities.</p></article></body>

LANGCHAIN — LangChain v0.1.0

First, solve the problem. Then, write the code. — John Johnson

LangChain version 0.1.0 (v0.1.0) is the first stable release of the LangChain framework, which is designed for building LLM (Language Model Microservice) applications. This version is fully backward-compatible and available in both Python and JavaScript, providing improved functionality and documentation. The release marks a significant milestone for LangChain, ensuring developer trust and systematic evolution of the library.

The major changes in this release include the separation of langchain-core, which comprises main abstractions, interfaces, and core functionality, and the segregation of partner packages into either langchain-community or standalone partner packages from langchain. This release introduces a new versioning standard, where any breaking changes to the public API will result in a minor version bump, and any bug fixes or new features will result in a patch version bump. This approach aims to provide clear communication on breaking changes, responsibly deal with integrations, and reduce bloat by deprecating and deleting old code.

To showcase the improvements and changes made, the following code snippets and examples from the release notes in multiple areas of LangChain are provided below:

Observability

LangSmith provides a best-in-class debugging experience for LLM applications. It offers a user-friendly way to log steps, inputs, outputs, and more, allowing developers to identify performance bottlenecks and debug unexpected LLM responses.

# Best-in-class debugging experience with LangSmith
from langsmith import LangSmith

# Create LangSmith instance
langsmith = LangSmith()

# Log steps, inputs, outputs, and more
langsmith.debug('Step 1: Processing input data...')
langsmith.debug('Step 2: Generating LLM response...')
langsmith.debug('Step 3: Analyzing output data...')

Composability

LangChain Expression Language (LCEL) enables the composition of arbitrary sequences, offering benefits such as batching, parallelization, and fallbacks for LLM workloads.

# Using LangChain Expression Language (LCEL) for composition
from langchain.expression_language import LCEL

# Create a compositional sequence
sequence = LCEL.sequence([
    LCEL.batch(process_data1),
    LCEL.parallelize(process_data2),
    LCEL.fallback(process_data3, fallback_data)
])

Output Parsing

LangChain provides advanced functionality for output parsing, allowing structured format parsing, streaming of partial results, and support for various encoding methods.

# Advanced output parsing with LangChain
from langchain.output_parsers import OutputParser

# Create an output parser for JSON format
json_parser = OutputParser.parse_json(data)

# Stream partial results from structured formats
for partial_result in json_parser.stream_partial_results():
    # Process and display partial results
    print(partial_result)

Retrieval

LangChain offers advanced retrieval strategies, such as FLARE, Hyde, Parent Document, and Self-Query, for efficient data retrieval and ingestion.

# Advanced retrieval with LangChain
from langchain.retrieval import AdvancedRetrieval

# Create an instance of Hyde retrieval strategy
hyde_retrieval = AdvancedRetrieval(strategy='hyde')

# Retrieve data using the Hyde strategy
retrieved_data = hyde_retrieval.retrieve_data(query)

Agents

LangChain supports agentic workloads, allowing users to define custom cyclical behavior for LLMs using the newly released langgraph library.

# Creating language agents as graphs with LangGraph
from langgraph.graph import Graph, END

# Define a workflow for language agents
workflow = Graph()
workflow.add_node("agent", agent)
workflow.add_node("tools", execute_tools)
workflow.set_entry_point("agent")
workflow.add_conditional_edges(
    "agent",
    should_continue,
    {"continue": "tools", "exit": END}
)
workflow.add_edge('tools', 'agent')
chain = workflow.compile()

LangChain v0.1.0 represents a major step towards stability, improved functionality, and clear versioning policies. With these changes, LangChain aims to address the needs of developers and the community, and the upcoming 0.2 release is anticipated to bring additional features, new chains, and enhanced production capabilities.

Langchain
1
ChatGPT
V0
Recommended from ReadMedium