时间过的很快,这个课程已经上线两个多月了,在这期间,有同学反馈了一些问题。接下来,就针对一些共性问题,给大家补录几节课,做一个统一的答疑。

问题列表

1、OpenAI相关问题

a) 账号申请就遇到了坎,比如验证手机号、绑定信用卡等。

最简单的方法,就是去万能的淘宝,直接买个账号即可,搜api key。需要注意的是,得跟商家确认,调用频率的限制,每分钟3次的不行。否则可能会报错,或者是响应特别慢。

如果想自己注册,又没有国外信用卡,可以用WildCard虚拟卡。

b) 科学上网之后,还是请求不通OpenAI的API。

这个原因是,梯子不是全局的,浏览器请求和终端请求是不一样的。

# openai_01_base.py
OPENAI_BASE_URL = 'https://api.openai-proxy.com/v1'
client = OpenAI(
     api_key='replace with your openai api key',
     base_url=OPENAI_BASE_URL
)

# .env
OPENAI_BASE_URL = 'https://api.openai-proxy.com/v1'

淘宝买的账号,很有可能需要配到他们的代理,也是改这个配置即可。以上代码,在课程讲义中都有更新,视频更新成本高,对照讲义学习。

2、文件编码问题

UnicodeDecodeError: 'gbk' codec can't decode byte 0xac in position 14: illegal multibyte sequence

# data_process.py
loader = CSVLoader(file_path, encoding='utf-8')
loader = TextLoader(file_path, encoding='utf-8')

3、Google搜索问题

跟OpenAI的类似,也是全局梯子的问题。百度返回结果解析有问题,可以用360搜索。

inputs = {
    'query': query,
    'url': 'https://www.so.com/s?q='+query.replace(' ', '+')
}

4、Neo4j协议问题

报错:ValueError: Unknown protocol 'neo4j'

NEO4J_URI='bolt://127.0.0.1:7687'

5、hwchase17/react-chat请求超时

# prompt.py
REACT_CHAT_PROMPT_TPL = '''
Assistant is a large language model trained by OpenAI.

Assistant is designed to be able to assist with a wide range of tasks, from answering simple questions to providing in-depth explanations and discussions on a wide range of topics. As a language model, Assistant is able to generate human-like text based on the input it receives, allowing it to engage in natural-sounding conversations and provide responses that are coherent and relevant to the topic at hand.

Assistant is constantly learning and improving, and its capabilities are constantly evolving. It is able to process and understand large amounts of text, and can use this knowledge to provide accurate and informative responses to a wide range of questions. Additionally, Assistant is able to generate its own text based on the input it receives, allowing it to engage in discussions and provide explanations and descriptions on a wide range of topics.

Overall, Assistant is a powerful tool that can help with a wide range of tasks and provide valuable insights and information on a wide range of topics. Whether you need help with a specific question or just want to have a conversation about a particular topic, Assistant is here to assist.

TOOLS:
------

Assistant has access to the following tools:

{tools}

To use a tool, please use the following format:

```
Thought: Do I need to use a tool? Yes
Action: the action to take, should be one of [{tool_names}]
Action Input: the input to the action
Observation: the result of the action
```

When you have a response to say to the Human, or if you do not need to use a tool, you MUST use the format:

```
Thought: Do I need to use a tool? No
Final Answer: [your response here]
```

Begin!

Previous conversation history:
{chat_history}

New input: {input}
{agent_scratchpad}
'''

# agent.py
prompt = PromptTemplate.from_template(REACT_CHAT_PROMPT_TPL)

6、依赖包问题

运行环境,python>=3.9即可,基础部分按课上演示的版本安装,项目部分依赖包如下。需要注意的是,安装包的环境,和运行代码的环境要一致。

pip install -r requirements.txt

# requirements.txt
tqdm
pandas
py2neo
langchain==0.1.14
langchainhub
langchain_openai
gradio==4.9.0
faiss-cpu
python-dotenv
chromadb
bs4

以上就是目前反馈的一些共性问题,因为LangChain还是0.x的版本,不是正式版,所以难免会有一些意料之外的问题,如果遇到其他问题,也可以及时反馈给小助手。

本文链接:http://www.ichenhua.cn/edu/note/728

版权声明:本文为「陈华编程」原创课程讲义,请给与知识创作者起码的尊重,未经许可不得传播或转售!