Thomas Richardson commited on
Commit
4e573d8
·
unverified ·
2 Parent(s): 7b3e5b845c8251

Merge pull request #229 from ttt246/feature/llm_opt_200

Browse files
Brain/src/rising_plugin/llm/llms.py CHANGED
@@ -24,16 +24,51 @@ EXCEPTION_MSG = f"The model is not correct. It should be in {LLM_MODELS}"
24
  MAX_AUTO_THINKING = 10
25
 
26
  """prompt"""
27
- CATEGORY_PROMPT = """
 
 
 
 
 
 
28
  If user is going to say about a image with its description to search, please answer belowing json format. {"program": "image", "content": "description of the image that user is going to search"}
29
  If user is going to ask about a image, please answer belowing json format. {"program": "image", "content": "description of the image that user is going to search"}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30
  If user said that send sms or text, please answer belowing json format. {"program": "sms", "content": "ask who"}
31
  If user said that compose, write, or create an sms message, please answer belowing json format. {"program": "sms", "content": "ask who"}
32
  If user said that search contact with its description such as display name or phone number, please answer belowing json format. {"program": "contact", "content": "description of the contact that user is going to search"}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
33
  If user said that open a tab, go to a tab, or open a page, please answer belowing json format. {"program": "opentab", "content": ""}
34
  If user said that open a tab and search, go to a tab and search, or open a page and search, please answer belowing json format. {"program": "opentabsearch", "content": "keyword that user is going to search"}
35
  If user said that close a tab, please answer belowing json format. {"program": "closetab", "content": ""}
36
- If user said that launch a browser or open a browser, please answer belowing json format. {"program": "browser", "content": "https://google.com"}
37
  If user said that go to a previous page, or open a previous page, please answer belowing json format. {"program": "previouspage", "content": ""}
38
  If user said that go to a next page, or open a next page, please answer belowing json format. {"program": "nextpage", "content": ""}
39
  If user said that scroll up, scroll up page, or page scroll up, please answer belowing json format. {"program": "scrollup", "content": ""}
@@ -42,17 +77,12 @@ If user said that scroll top, scroll top page, or scroll top of page, please ans
42
  If user said that scroll bottom, scroll bottom page, or scroll bottom of page, please answer belowing json format. {"program": "scrollbottom", "content": ""}
43
  If user is going to select an item, an article or a website with its description in a web browser, please answer belowing json format. {"program": "selectitemdetailinfo", "content": "the description of an item, an article or a website in a browser"}
44
  If user said that ask about the content in website, for example, if users ask something like 'what is #query in this website?' or 'Can you tell me about #query based on this website?', please answer belowing json format. {"program": "askwebsite", "content": ""}
45
- If user said that open a website using web browsers, please answer belowing json format. The url user is going to open can exist or not. If user doesn\\'t say exact url and want to open some sites, you have to find the best proper url. If user didn\\'t say any url and you can't find proper url, please set website url to "https://www.google.com". {"program": "browser", "url": "website url that user is going to open"}
46
- If user said that open a browser such as chrome, firefox or safari and search something, please answer belowing json format. The url user is going to open can exist or not. If user doesn\\'t say exact url and want to open some sites, you have to find the best proper url. If user didn\\'t say any url and you can't find proper url, please set website url to "https://www.google.com". {"program": "browser", "url": "website url that user is going to open"}
47
  If users are going to ask something based on the data of website, please answer belowing json format. {"program": "askwebsite", "content": ""}
48
- If user is going to set or create alarm with time and label, please answer belowing json format.\n {"program": "alarm", "content": {"type":"create", "time":"please set time as 24-hours format that user is going to set. If user did not provide any alarm time, set "0:0"", "label":"please set label that user is going to set. If user did not provide any label, set "alarm""}}\n This is example data.\n User: Set an alarm.\n AI: {"program":"alarm", "content": {"type":"create", "time":"0:0", "label":"alarm"}}\n User: Set an alarm with label as "wake up".\n AI: {"program":"alarm", "content": {"type":"create", "time":"0:0", "label":"wake up"}}\n User: Set an alarm for 5:00 AM.\n AI: {"program":"alarm", "content": {"type":"create", "time":"5:00", "label":"alarm"}}\n User: Set an alarm for 5:00 PM with label as "wake up".\n AI: {"program":"alarm", "content": {"type":"create", "time":"17:00", "label":"wake up"}}
49
- If user is going to read emails, please answer belowing json format. {"program": "reademails", "content": "if user is going to read email in inbox, set to inbox, if not, set to draft. if user did not provide where to read email, set to inbox"}
50
- If user is going to send email to other user, or save email to draft folder, please answer belowing json format. {"program": "sendemail", "content": {"type": "if user is going to send email to other user, set to true, if not, set to false. if user did not provide where to send email, set to true", "title": "make the proper title for email content", "body": "email content that user is going to send"}}
51
- User wants to help organization in achieving its goals, which bridges the gap between the user is (present) and where he/she wants to go (future), or that is deciding in advance what to do, how to do when to do it and by whom it is to be done. Also the description ensures in thoughts and actions, work is carried on smoothly without any confusion and misunderstanding. \n And it can be done for the future and the future is full of uncertainties. \n So it looks like to make a decision as well. It helps make rational decisions by choosing the best most profitable alternative which may bring lower cost, adaptable to the organization and situations. \n If user is going to say about planning strategy, or something like that , please answer belowing json format. {"program": "autotask", "content": ""}
52
- If all of above is not correct, please give the most appropriate answer to the user's question. Please answer belowing json format. {"program":"message", "content":"your answer"}
53
- If users are going to know about real-time capabilities such as News, Weather, Stocks, Booking, Planning, or etc, then please answer belowing json format. {"program": "autotask", "content": ""}
54
- If your answer is not correct with the program type which mentioned in this rules, please answer belowing json format. {"program": "autotask", "content": ""}
55
  """
 
 
 
 
