-
Notifications
You must be signed in to change notification settings - Fork 44.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b5f95fd
commit 4ec55ea
Showing
10 changed files
with
1,851 additions
and
1,133 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
497 changes: 497 additions & 0 deletions
497
tests/integration/cassettes/test_local_cache/test_get_relevant.yaml
Large diffs are not rendered by default.
Oops, something went wrong.
338 changes: 338 additions & 0 deletions
338
...ration/cassettes/test_memory_management/test_save_memory_trimmed_from_context_window.yaml
Large diffs are not rendered by default.
Oops, something went wrong.
466 changes: 234 additions & 232 deletions
466
...egration/challenges/memory/cassettes/test_memory_challenge_a/test_memory_challenge_a.yaml
Large diffs are not rendered by default.
Oops, something went wrong.
771 changes: 0 additions & 771 deletions
771
...egration/challenges/memory/cassettes/test_memory_challenge_b/test_memory_challenge_b.yaml
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
604 changes: 590 additions & 14 deletions
604
tests/integration/goal_oriented/cassettes/test_browse_website/test_browse_website.yaml
Large diffs are not rendered by default.
Oops, something went wrong.
223 changes: 111 additions & 112 deletions
223
tests/integration/goal_oriented/cassettes/test_write_file/test_write_file.yaml
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import json | ||
import re | ||
from typing import Any, Dict, List | ||
|
||
REPLACEMENTS: List[Dict[str, str]] = [ | ||
{ | ||
"regex": r"\w{3} \w{3} {1,2}\d{1,2} \d{2}:\d{2}:\d{2} \d{4}", | ||
"replacement": "Tue Jan 1 00:00:00 2000", | ||
}, | ||
{ | ||
"regex": r"<selenium.webdriver.chrome.webdriver.WebDriver[^>]*>", | ||
"replacement": "", | ||
}, | ||
] | ||
|
||
|
||
def replace_message_content(content: str, replacements: List[Dict[str, str]]) -> str: | ||
for replacement in replacements: | ||
pattern = re.compile(replacement["regex"]) | ||
content = pattern.sub(replacement["replacement"], content) | ||
|
||
return content | ||
|
||
|
||
def replace_timestamp_in_request(request: Any) -> Any: | ||
try: | ||
if not request or not request.body: | ||
return request | ||
body = json.loads(request.body) | ||
except ValueError: | ||
return request | ||
|
||
if "messages" not in body: | ||
return request | ||
body[ | ||
"max_tokens" | ||
] = 0 # this field is incosistent between requests and not used at the moment. | ||
for message in body["messages"]: | ||
if "content" in message and "role" in message: | ||
if message["role"] == "system": | ||
message["content"] = replace_message_content( | ||
message["content"], REPLACEMENTS | ||
) | ||
|
||
request.body = json.dumps(body) | ||
return request | ||
|
||
|
||
def before_record_response(response: Dict[str, Any]) -> Dict[str, Any]: | ||
if "Transfer-Encoding" in response["headers"]: | ||
del response["headers"]["Transfer-Encoding"] | ||
return response | ||
|
||
|
||
def before_record_request(request: Any) -> Any: | ||
filtered_request = filter_hostnames(request) | ||
filtered_request_without_dynamic_data = replace_timestamp_in_request( | ||
filtered_request | ||
) | ||
return filtered_request_without_dynamic_data | ||
|
||
|
||
def filter_hostnames(request: Any) -> Any: | ||
allowed_hostnames: List[str] = [ | ||
"api.openai.com", | ||
"localhost:50337", | ||
] | ||
|
||
# Add your implementation here for filtering hostnames | ||
if any(hostname in request.url for hostname in allowed_hostnames): | ||
return request | ||
else: | ||
return None |