app.py
CHANGED
@@ -7,48 +7,9 @@ import json
|
|
7 |
from dotenv import load_dotenv, find_dotenv
|
8 |
_ = load_dotenv(find_dotenv())
|
9 |
|
10 |
-
|
11 |
databricks_token = os.getenv('TENATCH_TOKEN')
|
12 |
model_uri = "http://15.152.197.215/v1/completions"
|
13 |
-
|
14 |
-
def extract_json(gen_text, n_shot_learning=0):
|
15 |
-
if(n_shot_learning == -1) :
|
16 |
-
start_index = 0
|
17 |
-
else :
|
18 |
-
start_index = gen_text.index("### Response:\n{") + 14
|
19 |
-
if(n_shot_learning > 0) :
|
20 |
-
for i in range(0, n_shot_learning):
|
21 |
-
gen_text = gen_text[start_index:]
|
22 |
-
start_index = gen_text.index("### Response:\n{") + 14
|
23 |
-
end_index = gen_text.find("}\n\n### ") + 1
|
24 |
-
return gen_text[start_index:end_index]
|
25 |
-
|
26 |
-
def score_model(model_uri, databricks_token, prompt):
|
27 |
-
ds_dict={
|
28 |
-
"model": "debisoft/mpt-7b-awq-tester",
|
29 |
-
"prompt": prompt,
|
30 |
-
"temperature": 0.5,
|
31 |
-
"max_tokens": 1000}
|
32 |
-
headers = {
|
33 |
-
"Authorization": f"Bearer {databricks_token}",
|
34 |
-
"Content-Type": "application/json",
|
35 |
-
}
|
36 |
-
#ds_dict = {'dataframe_split': dataset.to_dict(orient='split')} if isinstance(dataset, pd.DataFrame) else create_tf_serving_json(dataset)
|
37 |
-
data_json = json.dumps(ds_dict, allow_nan=True)
|
38 |
-
print("***ds_dict: ")
|
39 |
-
print(ds_dict)
|
40 |
-
print("***data_json: ")
|
41 |
-
print(data_json)
|
42 |
-
response = requests.request(method='POST', headers=headers, url=model_uri, data=data_json)
|
43 |
-
if response.status_code != 200:
|
44 |
-
raise Exception(f"Request failed with status {response.status_code}, {response.text}")
|
45 |
-
return response.json()
|
46 |
-
|
47 |
-
def get_completion(prompt):
|
48 |
-
return score_model(model_uri, databricks_token, prompt)
|
49 |
-
|
50 |
-
def greet(input):
|
51 |
-
n_shot_learning = f"""Below is an instruction that describes a task, paired with an input that provides further context. Write a response that appropriately completes the request.
|
52 |
|
53 |
### Instruction:
|
54 |
You are demanding customer
|
@@ -95,6 +56,44 @@ I am building an online community to help people to find dates.
|
|
95 |
{{"solution": "FindDates.com", "problem": "finding a date", "features": "online community to help people find dates", "target_customer": "people looking for a date", "fg_will_use": "True", "reason_to_use": "I am looking for an online community to help people find dates. FindDates.com meets my needs and I would use it to find my next great date.","fg_will_pay": "True", "reason_to_pay": "I would not pay for it as I am looking for an online community to help people find dates. But for products related to dating, paying for it would be a no-brainer.","fg_will_invest": "False", "reason_to_invest": "There are many online dating platforms already.","score": "40"}}
|
96 |
"""
|
97 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
98 |
sys_msg="You are demanding customer."
|
99 |
|
100 |
instruction = """Determine the product or solution, the problem being solved, features, target customer that is being discussed in the \
|
@@ -121,12 +120,8 @@ Give a score for the product. Format your response as a JSON object with \
|
|
121 |
print("***total_prompt:")
|
122 |
print(total_prompt)
|
123 |
response = get_completion(total_prompt)
|
124 |
-
#gen_text = response["predictions"][0]["generated_text"]
|
125 |
-
#return json.dumps(extract_json(gen_text, 3))
|
126 |
gen_text = response["choices"][0]["text"]
|
127 |
-
#return gen_text
|
128 |
return json.dumps(extract_json(gen_text, -1))
|
129 |
-
#return json.dumps(response)
|
130 |
|
131 |
#iface = gr.Interface(fn=greet, inputs="text", outputs="text")
|
132 |
#iface.launch()
|
|
|
7 |
from dotenv import load_dotenv, find_dotenv
|
8 |
_ = load_dotenv(find_dotenv())
|
9 |
|
|
|
10 |
databricks_token = os.getenv('TENATCH_TOKEN')
|
11 |
model_uri = "http://15.152.197.215/v1/completions"
|
12 |
+
n_shot_learning = f"""Below is an instruction that describes a task, paired with an input that provides further context. Write a response that appropriately completes the request.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
|
14 |
### Instruction:
|
15 |
You are demanding customer
|
|
|
56 |
{{"solution": "FindDates.com", "problem": "finding a date", "features": "online community to help people find dates", "target_customer": "people looking for a date", "fg_will_use": "True", "reason_to_use": "I am looking for an online community to help people find dates. FindDates.com meets my needs and I would use it to find my next great date.","fg_will_pay": "True", "reason_to_pay": "I would not pay for it as I am looking for an online community to help people find dates. But for products related to dating, paying for it would be a no-brainer.","fg_will_invest": "False", "reason_to_invest": "There are many online dating platforms already.","score": "40"}}
|
57 |
"""
|
58 |
|
59 |
+
def extract_json(gen_text, n_shot_learning=0):
|
60 |
+
if(n_shot_learning == -1) :
|
61 |
+
start_index = 0
|
62 |
+
else :
|
63 |
+
start_index = gen_text.index("### Response:\n{") + 14
|
64 |
+
if(n_shot_learning > 0) :
|
65 |
+
for i in range(0, n_shot_learning):
|
66 |
+
gen_text = gen_text[start_index:]
|
67 |
+
start_index = gen_text.index("### Response:\n{") + 14
|
68 |
+
end_index = gen_text.find("}\n\n### ") + 1
|
69 |
+
return gen_text[start_index:end_index]
|
70 |
+
|
71 |
+
def score_model(model_uri, databricks_token, prompt):
|
72 |
+
ds_dict={
|
73 |
+
"model": "debisoft/mpt-7b-awq-tester",
|
74 |
+
"prompt": prompt,
|
75 |
+
"temperature": 0.5,
|
76 |
+
"max_tokens": 1000}
|
77 |
+
headers = {
|
78 |
+
"Authorization": f"Bearer {databricks_token}",
|
79 |
+
"Content-Type": "application/json",
|
80 |
+
}
|
81 |
+
#ds_dict = {'dataframe_split': dataset.to_dict(orient='split')} if isinstance(dataset, pd.DataFrame) else create_tf_serving_json(dataset)
|
82 |
+
data_json = json.dumps(ds_dict, allow_nan=True)
|
83 |
+
print("***ds_dict: ")
|
84 |
+
print(ds_dict)
|
85 |
+
print("***data_json: ")
|
86 |
+
print(data_json)
|
87 |
+
response = requests.request(method='POST', headers=headers, url=model_uri, data=data_json)
|
88 |
+
if response.status_code != 200:
|
89 |
+
raise Exception(f"Request failed with status {response.status_code}, {response.text}")
|
90 |
+
return response.json()
|
91 |
+
|
92 |
+
def get_completion(prompt):
|
93 |
+
return score_model(model_uri, databricks_token, prompt)
|
94 |
+
|
95 |
+
def greet(input):
|
96 |
+
|
97 |
sys_msg="You are demanding customer."
|
98 |
|
99 |
instruction = """Determine the product or solution, the problem being solved, features, target customer that is being discussed in the \
|
|
|
120 |
print("***total_prompt:")
|
121 |
print(total_prompt)
|
122 |
response = get_completion(total_prompt)
|
|
|
|
|
123 |
gen_text = response["choices"][0]["text"]
|
|
|
124 |
return json.dumps(extract_json(gen_text, -1))
|
|
|
125 |
|
126 |
#iface = gr.Interface(fn=greet, inputs="text", outputs="text")
|
127 |
#iface.launch()
|