add uuid for each new chat
This commit is contained in:
@@ -1,5 +1,7 @@
|
|||||||
import tyro
|
import tyro
|
||||||
from typing import Annotated
|
from typing import Annotated
|
||||||
|
import uuid
|
||||||
|
|
||||||
|
|
||||||
from lang_agent.pipeline import Pipeline, PipelineConfig
|
from lang_agent.pipeline import Pipeline, PipelineConfig
|
||||||
from lang_agent.config import load_tyro_conf
|
from lang_agent.config import load_tyro_conf
|
||||||
@@ -19,7 +21,7 @@ def main(
|
|||||||
conf = load_tyro_conf(conf.config_f)
|
conf = load_tyro_conf(conf.config_f)
|
||||||
|
|
||||||
pipeline: Pipeline = conf.setup()
|
pipeline: Pipeline = conf.setup()
|
||||||
|
thread_id = str(uuid.uuid4())
|
||||||
while True:
|
while True:
|
||||||
user_input = input("请讲:")
|
user_input = input("请讲:")
|
||||||
if user_input.lower() == "exit":
|
if user_input.lower() == "exit":
|
||||||
@@ -28,12 +30,12 @@ def main(
|
|||||||
if stream:
|
if stream:
|
||||||
# Streaming mode: print chunks as they arrive
|
# Streaming mode: print chunks as they arrive
|
||||||
print("回答: ", end="", flush=True)
|
print("回答: ", end="", flush=True)
|
||||||
for chunk in pipeline.chat(user_input, as_stream=True):
|
for chunk in pipeline.chat(user_input, as_stream=True, thread_id=thread_id):
|
||||||
print(chunk, end="", flush=True)
|
print(chunk, end="", flush=True)
|
||||||
print() # New line after streaming completes
|
print() # New line after streaming completes
|
||||||
else:
|
else:
|
||||||
# Non-streaming mode: print full response
|
# Non-streaming mode: print full response
|
||||||
response = pipeline.chat(user_input, as_stream=False)
|
response = pipeline.chat(user_input, as_stream=False, thread_id=thread_id)
|
||||||
print(f"回答: {response}")
|
print(f"回答: {response}")
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user