Skip to content
This repository has been archived by the owner on Nov 11, 2023. It is now read-only.

Feature/llm opt 200 #229

Merged
merged 2 commits into from
Jul 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 41 additions & 11 deletions Brain/src/rising_plugin/llm/llms.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,51 @@
MAX_AUTO_THINKING = 10

"""prompt"""
CATEGORY_PROMPT = """

EMAIL_PROMPT = """
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"}
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"}}
"""

IMAGE_PROMPT = """
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"}
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"}
"""


AUTO_TASK_PROMPT = """
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": ""}
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": ""}
If your answer is not correct with the program type which mentioned in this rules, please answer belowing json format. {"program": "autotask", "content": ""}
"""

NO_MATCH_PROMPT = """
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"}
"""

MOBILE_PROMPT = (
"""
If user said that send sms or text, please answer belowing json format. {"program": "sms", "content": "ask who"}
If user said that compose, write, or create an sms message, please answer belowing json format. {"program": "sms", "content": "ask who"}
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"}
If user said that launch a browser or open a browser, please answer belowing json format. {"program": "browser", "content": "https://google.com"}
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"}
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"}
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"}}
"""
+ EMAIL_PROMPT
+ IMAGE_PROMPT
+ AUTO_TASK_PROMPT
+ NO_MATCH_PROMPT
)


EXTENSION_PROMPT = (
"""
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"}
If user said that open a tab, go to a tab, or open a page, please answer belowing json format. {"program": "opentab", "content": ""}
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"}
If user said that close a tab, please answer belowing json format. {"program": "closetab", "content": ""}
If user said that launch a browser or open a browser, please answer belowing json format. {"program": "browser", "content": "https://google.com"}
If user said that go to a previous page, or open a previous page, please answer belowing json format. {"program": "previouspage", "content": ""}
If user said that go to a next page, or open a next page, please answer belowing json format. {"program": "nextpage", "content": ""}
If user said that scroll up, scroll up page, or page scroll up, please answer belowing json format. {"program": "scrollup", "content": ""}
Expand All @@ -42,17 +77,12 @@
If user said that scroll bottom, scroll bottom page, or scroll bottom of page, please answer belowing json format. {"program": "scrollbottom", "content": ""}
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"}
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": ""}
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"}
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"}
If users are going to ask something based on the data of website, please answer belowing json format. {"program": "askwebsite", "content": ""}
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"}}
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"}
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"}}
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": ""}
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"}
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": ""}
If your answer is not correct with the program type which mentioned in this rules, please answer belowing json format. {"program": "autotask", "content": ""}
"""
+ EMAIL_PROMPT
+ AUTO_TASK_PROMPT
+ NO_MATCH_PROMPT
)

"""validate model"""

Expand Down
13 changes: 11 additions & 2 deletions Brain/src/rising_plugin/risingplugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,14 @@

from .csv_embed import get_embed
from .llm.falcon_llm import FalconLLM
from .llm.llms import get_llm, GPT_4, FALCON_7B, get_llm_chain, CATEGORY_PROMPT
from .llm.llms import (
get_llm,
GPT_4,
FALCON_7B,
get_llm_chain,
MOBILE_PROMPT,
EXTENSION_PROMPT,
)
from .pinecone_engine import init_pinecone
from .rails_validate import validate_rails
from ..common.brain_exception import BrainException
Expand Down Expand Up @@ -351,7 +358,9 @@ def ask_question(
docs = []

if ACTION_FLAG:
docs.append(Document(page_content=CATEGORY_PROMPT, metadata=""))
# apply the proper prompt for each platform
prompt_template = EXTENSION_PROMPT if is_browser else MOBILE_PROMPT
docs.append(Document(page_content=prompt_template, metadata=""))
# temperature shouldbe 0.
chain_data = get_llm_chain(
model=DEFAULT_GPT_MODEL, setting=setting, temperature=0.0
Expand Down