56
 
57
  """validate model"""
58
 
 
24
  MAX_AUTO_THINKING = 10
25
 
26
  """prompt"""
27
+
28
+ EMAIL_PROMPT = """
29
+ If user is going to read emails, please answer belowing json format. {"program": "reademails", "content": "if user is going to read email in inbox, set to inbox, if not, set to draft. if user did not provide where to read email, set to inbox"}
30
+ If user is going to send email to other user, or save email to draft folder, please answer belowing json format. {"program": "sendemail", "content": {"type": "if user is going to send email to other user, set to true, if not, set to false. if user did not provide where to send email, set to true", "title": "make the proper title for email content", "body": "email content that user is going to send"}}
31
+ """
32
+
33
+ IMAGE_PROMPT = """
34
  If user is going to say about a image with its description to search, please answer belowing json format. {"program": "image", "content": "description of the image that user is going to search"}
35
  If user is going to ask about a image, please answer belowing json format. {"program": "image", "content": "description of the image that user is going to search"}
36
+ """
37
+
38
+
39
+ AUTO_TASK_PROMPT = """
40
+ User wants to help organization in achieving its goals, which bridges the gap between the user is (present) and where he/she wants to go (future), or that is deciding in advance what to do, how to do when to do it and by whom it is to be done. Also the description ensures in thoughts and actions, work is carried on smoothly without any confusion and misunderstanding. \n And it can be done for the future and the future is full of uncertainties. \n So it looks like to make a decision as well. It helps make rational decisions by choosing the best most profitable alternative which may bring lower cost, adaptable to the organization and situations. \n If user is going to say about planning strategy, or something like that , please answer belowing json format. {"program": "autotask", "content": ""}
41
+ If users are going to know about real-time capabilities such as News, Weather, Stocks, Booking, Planning, or etc, then please answer belowing json format. {"program": "autotask", "content": ""}
42
+ If your answer is not correct with the program type which mentioned in this rules, please answer belowing json format. {"program": "autotask", "content": ""}
43
+ """
44
+
45
+ NO_MATCH_PROMPT = """
46
+ If all of above is not correct, please give the most appropriate answer to the user's question. Please answer belowing json format. {"program":"message", "content":"your answer"}
47
+ """
48
+
49
+ MOBILE_PROMPT = (
50
+ """
51
  If user said that send sms or text, please answer belowing json format. {"program": "sms", "content": "ask who"}
52
  If user said that compose, write, or create an sms message, please answer belowing json format. {"program": "sms", "content": "ask who"}
53
  If user said that search contact with its description such as display name or phone number, please answer belowing json format. {"program": "contact", "content": "description of the contact that user is going to search"}
54
+ If user said that launch a browser or open a browser, please answer belowing json format. {"program": "browser", "content": "https://google.com"}
55
+ If user said that open a website using web browsers, please answer belowing json format. The url user is going to open can exist or not. If user doesn\\'t say exact url and want to open some sites, you have to find the best proper url. If user didn\\'t say any url and you can't find proper url, please set website url to "https://www.google.com". {"program": "browser", "url": "website url that user is going to open"}
56
+ If user said that open a browser such as chrome, firefox or safari and search something, please answer belowing json format. The url user is going to open can exist or not. If user doesn\\'t say exact url and want to open some sites, you have to find the best proper url. If user didn\\'t say any url and you can't find proper url, please set website url to "https://www.google.com". {"program": "browser", "url": "website url that user is going to open"}
57
+ If user is going to set or create alarm with time and label, please answer belowing json format.\n {"program": "alarm", "content": {"type":"create", "time":"please set time as 24-hours format that user is going to set. If user did not provide any alarm time, set "0:0"", "label":"please set label that user is going to set. If user did not provide any label, set "alarm""}}\n This is example data.\n User: Set an alarm.\n AI: {"program":"alarm", "content": {"type":"create", "time":"0:0", "label":"alarm"}}\n User: Set an alarm with label as "wake up".\n AI: {"program":"alarm", "content": {"type":"create", "time":"0:0", "label":"wake up"}}\n User: Set an alarm for 5:00 AM.\n AI: {"program":"alarm", "content": {"type":"create", "time":"5:00", "label":"alarm"}}\n User: Set an alarm for 5:00 PM with label as "wake up".\n AI: {"program":"alarm", "content": {"type":"create", "time":"17:00", "label":"wake up"}}
58
+ """
59
+ + EMAIL_PROMPT
60
+ + IMAGE_PROMPT
61
+ + AUTO_TASK_PROMPT
62
+ + NO_MATCH_PROMPT
63
+ )
64
+
65
+
66
+ EXTENSION_PROMPT = (
67
+ """
68
+ If user said that search contact with its description such as display name or phone number, please answer belowing json format. {"program": "contact", "content": "description of the contact that user is going to search"}
69
  If user said that open a tab, go to a tab, or open a page, please answer belowing json format. {"program": "opentab", "content": ""}
70
  If user said that open a tab and search, go to a tab and search, or open a page and search, please answer belowing json format. {"program": "opentabsearch", "content": "keyword that user is going to search"}
71
  If user said that close a tab, please answer belowing json format. {"program": "closetab", "content": ""}
 
72
  If user said that go to a previous page, or open a previous page, please answer belowing json format. {"program": "previouspage", "content": ""}
73
  If user said that go to a next page, or open a next page, please answer belowing json format. {"program": "nextpage", "content": ""}
74
  If user said that scroll up, scroll up page, or page scroll up, please answer belowing json format. {"program": "scrollup", "content": ""}
 
77
  If user said that scroll bottom, scroll bottom page, or scroll bottom of page, please answer belowing json format. {"program": "scrollbottom", "content": ""}
78
  If user is going to select an item, an article or a website with its description in a web browser, please answer belowing json format. {"program": "selectitemdetailinfo", "content": "the description of an item, an article or a website in a browser"}
79
  If user said that ask about the content in website, for example, if users ask something like 'what is #query in this website?' or 'Can you tell me about #query based on this website?', please answer belowing json format. {"program": "askwebsite", "content": ""}
 
 
80
  If users are going to ask something based on the data of website, please answer belowing json format. {"program": "askwebsite", "content": ""}
 
 
 
 
 
 
 
81
  """
82
+ + EMAIL_PROMPT
83
+ + AUTO_TASK_PROMPT
84
+ + NO_MATCH_PROMPT
85
+ )
86
 
