Ryan Sandagon commited on
Commit
db581b1
·
1 Parent(s): 547ac4d

added recall to chat

Browse files
Files changed (1) hide show
  1. app.py +7 -14
app.py CHANGED
@@ -5,17 +5,18 @@ import requests
5
  API_URL = "https://api-inference.huggingface.co/models/EleutherAI/gpt-j-6B"
6
  headers = {"Authorization": "Bearer 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"}
7
  prompt = """
8
- me: I'm Twimbly Twombly. I leave in California.
 
 
9
  you: Hello. How are you?
10
- me: I'm fine
11
- you: """
12
 
13
  examples = [["how are you?"], ["hello"]]
14
 
15
 
16
  def chat_generate(word):
17
  # print(f"**current reply")
18
- p = prompt + word.lower() + "\n" + "me: "
19
  print(f"*****Inside chat_generate - Prompt is :{p}")
20
  json_ = {"inputs": p,
21
  "parameters":
@@ -28,17 +29,9 @@ def chat_generate(word):
28
  response = requests.post(API_URL, headers=headers, json=json_)
29
  output = response.json()
30
  output_tmp = output[0]['generated_text']
31
- print(f"GPTJ response without splits is: {output_tmp}")
32
- if "\n\n" not in output_tmp:
33
- if output_tmp.find('.') != -1:
34
- idx = output_tmp.find('.')
35
- reply = output_tmp[:idx+1]
36
- else:
37
- idx = output_tmp.rfind('\n')
38
- reply = output_tmp[:idx]
39
- else:
40
- reply = output_tmp.split("\n\n")[0] # +"."
41
  print(f"Chat Response being returned is: {reply}")
 
42
  return reply
43
 
44
  def text_to_image(reply):
 
5
  API_URL = "https://api-inference.huggingface.co/models/EleutherAI/gpt-j-6B"
6
  headers = {"Authorization": "Bearer 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"}
7
  prompt = """
8
+ me: I'm Twimbly Twombly. I live in California. I'm a robot."""
9
+
10
+ prev_chat = """
11
  you: Hello. How are you?
12
+ me: I'm fine"""
 
13
 
14
  examples = [["how are you?"], ["hello"]]
15
 
16
 
17
  def chat_generate(word):
18
  # print(f"**current reply")
19
+ p = prompt + prev_chat + "\n" + "you: " + word.lower() + "\n" + "me: "
20
  print(f"*****Inside chat_generate - Prompt is :{p}")
21
  json_ = {"inputs": p,
22
  "parameters":
 
29
  response = requests.post(API_URL, headers=headers, json=json_)
30
  output = response.json()
31
  output_tmp = output[0]['generated_text']
32
+ reply = output_tmp.split("you:")[0] # +"."
 
 
 
 
 
 
 
 
 
33
  print(f"Chat Response being returned is: {reply}")
34
+ prev_chat = "you: " + word.lower() + "\n" + "me: " + reply
35
  return reply
36
 
37
  def text_to_image(reply):