-
Notifications
You must be signed in to change notification settings - Fork 0
/
chat.py
64 lines (45 loc) · 1.4 KB
/
chat.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import random
import json
import openai
import torch
from IPython.display import Markdown
import config
import pinecone
import question
from IPython.display import Markdown
import os
from model import NeuralNet
from nltk_utils import bag_of_words, tokenize
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
with open('intents.json', 'r') as json_data:
intents = json.load(json_data)
FILE = "data.pth"
data = torch.load(FILE)
input_size = data["input_size"]
hidden_size = data["hidden_size"]
output_size = data["output_size"]
all_words = data['all_words']
tags = data['tags']
model_state = data["model_state"]
model = NeuralNet(input_size, hidden_size, output_size).to(device)
model.load_state_dict(model_state)
model.eval()
bot_name = "Sam"
# initialize openai API key
openai.api_key = os.environ["OPENAI_API_KEY"]
embed_model = config.embed_model
messages = [{"role": "system", "content": "You are a financial experts that specializes in real estate investment and negotiation"}]
def get_response(msg):
res = question.question(msg)
markdown_str = res.data
print(markdown_str)
return markdown_str
if __name__ == "__main__":
print("Let's chat! (type 'quit' to exit)")
while True:
# sentence = "do you use credit cards?"
sentence = input("You: ")
if sentence == "quit":
break
resp = get_response(sentence)
print(resp)