-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfile_question_chain.py
More file actions
43 lines (35 loc) · 1.15 KB
/
file_question_chain.py
File metadata and controls
43 lines (35 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import _env
import openai
openai.log="debug"
from langchain.llms import OpenAI
from tools import file_search_tool
import sys
from termcolor import colored
from langchain.embeddings import OpenAIEmbeddings
if __name__ == '__main__':
if len(sys.argv)!=3:
print("param error:"+" , ".join(sys.argv))
print(sys.argv[0]+" {question} {file}")
quit()
question=sys.argv[1]
filename=sys.argv[2]
print(sys.argv)
llm = OpenAI(model_name=_env.model_name, temperature=0.0,openai_api_key=_env.api_key)
embeddings = OpenAIEmbeddings(openai_api_key=_env.api_key)
tool = file_search_tool.CustomFileSearchTool(
name = "File",
#description = "you must use it first, when you need to answer questions about product after sale",
description = "Any question must first use this tool, using the original question as Action Input",
llm=llm,
embeddings=embeddings,
)
tool.load_from_file(filename)
result=tool._run(question)
print()
print()
print()
print("Result:")
print(colored(result, "green"))
print()
print()
print()