refactor: rename "text" to "document"

This commit is contained in:
michael 2024-01-24 11:36:28 +08:00
parent cc32eeae7f
commit 672fb031ec
16 changed files with 117 additions and 46 deletions

View File

@ -0,0 +1,37 @@
/*
* Copyright (c) 2022-2023, Agents-Flex (fuhai999@gmail.com).
* <p>
* Licensed 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
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* 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.agentsflex.document;
import java.io.InputStream;
public abstract class BaseLoader implements Loader{
protected Parser parser;
public BaseLoader(Parser parser) {
this.parser = parser;
}
@Override
public Document load() {
InputStream stream = loadInputStream();
return parser.parse(stream);
}
public abstract InputStream loadInputStream();
}

View File

@ -13,11 +13,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.agentsflex.text;
package com.agentsflex.document;
import com.agentsflex.util.Metadata;
public class Text extends Metadata {
public class Document extends Metadata {
private String content;
public String getContent() {

View File

@ -13,8 +13,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.agentsflex.text;
package com.agentsflex.document;
public interface Loader {
Text load();
Document load();
}

View File

@ -13,10 +13,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.agentsflex.text;
package com.agentsflex.document;
import java.io.InputStream;
public interface Parser {
Text parse(InputStream stream);
Document parse(InputStream stream);
}

View File

@ -13,10 +13,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.agentsflex.text;
package com.agentsflex.document;
import java.util.List;
public interface Splitter {
List<Text> split(Text text);
List<Document> split(Document text);
}

View File

@ -13,14 +13,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.agentsflex.text.loader;
package com.agentsflex.document;
import com.agentsflex.text.Loader;
import com.agentsflex.text.Text;
public class FileLoader implements Loader {
@Override
public Text load() {
return null;
}
public interface Transformer {
Document transform(Document document);
}

View File

@ -0,0 +1,33 @@
/*
* Copyright (c) 2022-2023, Agents-Flex (fuhai999@gmail.com).
* <p>
* Licensed 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
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* 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.agentsflex.document.loader;
import com.agentsflex.document.BaseLoader;
import com.agentsflex.document.Parser;
import java.io.InputStream;
public class FileLoader extends BaseLoader {
public FileLoader(Parser parser) {
super(parser);
}
@Override
public InputStream loadInputStream() {
return null;
}
}

View File

@ -13,14 +13,21 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.agentsflex.text.loader;
package com.agentsflex.document.loader;
import com.agentsflex.text.Loader;
import com.agentsflex.text.Text;
import com.agentsflex.document.BaseLoader;
import com.agentsflex.document.Parser;
import java.io.InputStream;
public class HttpLoader extends BaseLoader{
public HttpLoader(Parser parser) {
super(parser);
}
public class HttpLoader implements Loader {
@Override
public Text load() {
public InputStream loadInputStream() {
return null;
}
}

View File

@ -13,16 +13,16 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.agentsflex.text.splitter;
package com.agentsflex.document.splitter;
import com.agentsflex.text.Splitter;
import com.agentsflex.text.Text;
import com.agentsflex.document.Splitter;
import com.agentsflex.document.Document;
import java.util.List;
public class MarkdownSplitter implements Splitter {
@Override
public List<Text> split(Text text) {
public List<Document> split(Document text) {
return null;
}
}

View File

@ -13,16 +13,16 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.agentsflex.text.splitter;
package com.agentsflex.document.splitter;
import com.agentsflex.text.Splitter;
import com.agentsflex.text.Text;
import com.agentsflex.document.Splitter;
import com.agentsflex.document.Document;
import java.util.List;
public class ParagraphSplitter implements Splitter {
@Override
public List<Text> split(Text text) {
public List<Document> split(Document text) {
return null;
}
}

View File

@ -13,10 +13,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.agentsflex.text.splitter;
package com.agentsflex.document.splitter;
import com.agentsflex.text.Splitter;
import com.agentsflex.text.Text;
import com.agentsflex.document.Splitter;
import com.agentsflex.document.Document;
import com.agentsflex.util.StringUtil;
import java.util.ArrayList;
@ -32,14 +32,14 @@ public class SimpleSplitter implements Splitter {
}
@Override
public List<Text> split(Text text) {
public List<Document> split(Document text) {
if (text == null || StringUtil.noText(text.getContent())) {
return Collections.emptyList();
}
String[] textArray = text.getContent().split(regex);
List<Text> texts = new ArrayList<>(textArray.length);
List<Document> texts = new ArrayList<>(textArray.length);
for (String textString : textArray) {
Text newText = new Text();
Document newText = new Document();
newText.setMetadataMap(text.getMetadataMap());
newText.setContent(textString);
texts.add(newText);

View File

@ -15,11 +15,11 @@
*/
package com.agentsflex.llm;
import com.agentsflex.text.Text;
import com.agentsflex.document.Document;
import com.agentsflex.vector.VectorData;
public interface Embeddings {
VectorData embeddings(Text prompt);
VectorData embeddings(Document prompt);
}

