小编Law*_*Das的帖子

如何在 Python 中将“消息历史记录”添加到基于 llama-index 的 GPT-3

我对使用 llama-index 库来训练 GPT-3 以及通过标准 API 使用 ChatGPT(两者都在 Python 中)还相当陌生。我注意到标准 ChatGPT API 我可以简单地执行以下代码,让 ChatGPT 获取消息历史记录作为上下文:

message_history=[]
completion = openai.ChatCompletion.create(model="gpt-3.5-turbo",messages=message_history)
Run Code Online (Sandbox Code Playgroud)

现在我正在使用 llama-index 库在更具体的上下文中训练 GPT-3,但是我不知道如何让模型也考虑 message_history,这是我目前正在处理的代码,我不知道如何实现消息历史记录:


def construct_index(directory_path):
    # set maximum input size
    max_input_size = 4096
    # set number of output tokens
    num_outputs = 2000
    # set maximum chunk overlap
    max_chunk_overlap = 20
    # set chunk size limit
    chunk_size_limit = 600 

    # define prompt helper
    prompt_helper = PromptHelper(max_input_size, num_outputs, max_chunk_overlap, chunk_size_limit=chunk_size_limit)
    # define LLM
    llm_predictor = LLMPredictor(llm=OpenAI(temperature=0.5, model_name="text-ada-001", max_tokens=num_outputs))
    # define context …
Run Code Online (Sandbox Code Playgroud)

python openai-api gpt-3 gpt-index llama-index

7
推荐指数
1
解决办法
2581
查看次数

标签 统计

gpt-3 ×1

gpt-index ×1

llama-index ×1

openai-api ×1

python ×1