Compare commits
4 Commits
2706cf9d5a
..
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 72ddf46fc7 | |||
| f57c0c84ef | |||
| 9ee24627c2 | |||
| 88761a5d10 |
@@ -17,7 +17,7 @@ aiostream = "^0.6.2"
|
|||||||
llama-index = "0.10.63"
|
llama-index = "0.10.63"
|
||||||
cachetools = "^5.3.3"
|
cachetools = "^5.3.3"
|
||||||
protobuf = "4.25.4"
|
protobuf = "4.25.4"
|
||||||
nltk = "^3.9.1"
|
nltk = "^3.8.2"
|
||||||
jieba = "^0.42.1"
|
jieba = "^0.42.1"
|
||||||
|
|
||||||
#arize-phoenix = "^4.12.0"
|
#arize-phoenix = "^4.12.0"
|
||||||
@@ -35,7 +35,6 @@ chroma="^0.2.0"
|
|||||||
llama-index-vector-stores-chroma = "^0.1.10"
|
llama-index-vector-stores-chroma = "^0.1.10"
|
||||||
llama-index-readers-json = "^0.1.5"
|
llama-index-readers-json = "^0.1.5"
|
||||||
llama-index-retrievers-bm25 = "^0.2.2"
|
llama-index-retrievers-bm25 = "^0.2.2"
|
||||||
llama-index-experimental = "^0.2.0"
|
|
||||||
|
|
||||||
duckduckgo_search = "^6.2.6"
|
duckduckgo_search = "^6.2.6"
|
||||||
|
|
||||||
@@ -63,12 +62,6 @@ version = "^0.8"
|
|||||||
version = "0.0.7"
|
version = "0.0.7"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
[[tool.poetry.source]]
|
|
||||||
name = "mirrors"
|
|
||||||
url = "https://pypi.tuna.tsinghua.edu.cn/simple/"
|
|
||||||
priority = "default"
|
|
||||||
|
|
||||||
[build-system]
|
[build-system]
|
||||||
requires = [ "poetry-core" ]
|
requires = [ "poetry-core" ]
|
||||||
build-backend = "poetry.core.masonry.api"
|
build-backend = "poetry.core.masonry.api"
|
||||||
@@ -1,81 +0,0 @@
|
|||||||
from app.observability import init_observability
|
|
||||||
from app.settings import init_settings
|
|
||||||
from dotenv import load_dotenv
|
|
||||||
|
|
||||||
import nest_asyncio
|
|
||||||
nest_asyncio.apply()
|
|
||||||
|
|
||||||
load_dotenv()
|
|
||||||
|
|
||||||
|
|
||||||
from llama_index.core.node_parser import SentenceSplitter
|
|
||||||
from llama_index.core import (
|
|
||||||
VectorStoreIndex,
|
|
||||||
SimpleDirectoryReader,
|
|
||||||
Response,
|
|
||||||
)
|
|
||||||
from llama_index.core.evaluation import (
|
|
||||||
FaithfulnessEvaluator,
|
|
||||||
DatasetGenerator,
|
|
||||||
CorrectnessEvaluator,
|
|
||||||
SemanticSimilarityEvaluator,)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
init_settings()
|
|
||||||
init_observability()
|
|
||||||
|
|
||||||
faith_evaluator_qwen = FaithfulnessEvaluator() #诚实度评测
|
|
||||||
corr_evaluator_qwen = CorrectnessEvaluator() #准确率评测
|
|
||||||
Seman_evaluator_qwen = SemanticSimilarityEvaluator()#嵌入相似度评估
|
|
||||||
|
|
||||||
documents = SimpleDirectoryReader("D:/LLM_model/text2sql/zjdataai-app-test/backend/data-test").load_data()
|
|
||||||
|
|
||||||
splitter = SentenceSplitter(chunk_size=512)
|
|
||||||
|
|
||||||
|
|
||||||
vector_index = VectorStoreIndex.from_documents(
|
|
||||||
documents, transformations=[splitter],
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
# # 运行评估
|
|
||||||
# query_engine = vector_index.as_query_engine()
|
|
||||||
# response_vector = query_engine.query("工程监理费的金额是多少?")
|
|
||||||
# eval_result = evaluator_qwen.evaluate_response(response=response_vector)
|
|
||||||
|
|
||||||
# print(response_vector)
|
|
||||||
# print(eval_result)
|
|
||||||
|
|
||||||
|
|
||||||
question_generator = DatasetGenerator.from_documents(documents)
|
|
||||||
eval_questions = question_generator.generate_questions_from_nodes(5)
|
|
||||||
print(eval_questions)
|
|
||||||
|
|
||||||
import asyncio
|
|
||||||
|
|
||||||
async def evaluate_query_engine_async(query_engine, questions):
|
|
||||||
c = [query_engine.aquery(q) for q in questions]
|
|
||||||
gathering_future = asyncio.gather(*c)
|
|
||||||
results = await gathering_future
|
|
||||||
#print(results)
|
|
||||||
|
|
||||||
total_correct = 0
|
|
||||||
for r in results:
|
|
||||||
eval_result = (
|
|
||||||
1 if faith_evaluator_qwen.evaluate_response(response=r).passing else 0
|
|
||||||
)
|
|
||||||
total_correct += eval_result
|
|
||||||
|
|
||||||
return total_correct, len(results)
|
|
||||||
|
|
||||||
def evaluate_query_engine(query_engine, questions):
|
|
||||||
loop = asyncio.get_event_loop()
|
|
||||||
correct, total = loop.run_until_complete(evaluate_query_engine_async(query_engine, questions))
|
|
||||||
return correct, total
|
|
||||||
|
|
||||||
# 使用 evaluate_query_engine 函数
|
|
||||||
vector_query_engine = vector_index.as_query_engine()
|
|
||||||
correct, total = evaluate_query_engine(vector_query_engine, eval_questions[:5])
|
|
||||||
|
|
||||||
print(f"score: {correct}/{total}")
|
|
||||||
Reference in New Issue
Block a user