guidance-ai / guidance

A guidance language for controlling large language models.
MIT License
18.61k stars 1.03k forks source link

Mistaken character of streaming output in jupyter notebook #190

Open KaedinLian opened 1 year ago

KaedinLian commented 1 year ago

The bug get .��� character after running guidance writen by chinese in jupyter nokebook. And in normal .py file, it works fine.

To Reproduce Give a full working code snippet that can be pasted into a notebook cell or python file. Make sure to include the LLM load step so we know which model you are using.

# put your code snippet here
import os
import guidance
import guidance

guidance.llm = guidance.llms.transformers.Vicuna("vicuna-13b", device_map="auto", load_in_8bit=True, acceleration=False)
strategy = [
    {"strategy":"直接指导", "explaination": "提供建议、指令或指示,指引寻求帮助者应该怎样做才能改变"},
    {"strategy":"其他", "explaination": "上面六种策略之外的内容"},
    ]
new_question = "人生中的坎坷路,有时把情绪带回家,这情况怎么治?"
zero_program = guidance("""你是一名经验丰富的执证心理咨询师。在咨询时你会用到以下策略。
{{#each strategy}}{{this.strategy}}: {{this.explaination}}
{{/each~}}
下面是咨询过程的摘要,请还原成对话。
{{question}}
{{~#geneach 'conversation' num_iterations=2}}
用户:
{{~gen 'this.user' temperature=0.7 max_tokens=100 stop='\\n'}}
心理咨询师:
{{~gen 'this.ai' temperature=0.7 max_tokens=100 stop='\\n'}}
{{/geneach}}
""")
executed_program = zero_program(
    strategy=strategy,
    question=new_question,
    new_question=new_question
)
# one of output
#用户: 我���得有时候我会���到������过,不知道该���么���。
#心理咨询师: 我明白���的������。有时候我们会���到������和不确定,不知道该���么���。���是,我想告������,���不是������的。这种情������常���,���多人都会���

System info (please complete the following information):

Imformation I seach on the web, someone said " It caused by decoding GBK encoded chinese by uft8". Is there any tips for which code or how should I change? Appreciate.

KaedinLian commented 1 year ago

I now found same issue in .py file when setting stream=True