87
  """validate model"""
88
 
Brain/src/rising_plugin/risingplugin.py CHANGED
@@ -19,7 +19,14 @@ from firebase_admin import storage
19
 
20
  from .csv_embed import get_embed
21
  from .llm.falcon_llm import FalconLLM
22
- from .llm.llms import get_llm, GPT_4, FALCON_7B, get_llm_chain, CATEGORY_PROMPT
 
 
 
 
 
 
 
23
  from .pinecone_engine import init_pinecone
24
  from .rails_validate import validate_rails
25
  from ..common.brain_exception import BrainException
@@ -351,7 +358,9 @@ def ask_question(
351
  docs = []
352
 
353
  if ACTION_FLAG:
354
- docs.append(Document(page_content=CATEGORY_PROMPT, metadata=""))
 
 
355
  # temperature shouldbe 0.
356
  chain_data = get_llm_chain(
357
  model=DEFAULT_GPT_MODEL, setting=setting, temperature=0.0
 
19
 
20
  from .csv_embed import get_embed
21
  from .llm.falcon_llm import FalconLLM
22
+ from .llm.llms import (
23
+ get_llm,
24
+ GPT_4,
25
+ FALCON_7B,
26
+ get_llm_chain,
27
+ MOBILE_PROMPT,
28
+ EXTENSION_PROMPT,
29
+ )
30
  from .pinecone_engine import init_pinecone
31
  from .rails_validate import validate_rails
32
  from ..common.brain_exception import BrainException
 
358
  docs = []
359
 
360
  if ACTION_FLAG:
361
+ # apply the proper prompt for each platform
362
+ prompt_template = EXTENSION_PROMPT if is_browser else MOBILE_PROMPT
363
+ docs.append(Document(page_content=prompt_template, metadata=""))
364
  # temperature shouldbe 0.
365
  chain_data = get_llm_chain(
366
  model=DEFAULT_GPT_MODEL, setting=setting, temperature=0.0