-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSample.py
42 lines (34 loc) · 1.15 KB
/
Sample.py
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
def runPrompt():
index = faiss.read_index("training.index")
with open("faiss.pkl", "rb") as f:
store = pickle.load(f)
store.index = index
#TODO: Add your Master Prompt
with open("training/facts/master.txt", "r") as f:
promptTemplate = """*write the splunk SPL Query*
---
ConversationHistory: {history}
---
MemoryContext: {context}
---
Human: {question}
Bot:"""
prompt = Prompt(template=promptTemplate,
input_variables=["history", "context", "question"])
llmChain = LLMChain(prompt=prompt, llm=OpenAI(temperature=0.25))
def onMessage(question, history):
docs = store.similarity_search(question)
contexts = []
for i, doc in enumerate(docs):
contexts.append(f"Context {i}:\n{doc.page_content}")
answer = llmChain.predict(question=question,
context="\n\n".join(contexts),
history=history)
return answer
history = []
while True:
question = input("Ask a question > ")
answer = onMessage(question, history)
print(f"InSplunkGPT: {answer}")
history.append(f"SOC Analyst: {question}")
history.append(f"InSplunkGPT: {answer}")