Create gemma_tools.py
Browse files- gemma_tools.py +37 -0
gemma_tools.py
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
def get_args_or_none(data):
|
| 2 |
+
system_prompt = data.pop("system-prompt", "You are Gemma. Assist user with whatever they require, in a safe and moral manner.")
|
| 3 |
+
inputs = data.pop("inputs", "")
|
| 4 |
+
temperature = data.pop("temperature", None)
|
| 5 |
+
if not temperature or temperature is None:
|
| 6 |
+
temperature = data.pop("temp", 0.33)
|
| 7 |
+
if temperature > 3 or temperature < 0:
|
| 8 |
+
return {
|
| 9 |
+
0: False,
|
| 10 |
+
"status": "error",
|
| 11 |
+
"reason": "temperature",
|
| 12 |
+
"reason": "invalid temperature ( 0.01 - 1.00 only allowed )"
|
| 13 |
+
}
|
| 14 |
+
top_p = data.pop("top-p", 0.85)
|
| 15 |
+
if top_p > 3 or top_p < 0:
|
| 16 |
+
return {
|
| 17 |
+
0: False,
|
| 18 |
+
"status": "error",
|
| 19 |
+
"reason": "top_p",
|
| 20 |
+
"description": "invalid top percentage ( 0.01 - 1.00 only allowed )"
|
| 21 |
+
}
|
| 22 |
+
top_k = data.pop("top-k", 42)
|
| 23 |
+
if top_k > 100 or top_k < 0:
|
| 24 |
+
return {
|
| 25 |
+
0: False,
|
| 26 |
+
"status": "error",
|
| 27 |
+
"reason": "top_k",
|
| 28 |
+
"description": "invalid top k ( 1 - 99 only allowed )"
|
| 29 |
+
}
|
| 30 |
+
return {
|
| 31 |
+
0: True,
|
| 32 |
+
"inputs": inputs,
|
| 33 |
+
"system_prompt": system_prompt,
|
| 34 |
+
"temperature": temperature,
|
| 35 |
+
"top_p": top_p,
|
| 36 |
+
"top_k": top_k
|
| 37 |
+
}
|