any example code to demo a multi-turn conversation with starchat-beta?

#25
by alfred78 - opened

Following example code shows how to use pipeline to generate code with starchat:

outputs = pipe(prompt, max_new_tokens=256, do_sample=True, temperature=0.2, top_k=50, top_p=0.95, eos_token_id=49155)

while this demo is a "once-turn" conversation, how to implement a multi-turn conversation then?

I noticed following comments in above example code , so I assume here I should utilize the token ID 49155 to indicate starchat whether a conversation turn is ended or not. But how to code?

# We use a special <|end|> token with ID 49155 to denote ends of a turn

Following is a pseudo code snippet I can figure out ( I am using gradio herein), but can anyone tell me it is correct or not? Shall I use a for to loop ? Thanks a lot.

count=0
eos_token_id = 0
chatbot = gr.Chatbot()
history = gr.State([])
count += 1
if count % 5 == 0: # try 5 rounds query at most for each turn
    #indicate end of this turn
    eos_token_id = 49155
    count = 0

submitBtn.click(predict,
                    [user_input, chatbot, history, eos_token_id],
                    [chatbot, history],
                    show_progress=True)
submitBtn.click(reset_user_input, [], [user_input])
emptyBtn.click(reset_state, outputs=[chatbot, history], show_progress=True)

may be you can use TextIteratorStreamer or TextStreamer from transform@4.3x.x

Sign up or log in to comment