debisoft commited on
Commit
6c14617
·
1 Parent(s): ea47365

Changed to target Tenatch endpoint

Browse files
Files changed (1) hide show
  1. app.py +22 -15
app.py CHANGED
@@ -8,28 +8,32 @@ from dotenv import load_dotenv, find_dotenv
8
  _ = load_dotenv(find_dotenv())
9
 
10
 
11
- databricks_token = os.getenv('DATABRICKS_TOKEN')
12
- model_uri = "https://dbc-eb788f31-6c73.cloud.databricks.com/serving-endpoints/Mpt-7b-tester/invocations"
13
 
14
  def extract_json(gen_text, n_shot_learning=0):
15
- start_index = gen_text.index("### Response:\n{") + 14
 
 
 
16
  if(n_shot_learning > 0) :
17
  for i in range(0, n_shot_learning):
18
  gen_text = gen_text[start_index:]
19
  start_index = gen_text.index("### Response:\n{") + 14
20
- end_index = gen_text.index("}\n\n### ") + 1
21
  return gen_text[start_index:end_index]
22
 
23
  def score_model(model_uri, databricks_token, prompt):
24
- dataset=pd.DataFrame({
25
- "prompt":[prompt],
26
- "temperature": [0.5],
27
- "max_tokens": [1000]})
 
28
  headers = {
29
  "Authorization": f"Bearer {databricks_token}",
30
  "Content-Type": "application/json",
31
  }
32
- ds_dict = {'dataframe_split': dataset.to_dict(orient='split')} if isinstance(dataset, pd.DataFrame) else create_tf_serving_json(dataset)
33
  data_json = json.dumps(ds_dict, allow_nan=True)
34
  print("***ds_dict: ")
35
  print(ds_dict)
@@ -48,7 +52,7 @@ def greet(input):
48
 
49
  ### Instruction:
50
  You are demanding customer
51
- Determine the product or solution, the problem being solved, features, target customer that are being discussed in the
52
  following user prompt. State if you would use this product and elaborate on why. Also state if you would pay for it and elaborate on why.
53
  Finally, state if you would invest in it and elaborate on why.
54
 
@@ -64,7 +68,7 @@ Below is an instruction that describes a task, paired with an input that provide
64
 
65
  ### Instruction:
66
  You are demanding customer
67
- Determine the product or solution, the problem being solved, features, target customer that are being discussed in the
68
  following user prompt. State if you would use this product and elaborate on why. Also state if you would pay for it and elaborate on why.
69
  Finally, state if you would invest in it and elaborate on why.
70
 
@@ -78,7 +82,7 @@ Thawrih brings diversity and inclusivity to the activewear market with its sport
78
 
79
  ### Instruction:
80
  You are demanding customer
81
- Determine the product or solution, the problem being solved, features, target customer that are being discussed in the
82
  following user prompt. State if you would use this product and elaborate on why. Also state if you would pay for it and elaborate on why.
83
  Finally, state if you would invest in it and elaborate on why.
84
 
@@ -93,7 +97,7 @@ I am building an online community to help people to find dates.
93
 
94
  sys_msg="You are demanding customer."
95
 
96
- instruction = """Determine the product or solution, the problem being solved, features, target customer that are being discussed in the \
97
  following user prompt. State if you would use this product and elaborate on why. Also state if you would pay for it and elaborate on why.\
98
  Finally, state if you would invest in it and elaborate on why.\
99
 
@@ -117,8 +121,11 @@ Give a score for the product. Format your response as a JSON object with \
117
  print("***total_prompt:")
118
  print(total_prompt)
119
  response = get_completion(total_prompt)
120
- gen_text = response["predictions"][0]["generated_text"]
121
- return json.dumps(extract_json(gen_text, 3))
 
 
 
122
  #return json.dumps(response)
123
 
124
  #iface = gr.Interface(fn=greet, inputs="text", outputs="text")
 
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)
 
52
 
53
  ### Instruction:
54
  You are demanding customer
55
+ Determine the product or solution, the problem being solved, features, target customer that is being discussed in the
56
  following user prompt. State if you would use this product and elaborate on why. Also state if you would pay for it and elaborate on why.
57
  Finally, state if you would invest in it and elaborate on why.
58
 
 
68
 
69
  ### Instruction:
70
  You are demanding customer
71
+ Determine the product or solution, the problem being solved, features, target customer that is being discussed in the
72
  following user prompt. State if you would use this product and elaborate on why. Also state if you would pay for it and elaborate on why.
73
  Finally, state if you would invest in it and elaborate on why.
74
 
 
82
 
83
  ### Instruction:
84
  You are demanding customer
85
+ Determine the product or solution, the problem being solved, features, target customer that is being discussed in the
86
  following user prompt. State if you would use this product and elaborate on why. Also state if you would pay for it and elaborate on why.
87
  Finally, state if you would invest in it and elaborate on why.
88
 
 
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 \
101
  following user prompt. State if you would use this product and elaborate on why. Also state if you would pay for it and elaborate on why.\
102
  Finally, state if you would invest in it and elaborate on why.\
103
 
 
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 extract_json(gen_text, -1)
129
  #return json.dumps(response)
130
 
131
  #iface = gr.Interface(fn=greet, inputs="text", outputs="text")