langchain+chatgpt打造私有文档数据的问答系统代码

代码语言:python

所属分类:其他

代码描述:langchain+chatgpt打造私有文档数据的问答系统代码,给他一篇文档数据,chatgpt就可以帮你回答文档的内容,可设置temperature,max_tokens,max_chunk_overlap等参数。

代码标签: langchain chatgpt 打造 私有 文档 数据 问答 系统 代码

下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开

from llama_index import SimpleDirectoryReader, LangchainEmbedding, GPTListIndex,GPTSimpleVectorIndex, PromptHelper, LLMPredictor, ServiceContext
from langchain import OpenAI
import gradio as gr
import sys
import os
os.environ["OPENAI_API_KEY"] = 'key'
def construct_index(directory_path):
    # define LLM
# set maximum input size
    max_input_size = 4096
# set number of output tokens
    num_output = 256
# set maximum chunk overlap
    max_chunk_overlap = 20
    llm_predictor = LLMPredictor(llm=OpenAI(temperature=0.7, model_name="gpt-3.5-turbo", max_tokens=num_output))
    # define prompt helper

    prompt_helper = PromptHelper(max_input_size, num_output, max_chunk_overlap)

    service_context = ServiceContext.from_defaults(llm_predictor=llm_predictor, prompt_helper=prompt_helper)

    documents .........完整代码请登录后点击上方下载按钮下载查看

网友评论0