avatarLaxfed Paulacy

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

1818

Abstract

06f">LangChain introduces abstractions for different types of chat messages, including <code>HumanMessage</code>, <code>AIMessage</code>, <code>SystemMessage</code>, and <code>ChatMessage</code>. These abstractions allow for explicit representation of message types, enabling model API agnosticism.</p><h2 id="3d2d">Chat Models</h2><p id="e4b3">Abstractions for chat models have been added, aligning with the underlying ChatGPT API. The interface for these models expects a list of chat messages as input and returns a chat message.</p><h2 id="b84f">Chat Message Templates</h2><p id="3437">LangChain introduces corresponding chat message prompt templates, such as <code>HumanMessagePromptTemplate</code>, <code>AIMessagePromptTemplate</code>, <code>SystemMessagePromptTemplate</code>, and <code>ChatMessagePromptTemplate</code>, to facilitate the generation of chat messages from user input.</p><h2 id="178a">Prompt Values</h2><p id="a5f3">To ensure interoperability between “normal” LLM APIs and chat-based APIs, LangChain introduces the concept of <code>PromptValue</code>. This class provides methods for converting prompt values into strings for "normal" LLM APIs and into a list of messages for chat-based APIs.</p><h2 id="3264">How do these align with our objectives?</h2><p id="7bbd">The new abstractions align with the following objectives:</p><p id="5a36"><b>Allow users to fully take advantage of the new chat model interface</b>: The abstractions cover all functionality in the ChatGPT interface, enabling users to leverage the new chat model interface effectively.</p><p id="4e68"><b>Allow for interoperability of prompts between “normal” LLM APIs and chat-based APIs</b>: The <code>PromptValue</code> abstraction facilitates seamless conversion of prompts between different model types.</p><p id="d5e1"><b

Options

Make the abstractions generic beyond just OpenAI</b>: The explicit concepts of Human/AI/System messages, rather than relying on specific naming conventions, ensure that the abstractions are model API agnostic.</p><p id="500c">These new abstractions in LangChain provide a foundation for supporting chat-based models, enabling users to take full advantage of the capabilities offered by the new ChatGPT API and future chat-style models. As LangChain continues to evolve, further functionality around chat models, such as improved message-to-string support and chat memory support, will be added.</p><div id="4e9a" class="link-block"> <a href="https://readmedium.com/langchain-what-is-retrieval-031f8a76e222"> <div> <div> <h2>LANGCHAIN — What Is Retrieval?</h2> <div><h3>Social media is not about the exploitation of technology but service to community. — Simon Mainwaring</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="ae66">For more information, refer to the <a href="https://python.langchain.com/docs/modules/model_io/models/chat/">LangChain Python Documentation</a> and <a href="https://hwchase17.github.io/langchainjs/docs/modules/chat_models/overview">JS/TS Documentation</a>.</p><p id="9b90">We hope this tutorial has provided a clear understanding of the new abstractions introduced in LangChain for chat models. Your feedback and suggestions on these abstractions are highly appreciated as we continue to enhance the support for chat-based models in LangChain.</p></article></body>

LANGCHAIN — Chat Models

The great myth of our times is that technology is communication. — Libby Larsen

When OpenAI released the ChatGPT endpoint, it introduced a new API schema for chat-based models, which significantly differs from the existing GPT-3 endpoint. This change required the adaptation of LangChain to accommodate not only ChatGPT but also future chat-based models. In this tutorial, we will explore the new abstractions introduced in LangChain to support chat models.

Why new abstractions?

The new ChatGPT API has a different interface, accepting a list of chat messages as input and returning a chat message as output, unlike the traditional GPT-3 endpoint which takes and returns text. This shift in the interface led to the need for new abstractions to handle the input/output transformation for chat-based models.

Chat Messages

LangChain introduces abstractions for different types of chat messages, including HumanMessage, AIMessage, SystemMessage, and ChatMessage. These abstractions allow for explicit representation of message types, enabling model API agnosticism.

Chat Models

Abstractions for chat models have been added, aligning with the underlying ChatGPT API. The interface for these models expects a list of chat messages as input and returns a chat message.

Chat Message Templates

LangChain introduces corresponding chat message prompt templates, such as HumanMessagePromptTemplate, AIMessagePromptTemplate, SystemMessagePromptTemplate, and ChatMessagePromptTemplate, to facilitate the generation of chat messages from user input.

Prompt Values

To ensure interoperability between “normal” LLM APIs and chat-based APIs, LangChain introduces the concept of PromptValue. This class provides methods for converting prompt values into strings for "normal" LLM APIs and into a list of messages for chat-based APIs.

How do these align with our objectives?

The new abstractions align with the following objectives:

Allow users to fully take advantage of the new chat model interface: The abstractions cover all functionality in the ChatGPT interface, enabling users to leverage the new chat model interface effectively.

Allow for interoperability of prompts between “normal” LLM APIs and chat-based APIs: The PromptValue abstraction facilitates seamless conversion of prompts between different model types.

Make the abstractions generic beyond just OpenAI: The explicit concepts of Human/AI/System messages, rather than relying on specific naming conventions, ensure that the abstractions are model API agnostic.

These new abstractions in LangChain provide a foundation for supporting chat-based models, enabling users to take full advantage of the capabilities offered by the new ChatGPT API and future chat-style models. As LangChain continues to evolve, further functionality around chat models, such as improved message-to-string support and chat memory support, will be added.

For more information, refer to the LangChain Python Documentation and JS/TS Documentation.

We hope this tutorial has provided a clear understanding of the new abstractions introduced in LangChain for chat models. Your feedback and suggestions on these abstractions are highly appreciated as we continue to enhance the support for chat-based models in LangChain.

Langchain
ChatGPT
Chat
Recommended from ReadMedium