Update app.py
Browse files
app.py
CHANGED
|
@@ -125,8 +125,43 @@ def WEBScout_translate():
|
|
| 125 |
WEBS_instance = WEBS() # Instantiate WEBS without context manager
|
| 126 |
translation = WEBS_instance.translate(keywords, to=target_language)
|
| 127 |
return jsonify(translation)
|
|
|
|
|
|
|
|
|
|
| 128 |
|
| 129 |
@app.route('/chat', methods=['POST'])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 130 |
def chat_gpt():
|
| 131 |
user_input = request.json.get('message')
|
| 132 |
if user_input is None:
|
|
|
|
| 125 |
WEBS_instance = WEBS() # Instantiate WEBS without context manager
|
| 126 |
translation = WEBS_instance.translate(keywords, to=target_language)
|
| 127 |
return jsonify(translation)
|
| 128 |
+
|
| 129 |
+
# Configure the API key
|
| 130 |
+
palm.configure(api_key="AIzaSyDmHbZlWJJBlaW5BAJwfOu7HP-JAKFiCpY")
|
| 131 |
|
| 132 |
@app.route('/chat', methods=['POST'])
|
| 133 |
+
def generate():
|
| 134 |
+
data = request.get_json()
|
| 135 |
+
model = data.get('model', 'models/text-bison-001')
|
| 136 |
+
temperature = data.get('temperature', 1)
|
| 137 |
+
candidate_count = data.get('candidate_count', 1)
|
| 138 |
+
top_k = data.get('top_k', 40)
|
| 139 |
+
top_p = data.get('top_p', 0.95)
|
| 140 |
+
max_output_tokens = data.get('max_output_tokens', 1024)
|
| 141 |
+
stop_sequences = data.get('stop_sequences', [])
|
| 142 |
+
safety_settings = data.get('safety_settings', [
|
| 143 |
+
{"category": "HARM_CATEGORY_DEROGATORY", "threshold": "BLOCK_NONE"},
|
| 144 |
+
{"category": "HARM_CATEGORY_TOXICITY", "threshold": "BLOCK_NONE"},
|
| 145 |
+
{"category": "HARM_CATEGORY_VIOLENCE", "threshold": "BLOCK_NONE"},
|
| 146 |
+
{"category": "HARM_CATEGORY_SEXUAL", "threshold": "BLOCK_NONE"},
|
| 147 |
+
{"category": "HARM_CATEGORY_MEDICAL", "threshold": "BLOCK_NONE"},
|
| 148 |
+
{"category": "HARM_CATEGORY_DANGEROUS", "threshold": "BLOCK_NONE"},
|
| 149 |
+
])
|
| 150 |
+
|
| 151 |
+
result = palm.generate(
|
| 152 |
+
model=model,
|
| 153 |
+
temperature=temperature,
|
| 154 |
+
candidate_count=candidate_count,
|
| 155 |
+
top_k=top_k,
|
| 156 |
+
top_p=top_p,
|
| 157 |
+
max_output_tokens=max_output_tokens,
|
| 158 |
+
stop_sequences=stop_sequences,
|
| 159 |
+
safety_settings=safety_settings
|
| 160 |
+
)
|
| 161 |
+
|
| 162 |
+
return jsonify(result)
|
| 163 |
+
|
| 164 |
+
@app.route('/gpt', methods=['POST'])
|
| 165 |
def chat_gpt():
|
| 166 |
user_input = request.json.get('message')
|
| 167 |
if user_input is None:
|