JarvisLabs commited on
Commit
3ee0565
·
verified ·
1 Parent(s): 707a3f4

Update langchain_bot.py

Browse files
Files changed (1) hide show
  1. langchain_bot.py +34 -1
langchain_bot.py CHANGED
@@ -53,4 +53,37 @@ memory = ConversationBufferWindowMemory(
53
  output_key="answer", #output key 出力ののキー名
54
  k=8, #saved conversation number 保持する会話の履歴数
55
  return_messages=True, #get chat list チャット履歴をlistで取得する場合はTrue
56
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
53
  output_key="answer", #output key 出力ののキー名
54
  k=8, #saved conversation number 保持する会話の履歴数
55
  return_messages=True, #get chat list チャット履歴をlistで取得する場合はTrue
56
+ )
57
+
58
+
59
+ # RAG conversation chain (RAG用)会話chainの設定
60
+ chain = ConversationalRetrievalChain.from_llm(
61
+ llm=LLM,
62
+ retriever=retriever,
63
+ combine_docs_chain_kwargs={'prompt': QUESTION_PROMPT}, # プロンプトをセット
64
+ chain_type="stuff", # 検索した文章の処理方法
65
+ memory=memory # メモリーをセット
66
+ )
67
+
68
+ def invoke_question_time(chain,question):
69
+
70
+ start_time = time.time()
71
+ response = chain.invoke({"question": question})
72
+ end_time = time.time()
73
+ print(response["answer"])
74
+ print("responce time:", end_time - start_time, "seconds")
75
+ return response, end_time - start_time
76
+
77
+ #Test main
78
+ def main():
79
+
80
+ response,_=invoke_question_time(chain, "Hello what is precious plastic ? ")
81
+ time.sleep(30)
82
+ response,_=invoke_question_time(chain, """I live in the UK and want so start an extruder work shop.
83
+ What is needed ? What should safety issues might this have and where could i buy equipment could i buy in the UK to help me
84
+ """)
85
+ time.sleep(30)
86
+ response,_=invoke_question_time(chain, "Hello what is precious plastic ? ")
87
+
88
+ if __name__ ==" __main__":
89
+ main()