-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
51 lines (39 loc) · 1.24 KB
/
test.py
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
# system
import asyncio
import time
# first-party
from gpt_util import GPTUtil
# third-party
import tiktoken
def token_count(text, encoding_name="gpt-3.5-turbo"):
encoding = tiktoken.encoding_for_model(encoding_name)
return len(encoding.encode(text))
gpt = GPTUtil()
print(gpt.gpt_response("Hi there!"))
print("Testing GPT 4 fallback")
message = "AI is going to change the world! " * 1000
print(token_count(message))
s = time.time()
print(gpt.gpt_response("How many times AI is mentioned in the following text " + message))
e = time.time()
print("Time taken", e - s)
print("Testing GPT caching")
s = time.time()
print(gpt.gpt_response("How many times AI is mentioned in the following text " + message))
e = time.time()
print("Time taken", e - s)
gpt = GPTUtil(enable_cache=False)
print("Testing parallel calls")
message_list = ["What is 2^10? Respond with an integer only:"] * 10
s = time.time()
responses = [gpt.gpt_response(message) for message in message_list]
t = time.time()
print("Time taken", t - s)
print(responses[0])
print("Num responses", len(responses))
s = time.time()
responses = asyncio.run(gpt.parallel_gpt_response(message_list))
t = time.time()
print("Time taken", t - s)
print(responses[0])
print("Num responses", len(responses))