LOADING

GPT Cache:2 如何配置缓存存储

ChatGPT2023年5月19日 01:47发布 4个月前更新过 益丰AI
1.5K 0 0

为了阅读以下内容,您需要了解GPTCache的基本使用,参考:

  • Readme文档
  • 使用文档

v0.1.11 (2023.4.14)

  1. 添加openai complete适配器
cache.init(pre_embedding_func=get_prompt)

response = openai.Completion.create(
                model="text-davinci-003",
                prompt=question
            )
  1. 添加langchain和openai bootcamp
  2. 添加openai image适配器(「实验性的」
from gptcache.adapter import openai

cache.init()
cache.set_openai_key()

prompt1 = 'a cat sitting besides a dog'
size1 = '256x256'

openai.Image.create(
    prompt=prompt1,
    size=size1,
    response_format='b64_json'
    )
  1. 改进存储接口

v0.1.10 (2023.4.13)

  1. 添加kreciprocal相似度评估

K-reprciprocl评估是一种受ReID流行的重排方法启发的方法。术语“k-reciprocal”来自算法在前k个列表中创建相似嵌入之间的互惠关系。换句话说,如果嵌入A与嵌入B相似且嵌入B与嵌入A相似,则认为A和B相互之间是“互惠相似”的。这种评估方法放弃了那些在它们的K个最近邻居中不是“互惠相似”的嵌入对。剩下的嵌入对将保留距离以供最终排名。

vector_base = VectorBase("faiss", dimension=d)
data_manager = get_data_manager(CacheBase("sqlite"), vector_base)
evaluation = KReciprocalEvaluation(vectordb=vector_base)
cache.init(
    ... # other configs
    data_manager=data_manager,
    similarity_evaluation=evaluation,
)
  1. 添加LangChainChat适配器
from gptcache.adapter.langchain_models import LangChainChat

cache.init(
    pre_embedding_func=get_msg,
)

chat = LangChainChat(chat=ChatOpenAI(temperature=0))
answer = chat(
    messages=[
        HumanMessage(
            content="Translate this sentence from English to Chinese. I love programming."
        )
    ]
)

v0.1.9 (2023.4.12)

  1. 将数据导入缓存
cache.init()

questions = ["foo1", "foo2"]
answers = ["a1", "a2"]
cache.import_data(questions=questions, answers=answers)
  1. 新的预处理函数:删除提示

当使用LLM模型时,每个输入可能会添加一个提示。如果将带提示的整个消息放入缓存中,则可能导致缓存错误命中率增加。例如,提示文字非常长,而实际问题的文字非常短。

cache_obj.init(
    pre_embedding_func=last_content_without_prompt,
    config=Config(prompts=["foo"]),
)
  1. 嵌入Milvus

嵌入式Milvus是Milvus的轻量级版本,可嵌入到您的Python应用程序中。它是一个单一的二进制文件,可以轻松安装和在您的机器上运行。

with TemporaryDirectory(dir="./") as root:
    db = VectorBase(
                    "milvus",
                    local_mode=True,
                    local_data=str(root),
                    ... #other config
                )
    data_manager = get_data_manager("sqlite", vector_base)
© 版权声明

相关文章

暂无评论

暂无评论...