mirror of
https://github.com/aljazceru/dev-gpt.git
synced 2025-12-21 07:34:20 +01:00
⏪ fix: self healing response parser
This commit is contained in:
@@ -1,6 +1,11 @@
|
||||
import os
|
||||
|
||||
import pytest
|
||||
|
||||
from dev_gpt.apis.gpt import GPTSession
|
||||
from dev_gpt.options.generate.generator import Generator
|
||||
from dev_gpt.options.generate.parser import self_healing_json_parser
|
||||
|
||||
|
||||
def create_code_block(with_backticks, asterisks, with_highlight_info, file_name, start_inline, content):
|
||||
code_block = f'''
|
||||
@@ -42,3 +47,21 @@ def test_extract_content_from_result(plain_text, expected1, expected2):
|
||||
parsed_result2 = Generator.extract_content_from_result(plain_text, 'test100.json', True, False)
|
||||
assert parsed_result2 == expected2
|
||||
|
||||
|
||||
def test_self_healing_json_parser(tmpdir):
|
||||
os.environ['VERBOSE'] = 'true'
|
||||
GPTSession(os.path.join(str(tmpdir), 'log.json'), model='gpt-3.5-turbo')
|
||||
json_response = '''\
|
||||
solutions.json
|
||||
```json
|
||||
{
|
||||
"1": "Change line 7 of microservice.py to 'pdf_file = input_dict['pdf_file'].encode('latin-1')' to convert the bytes object to a string before passing it to PyPDF2.",
|
||||
"2": "Change line 7 of microservice.py to 'pdf_file = input_dict['pdf_file'].decode('utf-8')' to decode the bytes object to a string before passing it to PyPDF2.",
|
||||
"3": "Change line 13 of test_microservice.py to 'input_dict = {"pdf_file": 'Sample PDF file content'.encode('latin-1')}' to encode the string to a bytes object before passing it to func.",
|
||||
"4": "Change line 13 of test_microservice.py to 'input_dict = {"pdf_file": 'Sample PDF file content'.decode('utf-8')}' to decode the string to a bytes object before passing it to func."
|
||||
}
|
||||
```'''
|
||||
parsed_json = self_healing_json_parser(json_response)
|
||||
for key in ['1', '2', '3', '4']:
|
||||
assert key in parsed_json
|
||||
assert 'Change' in parsed_json[key]
|
||||
Reference in New Issue
Block a user