Skip to content

Commit

Permalink
Merge pull request HamaWhiteGG#90 from HamaWhiteGG/dev
Browse files Browse the repository at this point in the history
Update
  • Loading branch information
HamaWhiteGG authored Aug 25, 2023
2 parents c6bb684 + e3d3e40 commit 0d8e2dc
Show file tree
Hide file tree
Showing 12 changed files with 184 additions and 14 deletions.
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,16 @@

Java version of LangChain, bringing the capabilities of LLM to big data platforms like Flink and Spark.

> If you are interested, you can add me on WeChat: HamaWhite, or send email to baisongxx@gmail.com
## 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](https://github.com/langchain-ai/langchain).

If you use WeChat, you can join the following group.
This library is aimed at assisting in the development of those types of applications.

<img src="https://github.com/HamaWhiteGG/langchain-java/blob/dev/docs/images/wechat-group.png" alt="wechat-group.png" style="width:40%;">

The following example can view in the [langchain-example](langchain-examples/src/main/java/com/hw/langchain/examples)

Expand Down
Binary file removed docs/images/wechat-group.png
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* limitations under the License.
*/

package com.hw.langchain.chains.question.answering;
package com.hw.langchain.chains;

/**
* @author HamaWhite
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,19 @@
* limitations under the License.
*/

package com.hw.langchain.chains.question.answering.init;
package com.hw.langchain.chains.question.answering;

import com.hw.langchain.base.language.BaseLanguageModel;
import com.hw.langchain.chains.ChainType;
import com.hw.langchain.chains.combine.documents.base.BaseCombineDocumentsChain;
import com.hw.langchain.chains.combine.documents.stuff.StuffDocumentsChain;
import com.hw.langchain.chains.llm.LLMChain;
import com.hw.langchain.chains.question.answering.ChainType;
import com.hw.langchain.prompts.base.BasePromptTemplate;

import java.util.Map;
import java.util.function.Function;

import static com.hw.langchain.chains.question.answering.ChainType.STUFF;
import static com.hw.langchain.chains.ChainType.STUFF;
import static com.hw.langchain.chains.question.answering.StuffPrompt.PROMPT_SELECTOR;

/**
Expand All @@ -37,6 +37,7 @@
public class Init {

private Init() {
throw new IllegalStateException("Utility class");
}

private static final Map<ChainType, Function<BaseLanguageModel, BaseCombineDocumentsChain>> LOADER_MAPPING = Map.of(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@
package com.hw.langchain.chains.retrieval.qa.base;

import com.hw.langchain.base.language.BaseLanguageModel;
import com.hw.langchain.chains.ChainType;
import com.hw.langchain.chains.combine.documents.base.BaseCombineDocumentsChain;
import com.hw.langchain.chains.question.answering.ChainType;
import com.hw.langchain.schema.BaseRetriever;
import com.hw.langchain.schema.Document;

import java.util.List;

import static com.hw.langchain.chains.question.answering.ChainType.STUFF;
import static com.hw.langchain.chains.question.answering.init.Init.loadQaChain;
import static com.hw.langchain.chains.ChainType.STUFF;
import static com.hw.langchain.chains.question.answering.Init.loadQaChain;

/**
* Chain for question-answering against an index.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.hw.langchain.chains.summarize;

import com.hw.langchain.prompts.prompt.PromptTemplate;

import java.util.List;

/**
* @author HamaWhite
*/
public class MapReducePrompt {

private MapReducePrompt() {
throw new IllegalStateException("Utility class");
}

public static final PromptTemplate PROMPT = new PromptTemplate(
List.of("text"),
"""
Write a concise summary of the following:
"{text}"
CONCISE SUMMARY:""");
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.hw.langchain.chains.summarize;

import com.hw.langchain.prompts.prompt.PromptTemplate;

import java.util.List;

/**
* @author HamaWhite
*/
public class RefinePrompt {

private RefinePrompt() {
throw new IllegalStateException("Utility class");
}

public static final PromptTemplate REFINE_PROMPT = new PromptTemplate(
List.of("existing_answer", "text"),
"""
Your job is to produce a final summary
We have provided an existing summary up to a certain point: {existing_answer}
We have the opportunity to refine the existing summary
(only if needed) with some more context below.
------------
{text}
------------
Given the new context, refine the original summary
If the context isn't useful, return the original summary.
""");

public static final PromptTemplate PROMPT = new PromptTemplate(
List.of("text"),
"""
Write a concise summary of the following:
"{text}"
CONCISE SUMMARY:
""");
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.hw.langchain.chains.summarize;

import com.hw.langchain.prompts.prompt.PromptTemplate;

import java.util.List;

/**
* @author HamaWhite
*/
public class StuffPrompt {

private StuffPrompt() {
throw new IllegalStateException("Utility class");
}

public static final PromptTemplate PROMPT = new PromptTemplate(
List.of("text"),
"""
Write a concise summary of the following:
"{text}"
CONCISE SUMMARY:""");
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.hw.langchain.chains.summarize;

/**
* @author HamaWhite
*/
public class SummarizeUtils {

private SummarizeUtils() {
throw new IllegalStateException("Utility class");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;

import static com.hw.langchain.chains.question.answering.ChainType.STUFF;
import static com.hw.langchain.chains.ChainType.STUFF;
import static com.hw.langchain.vectorstores.pinecone.PineconeTest.INDEX_NAME;
import static org.junit.jupiter.api.Assertions.*;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

import io.milvus.param.ConnectParam;

import static com.hw.langchain.chains.question.answering.ChainType.STUFF;
import static com.hw.langchain.chains.ChainType.STUFF;
import static com.hw.langchain.examples.utils.PrintUtils.println;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import com.hw.langchain.llms.openai.OpenAI;
import com.hw.langchain.text.splitter.CharacterTextSplitter;

import static com.hw.langchain.chains.question.answering.ChainType.STUFF;
import static com.hw.langchain.chains.ChainType.STUFF;
import static com.hw.langchain.examples.utils.PrintUtils.println;
import static com.hw.langchain.examples.vectorstores.PineconeExample.*;

Expand Down

0 comments on commit 0d8e2dc

Please sign in to comment.