Update app.py
Browse files128 unmodified lines129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165128 unmodified lines# Configure the API keypalm.configure(api_key="AIzaSyDmHbZlWJJBlaW5BAJwfOu7HP-JAKFiCpY")@app.route('/chat', methods=['POST'])def generate():data = request.get_json()model = data.get('model', 'models/text-bison-001')temperature = data.get('temperature', 1)candidate_count = data.get('candidate_count', 1)top_k = data.get('top_k', 40)top_p = data.get('top_p', 0.95)max_output_tokens = data.get('max_output_tokens', 1024)stop_sequences = data.get('stop_sequences', [])safety_settings = data.get('safety_settings', [{"category": "HARM_CATEGORY_DEROGATORY", "threshold": "BLOCK_NONE"},{"category": "HARM_CATEGORY_TOXICITY", "threshold": "BLOCK_NONE"},{"category": "HARM_CATEGORY_VIOLENCE", "threshold": "BLOCK_NONE"},{"category": "HARM_CATEGORY_SEXUAL", "threshold": "BLOCK_NONE"},{"category": "HARM_CATEGORY_MEDICAL", "threshold": "BLOCK_NONE"},{"category": "HARM_CATEGORY_DANGEROUS", "threshold": "BLOCK_NONE"},])result = palm.generate(model=model,temperature=temperature,candidate_count=candidate_count,top_k=top_k,top_p=top_p,max_output_tokens=max_output_tokens,stop_sequences=stop_sequences,safety_settings=safety_settings)return jsonify(result)@app.route('/gpt', methods=['POST'])def chat_gpt():128 unmodified lines129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164128 unmodified lines# Configure the API keypalm.configure(api_key="AIzaSyDmHbZlWJJBlaW5BAJwfOu7HP-JAKFiCpY")defaults = {'model': 'models/text-bison-001','temperature': 1,'candidate_count': 1,'top_k': 40,'top_p': 0.95,'max_output_tokens': 1024,'stop_sequences': [],'safety_settings': [{"category": "HARM_CATEGORY_DEROGATORY", "threshold": "BLOCK_NONE"},{"category": "HARM_CATEGORY_TOXICITY", "threshold": "BLOCK_NONE"},{"category": "HARM_CATEGORY_VIOLENCE", "threshold": "BLOCK_NONE"},{"category": "HARM_CATEGORY_SEXUAL", "threshold": "BLOCK_NONE"},{"category": "HARM_CATEGORY_MEDICAL", "threshold": "BLOCK_NONE"},{"category": "HARM_CATEGORY_DANGEROUS", "threshold": "BLOCK_NONE"},]}@app.route('/chat', methods=['POST'])def generate():data = request.get_json()prompt = data.get('prompt', 'You are A helpfull AI that will follow users instructions.')# Call the generate functionresult = palm.generate_text(**defaults,prompt=prompt)return jsonify(result.result)@app.route('/gpt', methods=['POST'])def chat_gpt():
app.py+22-23