-
Notifications
You must be signed in to change notification settings - Fork 313
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
41e95a3
commit c18df1f
Showing
11 changed files
with
102 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# -*- coding: utf-8 -*- | ||
from kag.interface import VectorizerABC | ||
from kag.builder.model.sub_graph import SubGraph | ||
|
||
|
||
def test_batch_vectorizer(): | ||
batch_vectorizer = VectorizerABC.from_config( | ||
{ | ||
"type": "batch", | ||
"vectorizer_model": { | ||
"type": "bge", | ||
"path": "~/.cache/vectorizer/BAAI/bge-base-zh-v1.5", | ||
"url": "", | ||
"vector_dimensions": 768, | ||
}, | ||
} | ||
) | ||
names = [ | ||
"精卫填海", | ||
"海阔天空", | ||
"空前绝后", | ||
"后来居上", | ||
"上下一心", | ||
"心旷神怡", | ||
"怡然自得", | ||
"得心应手", | ||
] | ||
subgraph = SubGraph([], []) | ||
for name in names: | ||
subgraph.add_node(id=name, name=name, label="Keyword") | ||
|
||
new_graph = batch_vectorizer.invoke(subgraph)[0] | ||
assert len(subgraph.nodes) == len(new_graph.nodes) | ||
for node in new_graph.nodes: | ||
assert node.name in names | ||
assert "_name_vector" in node.properties | ||
assert len(node.properties["_name_vector"]) == 768 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# -*- coding: utf-8 -*- | ||
from kag.common.conf import KAG_CONFIG | ||
from kag.builder.model.chunk import Chunk | ||
from kag.interface import ExtractorABC | ||
from kag.builder.model.sub_graph import SubGraph | ||
|
||
llm_config = KAG_CONFIG.all_config["llm"] | ||
|
||
|
||
def test_kag_extractor(): | ||
conf = {"type": "kag", "llm": llm_config, "ner_prompt": {"type": "default_ner"}} | ||
|
||
extractor = ExtractorABC.from_config(conf) | ||
with open("../data/test_txt.txt", "r") as reader: | ||
content = reader.read() | ||
chunk = Chunk(id="111", name="test", content=content) | ||
subgraph = extractor.invoke(chunk)[0] | ||
print(subgraph) | ||
print(type(subgraph)) | ||
assert isinstance(subgraph, SubGraph) | ||
|
||
|
||
def test_spg_extractor(): | ||
conf = {"type": "spg", "llm": llm_config, "ner_prompt": {"type": "default_ner"}} | ||
|
||
extractor = ExtractorABC.from_config(conf) | ||
with open("../data/test_txt.txt", "r") as reader: | ||
content = reader.read() | ||
chunk = Chunk(id="111", name="test", content=content) | ||
subgraph = extractor.invoke(chunk)[0] | ||
print(subgraph) | ||
print(type(subgraph)) | ||
assert isinstance(subgraph, SubGraph) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters