2023-07-11 23:50:08 +02:00
|
|
|
import base64
|
2023-09-16 05:11:16 +02:00
|
|
|
import os
|
|
|
|
|
2023-07-11 23:50:08 +02:00
|
|
|
import numpy as np
|
|
|
|
|
2023-07-24 16:28:12 +02:00
|
|
|
def float_list_to_base64(float_array: np.ndarray) -> str:
|
2023-07-11 23:50:08 +02:00
|
|
|
# Convert the list to a float32 array that the OpenAPI client expects
|
2023-09-16 05:11:16 +02:00
|
|
|
# float_array = np.array(float_list, dtype="float32")
|
2023-07-11 23:50:08 +02:00
|
|
|
|
|
|
|
# Get raw bytes
|
|
|
|
bytes_array = float_array.tobytes()
|
|
|
|
|
|
|
|
# Encode bytes into base64
|
|
|
|
encoded_bytes = base64.b64encode(bytes_array)
|
|
|
|
|
|
|
|
# Turn raw base64 encoded bytes into ASCII
|
|
|
|
ascii_string = encoded_bytes.decode('ascii')
|
|
|
|
return ascii_string
|
|
|
|
|
2023-07-12 20:33:25 +02:00
|
|
|
|
2023-07-11 23:50:08 +02:00
|
|
|
def end_line(s):
|
|
|
|
if s and s[-1] != '\n':
|
|
|
|
s = s + '\n'
|
|
|
|
return s
|
|
|
|
|
2023-07-12 20:33:25 +02:00
|
|
|
|
2023-07-11 23:50:08 +02:00
|
|
|
def debug_msg(*args, **kwargs):
|
2023-09-18 03:39:29 +02:00
|
|
|
from extensions.openai.script import params
|
|
|
|
if os.environ.get("OPENEDAI_DEBUG", params.get('debug', 0)):
|
2023-07-12 20:33:25 +02:00
|
|
|
print(*args, **kwargs)
|