Spaces:
Sleeping
Sleeping
mohsenfayyaz
commited on
Commit
•
58775bb
1
Parent(s):
a9d7973
Update app.py
Browse files
app.py
CHANGED
@@ -45,6 +45,18 @@ DIVAR_CONTEXT = """
|
|
45 |
برای کسبوکار : خرید و فروش تجهیزات و ماشینآلات، عمدهفروشی و ...
|
46 |
استخدام و کاریابی : اداری و مدیریتی، سرایداری، عمران و ساختمانی، رایانه و فناوری اطلاعات، مالی و حسابداری و ...
|
47 |
شما باید کوتاه و بسیار دوستانه پاسخ دهید.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
48 |
"""
|
49 |
|
50 |
base_context = [ {'role':'system', 'content': DIVAR_CONTEXT} ] # accumulate messages
|
@@ -56,23 +68,27 @@ def respond(message, chat_history, api_key, context_box):
|
|
56 |
openai.api_key = api_key
|
57 |
save = api_key
|
58 |
bot_message, context = collect_messages(message, context)
|
59 |
-
|
|
|
|
|
60 |
|
61 |
-
messages = context.copy()
|
62 |
-
messages.append(
|
63 |
-
|
64 |
-
)
|
65 |
-
response = get_completion_from_messages(messages, temperature=0)
|
66 |
-
query =
|
67 |
h = f"<iframe src='https://www.google.com/search?igu=1&q=site:divar.ir+{query}' width='100%' height='400' title='description'></iframe>"
|
68 |
except Exception as e:
|
69 |
-
h,
|
70 |
-
return "", chat_history, h,
|
71 |
|
72 |
def clear_fn():
|
73 |
return None, base_context.copy()
|
74 |
|
75 |
-
with gr.Blocks() as demo:
|
|
|
|
|
76 |
with gr.Row():
|
77 |
with gr.Column(scale=1):
|
78 |
html = gr.HTML("Results Will be shown here!")
|
@@ -86,5 +102,4 @@ with gr.Blocks() as demo:
|
|
86 |
msg.submit(respond, [msg, chatbot, api_key_box, context_box], [msg, chatbot, html, htmlj, context_box])
|
87 |
clear.click(clear_fn, None, [chatbot, context_box], queue=False)
|
88 |
|
89 |
-
|
90 |
demo.launch()
|
|
|
45 |
برای کسبوکار : خرید و فروش تجهیزات و ماشینآلات، عمدهفروشی و ...
|
46 |
استخدام و کاریابی : اداری و مدیریتی، سرایداری، عمران و ساختمانی، رایانه و فناوری اطلاعات، مالی و حسابداری و ...
|
47 |
شما باید کوتاه و بسیار دوستانه پاسخ دهید.
|
48 |
+
|
49 |
+
Each answer from the bot must have two parts separated by "---". The first part is the response to the user. The second part is a json.
|
50 |
+
In the second part create a short json based on the previous conversation (Make sure to only output the json and nothing more). The fields should be 1) search_query (make it a list of possible queries which can find the best items for the user in Divar website in Farsi. If there are none put an empty string in the list.) 2) price_range with min and max number In Tomans 3) possible_filters (keys must be in english)
|
51 |
+
The results of this query will be shown to the user next to the chat by the website.
|
52 |
+
As you do not have the recent information such as prices, you can refer the user for such information to the results of the query that are shown on the left side of their chat.
|
53 |
+
|
54 |
+
Example:
|
55 |
+
سلام من ربات دستیار دیوار هستم.
|
56 |
+
---
|
57 |
+
{"search_query": ["131 پراید نو"], "price_range": [0, 100000], "possible_filters": {"brand": "پراید", "model": "131"}}
|
58 |
+
|
59 |
+
Make sure that every response has these two parts separated by "---" and the json is a valid json.
|
60 |
"""
|
61 |
|
62 |
base_context = [ {'role':'system', 'content': DIVAR_CONTEXT} ] # accumulate messages
|
|
|
68 |
openai.api_key = api_key
|
69 |
save = api_key
|
70 |
bot_message, context = collect_messages(message, context)
|
71 |
+
user_response = bot_message.split("---")[0]
|
72 |
+
query_response = bot_message.split("---")[1]
|
73 |
+
chat_history.append((message, user_response))
|
74 |
|
75 |
+
# messages = context.copy()
|
76 |
+
# messages.append(
|
77 |
+
# {'role':'system', 'content':'create a short json based on the previous conversation (Make sure to only output the json and nothing more). The fields should be 1) search_query (make it a list of possible queries which can find the best items for the user in Divar website) 2) price_range with min and max number In Tomans 3) possible_filters (keys must be in english)' },
|
78 |
+
# )
|
79 |
+
# response = get_completion_from_messages(messages, temperature=0)
|
80 |
+
query = ast.literal_eval(query_response)["search_query"][0]
|
81 |
h = f"<iframe src='https://www.google.com/search?igu=1&q=site:divar.ir+{query}' width='100%' height='400' title='description'></iframe>"
|
82 |
except Exception as e:
|
83 |
+
h, query_response = bot_message, str(e)
|
84 |
+
return "", chat_history, h, query_response, context
|
85 |
|
86 |
def clear_fn():
|
87 |
return None, base_context.copy()
|
88 |
|
89 |
+
with gr.Blocks(title="DivarGPT") as demo:
|
90 |
+
with gr.Row():
|
91 |
+
gr.HTML('<h2 style="text-align: center; margin-bottom: 1rem">DivarGPT v0.2</h1>')
|
92 |
with gr.Row():
|
93 |
with gr.Column(scale=1):
|
94 |
html = gr.HTML("Results Will be shown here!")
|
|
|
102 |
msg.submit(respond, [msg, chatbot, api_key_box, context_box], [msg, chatbot, html, htmlj, context_box])
|
103 |
clear.click(clear_fn, None, [chatbot, context_box], queue=False)
|
104 |
|
|
|
105 |
demo.launch()
|