MatteoScript commited on
Commit
89622e2
·
verified ·
1 Parent(s): a35fbd5

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +8 -6
main.py CHANGED
@@ -49,9 +49,12 @@ class PostSpazio(BaseModel):
49
  input: str = ''
50
  api_name: str = "/chat"
51
 
52
- def LoggaTesto(log_type, data):
53
- formatted_data = json.dumps(data, indent=2)
54
- print(f"\n{datetime.now()}: ---------------------------------------------------------------| {log_type} |-------------------------------------------------------------------\n{formatted_data}")
 
 
 
55
 
56
  #--------------------------------------------------- Generazione TESTO ------------------------------------------------------
57
  @app.post("/Genera")
@@ -62,7 +65,7 @@ def generate_text(request: Request, input_data: InputData):
62
  top_p = input_data.top_p
63
  repetition_penalty = input_data.repetition_penalty
64
  input_text = generate_input_text(input_data)
65
- LoggaTesto("RICHIESTA SINCRONA", input_text)
66
  max_new_tokens = min(max_new_tokens, 29500 - len(input_text))
67
  history = []
68
  generated_response = generate(input_text, history, temperature, max_new_tokens, top_p, repetition_penalty)
@@ -151,8 +154,7 @@ async def make_request(session, token, data, url, max_retries=3):
151
  try:
152
  result_data = await response.json()
153
  except aiohttp.ContentTypeError:
154
- result_data = await response.text()
155
- print(result_data)
156
  return result_data
157
  except (asyncio.TimeoutError, aiohttp.ClientError, requests.exceptions.HTTPError) as e:
158
  LoggaTesto("ERRORE ASYNC", {e})
 
49
  input: str = ''
50
  api_name: str = "/chat"
51
 
52
+ def LoggaTesto(log_type, data, serializza=True):
53
+ if serializza:
54
+ formatted_data = json.dumps(data, indent=2)
55
+ else:
56
+ formatted_data = data
57
+ print(f"\n{datetime.now()}: ---------------------------------------------------------------| {log_type} |--------------------------------------------------------------\n{formatted_data}")
58
 
59
  #--------------------------------------------------- Generazione TESTO ------------------------------------------------------
60
  @app.post("/Genera")
 
65
  top_p = input_data.top_p
66
  repetition_penalty = input_data.repetition_penalty
67
  input_text = generate_input_text(input_data)
68
+ LoggaTesto("RICHIESTA SINCRONA", input_text, False)
69
  max_new_tokens = min(max_new_tokens, 29500 - len(input_text))
70
  history = []
71
  generated_response = generate(input_text, history, temperature, max_new_tokens, top_p, repetition_penalty)
 
154
  try:
155
  result_data = await response.json()
156
  except aiohttp.ContentTypeError:
157
+ result_data = await response.text()
 
158
  return result_data
159
  except (asyncio.TimeoutError, aiohttp.ClientError, requests.exceptions.HTTPError) as e:
160
  LoggaTesto("ERRORE ASYNC", {e})