yihong0618 / xiaogpt

Play ChatGPT and other LLM with Xiaomi AI Speaker
MIT License
6.15k stars 860 forks source link

bard 使用报错 cannot access local variable 'r' #403

Closed wushuzh closed 8 months ago

wushuzh commented 9 months ago

语音启动和小爱同学的语音交互提问,总是返回错误消息 cannot access local variable 'r' where it is not associated with a value

我单独在 python 中,测试使用 Bard-API 测试,可以看到 Bard 的文字回复。

>>>proxies = {
    'http': 'http://myproxy',
    'https': 'http://myproxy'
}
>>> bard = Bard(token=token, proxies=proxies, timeout=30)
>>> bard.get_answer("你会说英文吗?")['content']                           
'是的,我会说英语。我可以用英语进行交流,包括阅读、写作和口语。我还可以翻译英语和其他语言。\r\n\r\n你想用英
语和我说话吗?'

xiaogpt 启动测试:

powershell> python xiaogpt.py --config xiao_config.json
Running xiaogpt now, 用请问开头来提问
或用开始持续对话开始持续对话
--------------------
问题:你会说英文吗?
以下是小爱的回答:  哎呀,我目前只会普通话。其他语言正在解锁中,耐心等待哦~
(小爱继续说,正在问 Bard ,请耐心等待)
以下是 Bard 的回答: 
Bard 回答出错 cannot access local variable 'r' where it is not associated with a value

另一次测试:

powershell> python xiaogpt.py --config xiao_config.json 
Running xiaogpt now, 用请问开头来提问
或用开始持续对话开始持续对话
--------------------
问题:今天几月几号?
以下是小爱的回答:  今天是12月16日,周六,农历癸卯年冬月初四。
(小爱继续说,正在问 Bard ,请耐心等待)
以下是 Bard 的回答: 
Bard 回答出错 cannot access local variable 'r' where it is not associated with a value
wushuzh commented 9 months ago

应该是代理设定的问题。

排查时发现:直接尝试强行把我的代理插入到 bardapi 代码中,初步定位到我的 venv 环境中 bardapi 模块中 core_async.py 文件报错,它调用 client.post 的时候,传入了 proxies 参数,而 httpx 的 AsyncClient.post 方法并不需要(不接收) proxies 参数。

然后我去查看 bardapi 的最新代码,已经去掉了 proxies 参数,有可能是我本地环境的 bardapi 的版本需要更新了。

本地 venv 环境中的 bardapi 的版本为 0.1.38 和 pypi 上 latest 对齐( bardapi 于 2023-10-2 发布该版本),所以可能需要安装 bardapi 在 github 上的版本。

powershell> pip freeze |findstr bardapi
bardapi==0.1.38
wushuzh commented 9 months ago

不确定这是不是安装 git 版本模块的正确做法。

安装报错说 edge-tts 需要的 certifi 版本有问题。

git bash>pip install -U --force-reinstall  git+https://github.com/dsdanielpark/Bard-API.git#egg=bardapi
...

ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour 
is the source of the following dependency conflicts.
edge-tts 6.1.9 requires certifi==2023.07.22, but you have certifi 2023.11.17 which is incompatible.
Successfully installed anyio-4.0.0 bardapi-0.1.38 certifi-2023.11.17 charset-normalizer-3.3.2 colorama-0.4.5 h11-0.13.0 h2-4.1.0 hpack-4.0.0 httpcore-0.17.2 httpx-0.24.1 hyperframe-6.0.1 idna-3.4 requests-2.31.0 sniffio-1.2.0 urllib3-2.1.0     
yihong0618 commented 9 months ago

edge-tts 没装上的话可以搜索那个 certifi 怎么弄

wushuzh commented 9 months ago

好消息是目前 venv 环境中,pip 还可以 list 出来 edge-tts 。

但坏消息是目前室友睡觉中,我就先不呼叫小爱同学了,希望咱们这个工具,未来可以有文本输入的交互模式+小爱音箱 mock 模拟器,方便静默排查 bug。

powershell> pip freeze |findstr edge-tts
edge-tts==6.1.9
frostming commented 9 months ago

别靠猜,加-v 应该可以看到堆栈信息

yihong0618 commented 9 months ago

@wushuzh 稍后我们会更新 gemini 但需要 US ip 墙内 ip 的话可以考虑用 chatglm bard 这个不算太稳定

yzlnew commented 9 months ago

国内还可以考虑 qwen,qwen-max 近期也是免费的。

superwiboy commented 9 months ago

@wushuzh 稍后我们会更新 gemini 但需要 US ip 墙内 ip 的话可以考虑用 chatglm bard 这个不算太稳定

https://www.youtube.com/watch?v=xefaQug_eyk&t=338s 这个视频 4:50有解决办法

yihong0618 commented 9 months ago

@wushuzh 稍后我们会更新 gemini 但需要 US ip 墙内 ip 的话可以考虑用 chatglm bard 这个不算太稳定

https://www.youtube.com/watch?v=xefaQug_eyk&t=338s 这个视频 4:50有解决办法

will support gemini next week maybe

yihong0618 commented 8 months ago

支持了 gemini