Spaces:
Running
Running
Update main.py
Browse files
main.py
CHANGED
|
@@ -52,26 +52,36 @@ def read_root(request: Request, input_data: InputData):
|
|
| 52 |
max_new_tokens = input_data.max_new_tokens
|
| 53 |
top_p = input_data.top_p
|
| 54 |
repetition_penalty = input_data.repetition_penalty
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
history = []
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
"
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
"messages": [
|
| 64 |
-
{{
|
| 65 |
-
"role": "instructions",
|
| 66 |
-
"content": "{input_data.instruction}"
|
| 67 |
}},
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 75 |
print(f"{datetime.now()} - Input Text: {input_text}")
|
| 76 |
generated_response = generate(input_text, history, temperature, max_new_tokens, top_p, repetition_penalty)
|
| 77 |
print(f"{datetime.now()} - Response Text: {generated_response}")
|
|
|
|
| 52 |
max_new_tokens = input_data.max_new_tokens
|
| 53 |
top_p = input_data.top_p
|
| 54 |
repetition_penalty = input_data.repetition_penalty
|
| 55 |
+
if input_data.instruction.startswith("http"):
|
| 56 |
+
try:
|
| 57 |
+
resp = requests.get(input_data.instruction)
|
| 58 |
+
resp.raise_for_status() # Lancia un'eccezione per errori HTTP
|
| 59 |
+
input_data.instruction = resp.text
|
| 60 |
+
except requests.exceptions.RequestException as e:
|
| 61 |
+
input_data.instruction = ""
|
| 62 |
history = []
|
| 63 |
+
if input_data.systemRole != "" or input_data.systemStyle != "" or input_data.instruction != ""
|
| 64 |
+
input_text = f'''
|
| 65 |
+
{{
|
| 66 |
+
"input": {{
|
| 67 |
+
"role": "system",
|
| 68 |
+
"content": "{input_data.systemRole}",
|
| 69 |
+
"style": "{input_data.systemStyle}"
|
|
|
|
|
|
|
|
|
|
|
|
|
| 70 |
}},
|
| 71 |
+
"messages": [
|
| 72 |
+
{{
|
| 73 |
+
"role": "instructions",
|
| 74 |
+
"content": "{input_data.instruction}"
|
| 75 |
+
}},
|
| 76 |
+
{{
|
| 77 |
+
"role": "user",
|
| 78 |
+
"content": "{input_data.input}"
|
| 79 |
+
}}
|
| 80 |
+
]
|
| 81 |
+
}}
|
| 82 |
+
'''
|
| 83 |
+
else:
|
| 84 |
+
input_text = input_data.input
|
| 85 |
print(f"{datetime.now()} - Input Text: {input_text}")
|
| 86 |
generated_response = generate(input_text, history, temperature, max_new_tokens, top_p, repetition_penalty)
|
| 87 |
print(f"{datetime.now()} - Response Text: {generated_response}")
|