Llama-Index Tips

Llama-Index保存中文文本

    def persist(
        self, persist_path: str, fs: Optional[fsspec.AbstractFileSystem] = None
    ) -> None:
        """Persist the store."""
        fs = fs or fsspec.filesystem("file")
        dirpath = os.path.dirname(persist_path)
        if not fs.exists(dirpath):
            fs.makedirs(dirpath)

        # 保存为英文
        # with fs.open(persist_path, "w") as f:
        #     f.write(json.dumps(self._data))
        
        # 保存为中文
        with fs.open(persist_path, "w", encoding="utf-8") as f:
            f.write(json.dumps(self._data, ensure_ascii=False))

Llama-Index加载azure embedding模型

# embedding model init
from llama_index.embeddings import OpenAIEmbedding

embed_model = OpenAIEmbedding(
                embed_batch_size=1, 
                deployment_name="text-embedding-ada-002", 
                api_type='azure', 
                api_base='https://xxxxxxxxxxxxxxxx.openai.azure.com', 
                api_key='xxxxxxxxxxxxxxxxxxxx')
ret = embed_model.get_query_embedding("hello")
print(ret)

openai.error.InvalidRequestError: Unrecognized request argument supplied: functions

# 使用chat_engine出错
chat_engine = index.as_chat_engine()
response = chat_engine.chat("这篇文档讲了什么?请用中文回复")
print(response)

# bug由openai各模型版本接口不同引起,选择正确的模型版本即可
from llama_index.llms import AzureOpenAI
llm = AzureOpenAI(
    model="gpt-35-turbo-16k",
    deployment="gpt-35-turbo-16k",
    temperature=0.0,
    api_type='azure', 
    api_base='https://xxxxxxxxxxxxxxxxxxxx.openai.azure.com', 
    api_key='xxxxxxxxxxxxxxxxxxxxxxxxxxx',
    # api_version="2023-05-15",    # 错误版本
    api_version="2023-07-01-preview",    # 正确版本
)
# 库版本
openai                        0.28.1
llama-index                   0.8.41

[llama-hub] requests.exceptions.SSLError: HTTPSConnectionPool(host='raw.githubusercontent.com', port=443): Max retries exceeded with url: /emptycrown/llama-hub/main/llama_hub/file/docx/requirements.txt (Caused by SSLError(SSLEOFError(8, 'EOF occurred in violation of protocol (_ssl.c:1122)')))

方案1:替换无效链接

# 无效链接
# LLAMA_HUB_CONTENTS_URL = "https://raw.githubusercontent.com/emptycrown/llama-hub/main"
# 最新链接
LLAMA_HUB_CONTENTS_URL = "https://raw.githubusercontent.com/run-llama/llama-hub/tree/main"    
LOADER_HUB_PATH = "/llama_hub"
LOADER_HUB_URL = LLAMA_HUB_CONTENTS_URL + LOADER_HUB_PATH

方案2:手动下载所需文件

下载文件夹:https://github.com/run-llama/llama-hub/tree/main/llama_hub/file
拷贝到:D:\Miniconda3\envs\pynlp\Lib\site-packages\llama_index\readers\llamahub_modules\file

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值