56 lines
1.7 KiB
Python
56 lines
1.7 KiB
Python
|
||
import asyncio
|
||
import sys
|
||
import os
|
||
|
||
# Add project path
|
||
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)) + "/../")
|
||
|
||
from module_admin.service.ragflow_service import RAGFlowService
|
||
from module_admin.entity.vo.ragflow_vo import ConverseWithChatAssistantModel
|
||
|
||
async def test_rag_internal():
|
||
print("=" * 60)
|
||
print("Direct RAGFlow Service Test (Native Endpoint)")
|
||
print("=" * 60)
|
||
|
||
chat_id = "db4bb966895b11f08cda0242ac130006"
|
||
q = "康达什么时候成立的?"
|
||
|
||
print(f"Chat ID: {chat_id}")
|
||
print(f"Query: {q}")
|
||
print("-" * 60)
|
||
|
||
params = ConverseWithChatAssistantModel(
|
||
chat_id=chat_id,
|
||
question=q,
|
||
stream=True
|
||
)
|
||
|
||
try:
|
||
# Call the NATIVE SERVICE method directly
|
||
# This bypassed the Controller Delta Logic, so we expect CUMULATIVE text here.
|
||
# 修复:直接获取AsyncGenerator,不使用await消费
|
||
result_stream = RAGFlowService.converse_with_chat_assistant_services(params)
|
||
|
||
print("\n[Start Streaming]...")
|
||
async for chunk in result_stream:
|
||
# Native chunk structure: {'data': {'answer': '...'}}
|
||
payload = chunk.get('data') if isinstance(chunk, dict) else chunk
|
||
if isinstance(payload, dict):
|
||
ans = payload.get('answer', '')
|
||
if ans:
|
||
print(f"Token: {repr(ans)}")
|
||
else:
|
||
print(f"Raw Chunk: {chunk}")
|
||
|
||
print("\n[End Streaming]")
|
||
|
||
except Exception as e:
|
||
print(f"\nError: {e}")
|
||
import traceback
|
||
traceback.print_exc()
|
||
|
||
if __name__ == "__main__":
|
||
asyncio.run(test_rag_internal())
|