如果是从 huggingface.co 下载模型,由于国内不能访问,所以建议先配置一下环境变量,
通过访问国内镜像站点 https://hf-mirror.com来下载模型

使用huggingface 官方提供的 [huggingface-cli](https://hf-mirror.com/docs/huggingface_hub/guides/download#download-from-the-cli) 命令行工具。

1
pip install -U huggingface_hub

基本命令示例:

1
2
export HF_ENDPOINT=https://hf-mirror.com
huggingface-cli download --resume-download --local-dir-use-symlinks False bigscience/bloom-560m --local-dir bloom-560m

PS:详情参考https://fanfer.top/2024/01/18/HuggingFace-下载模型/https://hf-mirror.com

如果是国内想要通过OpenAI API访问GPT

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
from openai import OpenAI

client = OpenAI(
base_url='https://api.openai-proxy.org/v1',
api_key='sk-xxxxxxxx',
)

chat_completion = client.chat.completions.create(
messages=[
{
"role": "user",
"content": "Say hi",
}
],
model="gpt-3.5-turbo",
)

如使用LangChain,可以使用closeai提供的代理进行访问

1
2
export OPENAI_API_BASE=https://api.openai-proxy.org/v1
export OPENAI_API_KEY=sk-xxxxxxxx