locust 2.33.3.dev3__py3-none-any.whl → 2.33.3.dev9__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- locust/_version.py +2 -2
- locust/contrib/oai.py +73 -0
- {locust-2.33.3.dev3.dist-info → locust-2.33.3.dev9.dist-info}/METADATA +1 -1
- {locust-2.33.3.dev3.dist-info → locust-2.33.3.dev9.dist-info}/RECORD +7 -6
- {locust-2.33.3.dev3.dist-info → locust-2.33.3.dev9.dist-info}/WHEEL +0 -0
- {locust-2.33.3.dev3.dist-info → locust-2.33.3.dev9.dist-info}/entry_points.txt +0 -0
- {locust-2.33.3.dev3.dist-info → locust-2.33.3.dev9.dist-info}/licenses/LICENSE +0 -0
locust/_version.py
CHANGED
@@ -17,5 +17,5 @@ __version__: str
|
|
17
17
|
__version_tuple__: VERSION_TUPLE
|
18
18
|
version_tuple: VERSION_TUPLE
|
19
19
|
|
20
|
-
__version__ = version = '2.33.3.
|
21
|
-
__version_tuple__ = version_tuple = (2, 33, 3, '
|
20
|
+
__version__ = version = '2.33.3.dev9'
|
21
|
+
__version_tuple__ = version_tuple = (2, 33, 3, 'dev9')
|
locust/contrib/oai.py
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
# Note: this User is experimental and may change without notice.
|
2
|
+
# The filename is oai.py so it doesnt clash with the openai package.
|
3
|
+
from locust.user import User
|
4
|
+
|
5
|
+
import os
|
6
|
+
import time
|
7
|
+
from collections.abc import Generator
|
8
|
+
from contextlib import contextmanager
|
9
|
+
|
10
|
+
import httpx
|
11
|
+
from openai import OpenAI # dont forget to install openai
|
12
|
+
|
13
|
+
# convenience for when running in Locust Cloud, where only LOCUST_* env vars are forwarded
|
14
|
+
if "LOCUST_OPENAI_API_KEY" in os.environ:
|
15
|
+
os.environ["OPENAI_API_KEY"] = os.environ["LOCUST_OPENAI_API_KEY"]
|
16
|
+
|
17
|
+
if not "OPENAI_API_KEY" in os.environ:
|
18
|
+
raise Exception("You need to set OPENAI_API_KEY or LOCUST_OPENAI_API_KEY env var to use OpenAIUser")
|
19
|
+
|
20
|
+
|
21
|
+
class OpenAIClient(OpenAI):
|
22
|
+
def __init__(self, request_event, user, *args, **kwargs):
|
23
|
+
self.request_name = None # used to override url-based request names
|
24
|
+
self.user = user # currently unused, but could be useful later
|
25
|
+
|
26
|
+
def request_start(request):
|
27
|
+
request.start_time = time.time()
|
28
|
+
request.start_perf_counter = time.perf_counter()
|
29
|
+
|
30
|
+
def request_end(response):
|
31
|
+
exception = None
|
32
|
+
response.read()
|
33
|
+
response_time = (time.perf_counter() - response.request.start_perf_counter) * 1000
|
34
|
+
try:
|
35
|
+
response.raise_for_status()
|
36
|
+
except httpx.HTTPStatusError as e:
|
37
|
+
exception = e
|
38
|
+
request_event.fire(
|
39
|
+
request_type=response.request.method,
|
40
|
+
name=self.request_name if self.request_name else response.url.path,
|
41
|
+
context={},
|
42
|
+
response=response,
|
43
|
+
exception=exception,
|
44
|
+
start_time=response.request.start_time,
|
45
|
+
response_time=response_time,
|
46
|
+
# Store the number of output tokens as response_length instead of the actual payload size because it is more useful
|
47
|
+
response_length=response.json().get("usage", {}).get("output_tokens", 0),
|
48
|
+
url=response.url,
|
49
|
+
)
|
50
|
+
|
51
|
+
super().__init__(
|
52
|
+
*args,
|
53
|
+
**kwargs,
|
54
|
+
http_client=httpx.Client(event_hooks={"request": [request_start], "response": [request_end]}),
|
55
|
+
)
|
56
|
+
|
57
|
+
@contextmanager
|
58
|
+
def rename_request(self, name: str) -> Generator[None]:
|
59
|
+
"""Group requests using the "with" keyword"""
|
60
|
+
|
61
|
+
self.request_name = name
|
62
|
+
try:
|
63
|
+
yield
|
64
|
+
finally:
|
65
|
+
self.request_name = None
|
66
|
+
|
67
|
+
|
68
|
+
class OpenAIUser(User):
|
69
|
+
abstract = True
|
70
|
+
|
71
|
+
def __init__(self, *args, **kwargs):
|
72
|
+
super().__init__(*args, **kwargs)
|
73
|
+
self.client = OpenAIClient(self.environment.events.request, user=self)
|
@@ -1,6 +1,6 @@
|
|
1
1
|
locust/__init__.py,sha256=aWeuBPUxONjwNm1xp4v8L4BO14SuYLjscIiwJVX1Ui4,1746
|
2
2
|
locust/__main__.py,sha256=vBQ82334kX06ImDbFlPFgiBRiLIinwNk3z8Khs6hd74,31
|
3
|
-
locust/_version.py,sha256=
|
3
|
+
locust/_version.py,sha256=rtO6T9Z-9Cvc1wxULMvtZ1HAeWQphLTGmdmZ6ypkvu8,526
|
4
4
|
locust/argument_parser.py,sha256=ruSJcY4ouERwVopHvHDK-obQD6nlRKDqjLLwje2SH9k,32806
|
5
5
|
locust/clients.py,sha256=LHAYjaoRjMXwdOB8KBUYRH9-8Uk4F8NvUsDy5UTxKkA,19352
|
6
6
|
locust/debug.py,sha256=7CCm8bIg44uGH2wqBlo1rXBzV2VzwPicLxLewz8r5CQ,5099
|
@@ -20,6 +20,7 @@ locust/web.py,sha256=oVHqJ_vPQ-gLzMZgc8RwqG44DQ6nzbXpta78ihtVCjo,30122
|
|
20
20
|
locust/contrib/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
21
21
|
locust/contrib/fasthttp.py,sha256=lB1t8syshdpJDrNnrN6j00FF4TszdYY8YUfdg-9mwwE,29275
|
22
22
|
locust/contrib/mongodb.py,sha256=1seUYgJOaNKwybYOP9PUEVhgl8hGy-G33f8lFj3R8W8,1246
|
23
|
+
locust/contrib/oai.py,sha256=Ot3T8lp31ThckGbNps86oVvq6Vn845Eec0mxhDmONDE,2684
|
23
24
|
locust/contrib/postgres.py,sha256=OuMWnGYN10K65Tq2axVESEW25Y0g5gJb0rK90jkcCJg,1230
|
24
25
|
locust/rpc/__init__.py,sha256=5YOu-58XSnt-oWWNATgXLTNdYoDkkngwHNXprxkWKSM,99
|
25
26
|
locust/rpc/protocol.py,sha256=n-rb3GZQcAlldYDj4E4GuFGylYj_26GSS5U29meft5Y,1282
|
@@ -50,8 +51,8 @@ locust/webui/dist/assets/graphs-light.png,sha256=7L6pOehXqCojQclzeP91l-LskFQAw_n
|
|
50
51
|
locust/webui/dist/assets/index-DcS9MJSn.js,sha256=CWbthTyP_6GEGZOqPHZXKAA9r7K0CWX32WWSAHKA9O0,1679855
|
51
52
|
locust/webui/dist/assets/testruns-dark.png,sha256=np6MvpgJ2gkKQ66SOmukLtjsMtHqTSr5dNfza-2XtCo,267621
|
52
53
|
locust/webui/dist/assets/testruns-light.png,sha256=iLAxBZh3kRsfGkcB1-1KSAbFgGji43IqiUrYuJlUoPk,276839
|
53
|
-
locust-2.33.3.
|
54
|
-
locust-2.33.3.
|
55
|
-
locust-2.33.3.
|
56
|
-
locust-2.33.3.
|
57
|
-
locust-2.33.3.
|
54
|
+
locust-2.33.3.dev9.dist-info/METADATA,sha256=19Te0Z7H0swCOOPhxqVhNrHfitTfPJ2uek21n4xZbj0,9637
|
55
|
+
locust-2.33.3.dev9.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
56
|
+
locust-2.33.3.dev9.dist-info/entry_points.txt,sha256=RAdt8Ku-56m7bFjmdj-MBhbF6h4NX7tVODR9QNnOg0E,44
|
57
|
+
locust-2.33.3.dev9.dist-info/licenses/LICENSE,sha256=5hnz-Vpj0Z3kSCQl0LzV2hT1TLc4LHcbpBp3Cy-EuyM,1110
|
58
|
+
locust-2.33.3.dev9.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|