Spaces:
Build error
Build error
File size: 2,437 Bytes
256f1a5 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 | from old_app import respond, base_message
import time
def test_api():
# Set up input parameters
message = "What is the meaning of life?"
history = []
system_message_val = base_message
temperature = 0.7
practicality = 0.8 # This should modify the system message to provide actionable advice
max_tokens = 256
use_local_model = False # Set to False to use the API-based model
start_time = time.time()
# Call the respond function (generator)
result_generator = respond(
message=message,
history=history,
system_message_val=system_message_val,
temperature=temperature,
practicality=practicality,
use_local_model=use_local_model
)
# Iterate over the generator to get the final output
final_history, final_system_message = None, None
for result in result_generator:
final_history, final_system_message = result
end_time = time.time()
runtime = end_time - start_time
print("API Runtime: ", runtime)
print("API Final conversation history:", final_history)
print("API Final system message:", final_system_message)
def test_local():
# Set up input parameters
message = "What is the meaning of life?"
history = []
system_message_val = base_message
temperature = 0.7
practicality = 0.8 # This should modify the system message to provide actionable advice
use_local_model = True # Set to True to use the local model
start_time = time.time()
print("start time: ", start_time)
# Call the respond function (generator)
result_generator = respond(
message=message,
history=history,
system_message_val=system_message_val,
temperature=temperature,
practicality=practicality,
use_local_model=use_local_model,
max_tokens=256
)
# Iterate over the generator to get the final output
final_history, final_system_message = None, None
print("Iterating over results...")
for result in result_generator:
print("Result: ", result)
final_history, final_system_message = result
end_time = time.time()
runtime = end_time - start_time
print("Local Runtime: ", runtime)
print("Local Final conversation history:", final_history)
print("Local Final system message:", final_system_message)
# Run the tests
if __name__ == "__main__":
# test_api()
test_local()
|