|
|
@ -24,7 +24,7 @@ def build(chunk_size=4000):
|
|
|
|
chunk_count = len(chunks)
|
|
|
|
chunk_count = len(chunks)
|
|
|
|
result = []
|
|
|
|
result = []
|
|
|
|
for idx, chunk in enumerate(chunks):
|
|
|
|
for idx, chunk in enumerate(chunks):
|
|
|
|
embedding = GPT.toolkit.embedding(chunk.encode(encoding='ASCII', errors='ignore').decode())
|
|
|
|
embedding = GPT.gpt_tools.embedding(chunk.encode(encoding='ASCII', errors='ignore').decode())
|
|
|
|
info = {'content': chunk, 'vector': embedding}
|
|
|
|
info = {'content': chunk, 'vector': embedding}
|
|
|
|
print(info, '\n\n\n')
|
|
|
|
print(info, '\n\n\n')
|
|
|
|
|
|
|
|
|
|
|
@ -38,7 +38,7 @@ def build(chunk_size=4000):
|
|
|
|
def run(query, model, prompt_file, isQuestion, params, info_file=None):
|
|
|
|
def run(query, model, prompt_file, isQuestion, params, info_file=None):
|
|
|
|
if isQuestion:
|
|
|
|
if isQuestion:
|
|
|
|
data = util.read_json(INFO.BRAIN_DATA)
|
|
|
|
data = util.read_json(INFO.BRAIN_DATA)
|
|
|
|
results = GPT.toolkit.search_chunks(query, data, params.chunk_count)
|
|
|
|
results = GPT.gpt_tools.search_chunks(query, data, params.chunk_count)
|
|
|
|
answers = []
|
|
|
|
answers = []
|
|
|
|
for result in results:
|
|
|
|
for result in results:
|
|
|
|
my_info = util.read_file(info_file)
|
|
|
|
my_info = util.read_file(info_file)
|
|
|
@ -47,7 +47,7 @@ def run(query, model, prompt_file, isQuestion, params, info_file=None):
|
|
|
|
prompt = prompt.replace('<<QS>>', query)
|
|
|
|
prompt = prompt.replace('<<QS>>', query)
|
|
|
|
prompt = prompt.replace('<<MY-INFO>>', my_info)
|
|
|
|
prompt = prompt.replace('<<MY-INFO>>', my_info)
|
|
|
|
|
|
|
|
|
|
|
|
answer = GPT.toolkit.gpt3(prompt, model, params)
|
|
|
|
answer = GPT.gpt_tools.gpt3(prompt, model, params)
|
|
|
|
answers.append(answer)
|
|
|
|
answers.append(answer)
|
|
|
|
all_response = '\n\n'.join(answers)
|
|
|
|
all_response = '\n\n'.join(answers)
|
|
|
|
else:
|
|
|
|
else:
|
|
|
@ -55,7 +55,7 @@ def run(query, model, prompt_file, isQuestion, params, info_file=None):
|
|
|
|
responses = []
|
|
|
|
responses = []
|
|
|
|
for chunk in chunks:
|
|
|
|
for chunk in chunks:
|
|
|
|
prompt = util.read_file(prompt_file).replace('<<DATA>>', chunk)
|
|
|
|
prompt = util.read_file(prompt_file).replace('<<DATA>>', chunk)
|
|
|
|
response = GPT.toolkit.gpt3(prompt, model, params)
|
|
|
|
response = GPT.gpt_tools.gpt3(prompt, model, params)
|
|
|
|
responses.append(response)
|
|
|
|
responses.append(response)
|
|
|
|
all_response = '\n\n'.join(responses)
|
|
|
|
all_response = '\n\n'.join(responses)
|
|
|
|
return all_response
|
|
|
|
return all_response
|
|
|
@ -65,7 +65,7 @@ def get_stream_prompt(query, prompt_file, isQuestion, info_file=None):
|
|
|
|
openai.api_key = API_KEY
|
|
|
|
openai.api_key = API_KEY
|
|
|
|
if isQuestion:
|
|
|
|
if isQuestion:
|
|
|
|
data = util.read_json(INFO.BRAIN_DATA)
|
|
|
|
data = util.read_json(INFO.BRAIN_DATA)
|
|
|
|
result = GPT.toolkit.search_chunks(query, data, count=1)
|
|
|
|
result = GPT.gpt_tools.search_chunks(query, data, count=1)
|
|
|
|
my_info = util.read_file(info_file)
|
|
|
|
my_info = util.read_file(info_file)
|
|
|
|
prompt = util.read_file(prompt_file)
|
|
|
|
prompt = util.read_file(prompt_file)
|
|
|
|
prompt = prompt.replace('<<INFO>>', result[0]['content'])
|
|
|
|
prompt = prompt.replace('<<INFO>>', result[0]['content'])
|
|
|
@ -79,5 +79,5 @@ def get_stream_prompt(query, prompt_file, isQuestion, info_file=None):
|
|
|
|
|
|
|
|
|
|
|
|
def run_stream(query, model, prompt_file, isQuestion, params, info_file=None):
|
|
|
|
def run_stream(query, model, prompt_file, isQuestion, params, info_file=None):
|
|
|
|
prompt = get_stream_prompt(query, prompt_file, isQuestion, info_file)
|
|
|
|
prompt = get_stream_prompt(query, prompt_file, isQuestion, info_file)
|
|
|
|
client = GPT.toolkit.gpt3_stream(API_KEY, prompt, model, params)
|
|
|
|
client = GPT.gpt_tools.gpt3_stream(API_KEY, prompt, model, params)
|
|
|
|
return client
|
|
|
|
return client
|
|
|
|