LangChain Java-the Java implementation of LangChain
https://github.com/HamaWhiteGG/langchain-java
1. What is this?
This is the Java language implementation of LangChain.
Large language models (LLMs) are emerging as a transformative technology, enabling developers to build applications that they previously could not. But using these LLMs in isolation is often not enough to create a truly powerful app - the real power comes when you can combine them with other sources of computation or knowledge.
This library is aimed at assisting in the development of those types of applications.
Looking for the Python version? Check out LangChain.
2. Quickstart Guide
This tutorial gives you a quick walkthrough about building an end-to-end language model application with LangChain.
View the Quickstart Guide on the LangChain official website.
2.1 Maven Repository
Prerequisites for building:
Java 17 or later
Unix-like environment (we use Linux, Mac OS X)
Maven (we recommend version 3.8.6 and require at least 3.5.4)
2.2 Environment Setup
Using LangChain will usually require integrations with one or more model providers, data stores, apis, etc. For this example, we will be using OpenAI’s APIs.
We will then need to set the environment variable.
If you want to set the API key and proxy dynamically, you can use the openaiApiKey and openaiProxy parameter when initiating OpenAI class.
The following test code can be used to view the QuickStart.java
2.3 LLMs: Get predictions from a language model
The most basic building block of LangChain is calling an LLM on some input. Let’s walk through a simple example of how to do this. For this purpose, let’s pretend we are building a service that generates a company name based on what the company makes.
2.4 Prompt Templates: Manage prompts for LLMs
Calling an LLM is a great first step, but it’s just the beginning. Normally when you use an LLM in an application, you are not sending user input directly to the LLM. Instead, you are probably taking user input and constructing a prompt, and then sending that to the LLM.
2.5 Chains: Combine LLMs and prompts in multi-step workflows
Up until now, we’ve worked with the PromptTemplate and LLM primitives by themselves. But of course, a real application is not just one primitive, but rather a combination of them.
A chain in LangChain is made up of links, which can be either primitives like LLMs or other chains.
2.5.1 LLM Chain
The most core type of chain is an LLMChain, which consists of a PromptTemplate and an LLM.
2.5.2 SQL Chain
This example demonstrates the use of the SQLDatabaseChain for answering questions over a database.
2.6 Agents: Dynamically Call Chains Based on User Input
Agents no longer do: they use an LLM to determine which actions to take and in what order. An action can either be using a tool and observing its output, or returning to the user.
When used correctly agents can be extremely powerful. In this tutorial, we show you how to easily use agents through the simplest, highest level API.
Set the appropriate environment variables.
Now we can get started!
3. Run Test Cases from Source
4. Apply Spotless
5. Support
Don’t hesitate to ask!
Open an issue if you find a bug in Flink.
6. Fork and Contribute
This is an active open-source project. We are always open to people who want to use the system or contribute to it.
Contact me if you are looking for implementation tasks that fit your skills.
版权声明: 本文为 InfoQ 作者【HamaWhite】的原创文章。
原文链接:【http://xie.infoq.cn/article/80bbd647efa8a9ccd39436fe9】。
本文遵守【CC BY-NC】协议,转载请保留原文出处及本版权声明。
评论