refactor: summarize error message without line number

This commit is contained in:
Florian Hönicke
2023-05-29 13:49:46 +02:00
parent 4252c175fe
commit 2924ef98f8
3 changed files with 17 additions and 5 deletions

View File

@@ -17,9 +17,8 @@ def boolean_parser(x):
return 'yes' in x.lower() return 'yes' in x.lower()
def json_parser(x): def json_parser(x):
if '```' in x: pattern = r'([\[\{].*[\]\}])'
pattern = r'([\[\{].+[\]\}])' x = re.findall(pattern, x, re.DOTALL)[-1]
x = re.findall(pattern, x, re.DOTALL)[-1]
return json.loads(x) return json.loads(x)
def self_healing_json_parser(original_json_string): def self_healing_json_parser(original_json_string):

View File

@@ -78,7 +78,8 @@ Description of the microservice:
) )
return microservice_description, test_description return microservice_description, test_description
def get_used_tools(self, microservice_description): @staticmethod
def get_used_tools(microservice_description):
return ask_gpt( return ask_gpt(
generate_used_tools_prompt, generate_used_tools_prompt,
self_healing_json_parser, self_healing_json_parser,

View File

@@ -1,5 +1,7 @@
import os import os
from dev_gpt.apis.gpt import GPTSession
from dev_gpt.options.generate.pm.pm import PM
from dev_gpt.options.generate.tools.tools import get_available_tools from dev_gpt.options.generate.tools.tools import get_available_tools
@@ -10,4 +12,14 @@ def test_all_tools():
def test_no_search(): def test_no_search():
os.environ['GOOGLE_API_KEY'] = '' os.environ['GOOGLE_API_KEY'] = ''
tool_lines = get_available_tools().split('\n') tool_lines = get_available_tools().split('\n')
assert len(tool_lines) == 1 assert len(tool_lines) == 1
def test_get_used_tools(tmpdir):
os.environ['VERBOSE'] = 'true'
GPTSession(os.path.join(str(tmpdir), 'log.json'), model='gpt-3.5-turbo')
used_tools = PM.get_used_tools('''\
This microservice listens for incoming requests and generates a fixed output of "test" upon receiving a request. \
The response sent back to the requester includes the output as a string parameter. \
No specific request parameters are required, and the response always follows a fixed schema with a single "output" parameter.'''
)
assert used_tools == []