thomas commited on
Commit ·
49d14d9
1
Parent(s): 4b17d8c
feature(#32): fixed selection_item function to get only its link from the list with the format. And adjustify its temperature.
Browse files- src/common/assembler.py +10 -0
- src/common/program_type.py +23 -0
- src/rising_plugin/risingplugin.py +2 -3
- src/router/browser_router.py +7 -1
- src/service/browser_service.py +3 -1
src/common/assembler.py
CHANGED
|
@@ -48,3 +48,13 @@ class Assembler:
|
|
| 48 |
contact_model = ContactModel()
|
| 49 |
contact_model.get_contact_model(data)
|
| 50 |
return contact_model
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
contact_model = ContactModel()
|
| 49 |
contact_model.get_contact_model(data)
|
| 50 |
return contact_model
|
| 51 |
+
|
| 52 |
+
"""mapping result type into json
|
| 53 |
+
{
|
| 54 |
+
"program": sms | contacts | browser | select_item_detail_info,
|
| 55 |
+
"content": string
|
| 56 |
+
}
|
| 57 |
+
"""
|
| 58 |
+
|
| 59 |
+
def to_result_format(self, program: str, content: str) -> Any:
|
| 60 |
+
return {"program": program, "content": content}
|
src/common/program_type.py
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Program Type for all commands to categorize"""
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
class ProgramType:
|
| 5 |
+
BROWSER = "browser"
|
| 6 |
+
ALERT = "alert"
|
| 7 |
+
IMAGE = "image"
|
| 8 |
+
SMS = "sms"
|
| 9 |
+
CONTACT = "contact"
|
| 10 |
+
MESSAGE = "message"
|
| 11 |
+
|
| 12 |
+
class BrowserType:
|
| 13 |
+
OPEN_TAB = "open_tab"
|
| 14 |
+
OPEN_TAB_SEARCH = "open_tab_search"
|
| 15 |
+
CLOSE_TAB = "close_tab"
|
| 16 |
+
PREVIOUS_PAGE = "previous_page"
|
| 17 |
+
NEXT_PAGE = "next_page"
|
| 18 |
+
SCROLL_UP = "scroll_up"
|
| 19 |
+
SCROLL_DOWN = "scroll_down"
|
| 20 |
+
SCROLL_TOP = "scroll_top"
|
| 21 |
+
SCROLL_BOTTOM = "scroll_bottom"
|
| 22 |
+
SELECT_ITEM_DETAIL_INFO = "select_item_detail_info"
|
| 23 |
+
SELECT_ITEM = "select_item"
|
src/rising_plugin/risingplugin.py
CHANGED
|
@@ -126,10 +126,9 @@ def getCompletionOnly(
|
|
| 126 |
query: str,
|
| 127 |
model: str = "gpt-4",
|
| 128 |
) -> str:
|
| 129 |
-
llm = ChatOpenAI(model_name=model, temperature=
|
| 130 |
chain = load_qa_chain(llm, chain_type="stuff")
|
| 131 |
-
|
| 132 |
-
chain_data = chain.run(input_documents=[], question=test_question)
|
| 133 |
return chain_data
|
| 134 |
|
| 135 |
|
|
|
|
| 126 |
query: str,
|
| 127 |
model: str = "gpt-4",
|
| 128 |
) -> str:
|
| 129 |
+
llm = ChatOpenAI(model_name=model, temperature=0.5, openai_api_key=OPENAI_API_KEY)
|
| 130 |
chain = load_qa_chain(llm, chain_type="stuff")
|
| 131 |
+
chain_data = chain.run(input_documents=[], question=query)
|
|
|
|
| 132 |
return chain_data
|
| 133 |
|
| 134 |
|
src/router/browser_router.py
CHANGED
|
@@ -1,6 +1,7 @@
|
|
| 1 |
from fastapi import APIRouter, Request, Depends
|
| 2 |
|
| 3 |
from src.common.assembler import Assembler
|
|
|
|
| 4 |
from src.common.utils import parseUrlFromStr
|
| 5 |
from src.model.requests.request_model import BrowserItem
|
| 6 |
from src.service.browser_service import BrowserService
|
|
@@ -38,7 +39,12 @@ def construct_blueprint_browser_api() -> APIRouter:
|
|
| 38 |
except Exception as e:
|
| 39 |
return assembler.to_response(400, "Failed to get item in a browser", "")
|
| 40 |
return assembler.to_response(
|
| 41 |
-
200,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
)
|
| 43 |
|
| 44 |
return router
|
|
|
|
| 1 |
from fastapi import APIRouter, Request, Depends
|
| 2 |
|
| 3 |
from src.common.assembler import Assembler
|
| 4 |
+
from src.common.program_type import ProgramType
|
| 5 |
from src.common.utils import parseUrlFromStr
|
| 6 |
from src.model.requests.request_model import BrowserItem
|
| 7 |
from src.service.browser_service import BrowserService
|
|
|
|
| 39 |
except Exception as e:
|
| 40 |
return assembler.to_response(400, "Failed to get item in a browser", "")
|
| 41 |
return assembler.to_response(
|
| 42 |
+
200,
|
| 43 |
+
"Getting an item in a browser successfully",
|
| 44 |
+
assembler.to_result_format(
|
| 45 |
+
ProgramType.BrowserType.SELECT_ITEM,
|
| 46 |
+
parseUrlFromStr(item_link),
|
| 47 |
+
),
|
| 48 |
)
|
| 49 |
|
| 50 |
return router
|
src/service/browser_service.py
CHANGED
|
@@ -7,5 +7,7 @@ class BrowserService:
|
|
| 7 |
"""query to get the link of the item from the list"""
|
| 8 |
|
| 9 |
def query_item(self, items: list[BrowserItem.ItemReq], query: str) -> str:
|
| 10 |
-
prompt_template = f"
|
|
|
|
|
|
|
| 11 |
return getCompletionOnly(query=prompt_template)
|
|
|
|
| 7 |
"""query to get the link of the item from the list"""
|
| 8 |
|
| 9 |
def query_item(self, items: list[BrowserItem.ItemReq], query: str) -> str:
|
| 10 |
+
prompt_template = f"""
|
| 11 |
+
User is trying to '{query}' and it includes the title of the item.
|
| 12 |
+
Please return the link of best relatedness of the item with the title from the below data.\n {items}"""
|
| 13 |
return getCompletionOnly(query=prompt_template)
|