mirror of
https://github.com/infiniflow/ragflow.git
synced 2025-12-08 20:42:30 +08:00
Feat: Redesign and refactor agent module (#9113)
### What problem does this PR solve? #9082 #6365 <u> **WARNING: it's not compatible with the older version of `Agent` module, which means that `Agent` from older versions can not work anymore.**</u> ### Type of change - [x] New Feature (non-breaking change which adds functionality)
This commit is contained in:
@ -15,9 +15,8 @@
|
||||
#
|
||||
import argparse
|
||||
import os
|
||||
from functools import partial
|
||||
from agent.canvas import Canvas
|
||||
from agent.settings import DEBUG
|
||||
from api import settings
|
||||
|
||||
if __name__ == '__main__':
|
||||
parser = argparse.ArgumentParser()
|
||||
@ -31,19 +30,17 @@ if __name__ == '__main__':
|
||||
parser.add_argument('-m', '--stream', default=False, help="Stream output", action='store_true', required=False)
|
||||
args = parser.parse_args()
|
||||
|
||||
settings.init_settings()
|
||||
canvas = Canvas(open(args.dsl, "r").read(), args.tenant_id)
|
||||
if canvas.get_prologue():
|
||||
print(f"==================== Bot =====================\n> {canvas.get_prologue()}", end='')
|
||||
query = ""
|
||||
while True:
|
||||
ans = canvas.run(stream=args.stream)
|
||||
canvas.reset(True)
|
||||
query = input("\n==================== User =====================\n> ")
|
||||
ans = canvas.run(query=query)
|
||||
print("==================== Bot =====================\n> ", end='')
|
||||
if args.stream and isinstance(ans, partial):
|
||||
cont = ""
|
||||
for an in ans():
|
||||
print(an["content"][len(cont):], end='', flush=True)
|
||||
cont = an["content"]
|
||||
else:
|
||||
print(ans["content"])
|
||||
for ans in canvas.run(query=query):
|
||||
print(ans, end='\n', flush=True)
|
||||
|
||||
if DEBUG:
|
||||
print(canvas.path)
|
||||
question = input("\n==================== User =====================\n> ")
|
||||
canvas.add_user_input(question)
|
||||
print(canvas.path)
|
||||
|
||||
Reference in New Issue
Block a user