在这几天的课程学习中,我在 AI 练中学中运行项目时遇到了一些问题,现将这些问题和解决方法记录下来,也分享给大家。
配置使用自己的API
由于 AI 练中学中只预置了 10k 限额的免费豆包API,一个月的课程学习大概率是不够的,我自己是在第二天就用完了。
可以根据 AI 练中学文件目录中的 README.md 文件进行操作。
注册完成后,可以在如图位置打开.cloudiderc文件:
配置完成后大概是这样子的, 双引号不是必要的:
export OPENAI_API_KEY=xxxxxxxxxxxxxxxxxxxx
export OPENAI_BASE_URL="https://xxxxxxxx"
export LLM_MODELEND="ep-xxxxxxxxxx"
01/01报错
配置完成后,一般来说 00-01的文件大部分都是可以直接运行的,除了01/01,它会报错。
Traceback (most recent call last):
File "/cloudide/workspace/LangChain-shizhanke/01_LangChain快速入门/01_TextModel.py", line 17, in <module>
response = client.completions.create(
^^^^^^^^^^^^^^^^^^^^^^^^^^
......
openai.NotFoundError: Error code: 404
通过出错位置的第一个提示和结尾,可以大概猜出问题与openai和client.completions.create有关,具体报错的原因在代码开头的注释有说明:
OpenAI的Completions API已经在2023年7月完成最后一次更新并废弃......Doubao API兼容最新版本的API调用,对废弃接口不再支持,本文件代码仅做示意。
02/DocQA.py报错
在运行文件后,会发现如下错误:
Traceback (most recent call last):
File "/cloudide/workspace/LangChain-shizhanke/02_文档QA系统/DocQA.py", line 78, in <module>
vectorstore = Qdrant.from_documents(
^^^^^^^^^^^^^^^^^^^^^^
......
volcenginesdkarkruntime._exceptions.ArkNotFoundError: Error code: 404
像上一个报错一样,可以大概猜出问题与volcenginesdkarkruntime和Qdrant.from_documents有关,我又看了Qdrant.from_documents下的代码:
embedding=DoubaoEmbeddings(
model=os.environ["EMBEDDING_MODELEND"],
), # 用OpenAI的Embedding Model做嵌入
通过这一段,可以看出应该是缺少一个Embedding Model,但这个model要从哪里获取呢,最后通过阅读这篇文章中我得知了解决方法 MarsCode中Langchain使用与注意事项 | 豆包MarsCode AI刷题在Marscode使用Langch - 掘金,希望大家也去看看,我就不再赘述了。
不过在.cloudiderc里添加 Embedding Model id后执行source ~/.cloudiderc就可以运行了,似乎不需要在文件里再导入一次id。
Embedding Model配置好后再运行会发现出现如下的警告:
WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.
这是告知我们要使用web浏览。
它可以使用页面的右方点击眼睛图标打开:
或者在页面下方的网络服务中复制地址,然后在新标签页的网址栏中粘贴打开:
03/04报错
在运行文件后,会发现如下错误:
Traceback (most recent call last):
File "/cloudide/workspace/LangChain-shizhanke/03_模型IO/04_ModelIO_HuggingFace.py", line 24, in <module>
model = HuggingFaceHub(repo_id="google/flan-t5-large")
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
......
Did not find huggingfacehub_api_token, please add an environment variable `HUGGINGFACEHUB_API_TOKEN` which contains it, or pass `huggingfacehub_api_token` as a named parameter. (type=value_error)
错误很明显是因为没有huggingfacehub_api_token,然后当我尝试注册huggingfacehub时,我发现无法进入网页,由于不想使用魔法,我就没有再进行尝试。
其他错误
在摸索着解决以上问题时,我还遇到了 name 'xxx' is not defined的问题,后来我通过代码里的标黄,发现是我自己把需要的环境给删了,最后用pip install xxx下载回来了。
所以如果遇到类似报错,可以去看看是不是代码开头导入类的部分出了问题。