View File

@ -22,7 +22,7 @@ import com.agentsflex.message.HumanMessage;
import com.agentsflex.message.Message;
import com.agentsflex.message.MessageStatus;
import com.agentsflex.prompt.Prompt;
import com.agentsflex.text.Text;
import com.agentsflex.document.Document;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.JSONPath;
@ -47,7 +47,7 @@ public class OpenAiLLmUtil {
}
public static String promptToEmbeddingsPayload(Text text) {
public static String promptToEmbeddingsPayload(Document text) {
// https://platform.openai.com/docs/api-reference/making-requests
String payload = "{\n" +

View File

@ -24,7 +24,7 @@ import com.agentsflex.llm.BaseLlm;
import com.agentsflex.llm.ChatListener;
import com.agentsflex.llm.FunctionCalling;
import com.agentsflex.prompt.Prompt;
import com.agentsflex.text.Text;
import com.agentsflex.document.Document;
import com.agentsflex.util.OKHttpUtil;
import com.agentsflex.util.StringUtil;
import com.agentsflex.vector.VectorData;
@ -61,7 +61,7 @@ public class OpenAiLlm extends BaseLlm<OpenAiLlmConfig> implements FunctionCalli
@Override
public VectorData embeddings(Text text) {
public VectorData embeddings(Document text) {
Map<String, String> headers = new HashMap<>();
headers.put("Content-Type", "application/json");
headers.put("Authorization", "Bearer " + getConfig().getApiKey());

View File

@ -23,7 +23,7 @@ import com.agentsflex.llm.BaseLlm;
import com.agentsflex.llm.ChatListener;
import com.agentsflex.message.AiMessage;
import com.agentsflex.prompt.Prompt;
import com.agentsflex.text.Text;
import com.agentsflex.document.Document;
import com.agentsflex.vector.VectorData;
import java.util.HashMap;
@ -62,7 +62,7 @@ public class QwenLlm extends BaseLlm<QwenLlmConfig> {
@Override
public VectorData embeddings(Text text) {
public VectorData embeddings(Document text) {
return null;
}
}

View File

@ -22,7 +22,7 @@ import com.agentsflex.llm.client.impl.WebSocketClient;
import com.agentsflex.llm.BaseLlm;
import com.agentsflex.llm.ChatListener;
import com.agentsflex.prompt.Prompt;
import com.agentsflex.text.Text;
import com.agentsflex.document.Document;
import com.agentsflex.vector.VectorData;
public class SparkLlm extends BaseLlm<SparkLlmConfig> {
@ -46,7 +46,7 @@ public class SparkLlm extends BaseLlm<SparkLlmConfig> {
@Override
public VectorData embeddings(Text text) {
public VectorData embeddings(Document text) {
return null;
}
}