Skip to content

Commit

Permalink
Improved split to components
Browse files Browse the repository at this point in the history
Signed-off-by: Yoav Katz <[email protected]>
  • Loading branch information
yoavkatz committed Feb 9, 2025
1 parent cd57ea3 commit 0804a9c
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions examples/api_call_evaluation.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"reference_query": "curl -X GET 'https://petstore.swagger.io/v2/pets?tags=dogs&limit=5'",
},
{
"user_request": "Create a pet entry with name Rexy and rag dog. ",
"user_request": "Create a pet entry with name Rexy and tag dog. ",
"reference_query": 'curl -X POST -H "Content-Type: application/json" -d \'{"name": "Rexy", "tag": "dog"}\' https://petstore.swagger.io/v2/pets',
},
{
Expand Down Expand Up @@ -206,15 +206,21 @@ class CurlStrToListOfKeyValuePairs(FieldOperator):
"""

def process_value(self, text: str) -> List[Tuple[str, str]]:
import re

text = text.replace("%20", " ")
text = text.replace("'", "")
# text=re.sub(r"&pageSize=\d+", "", text)

splits = text.split("?")
split_command = re.split(r"((?=GET|POST|DELETE)GET|POST|DELETE)", splits[0])
result = [
("command", split_command[0]),
("operation", split_command[1]),
("url", split_command[2]),
]
if len(splits) == 1:
return [("url", text)]
result = []
(url, params) = splits
result.append(("url", url))
return result
params = splits[1]
params_splits = params.split("&")
for param in params_splits:
key_value_splits = param.split("=")
Expand All @@ -224,7 +230,7 @@ def process_value(self, text: str) -> List[Tuple[str, str]]:
(key, value) = key_value_splits
value_splits = value.split(",")
if len(value_splits) == 1:
result.append((f"{key}", f"{value}"))
result.append((f"query_param_{key}", f"{value}"))

return result

Expand Down Expand Up @@ -265,7 +271,7 @@ def process_value(self, text: str) -> List[Tuple[str, str]]:

print("Example prompt:")

print(json.dumps(results.instance_scores[0]["source"], indent=4))
print(json.dumps(results.instance_scores[0]["source"], indent=4).replace("\\n", "\n"))

print("Instance Results:")
df = results.instance_scores.to_df(
Expand All @@ -278,6 +284,7 @@ def process_value(self, text: str) -> List[Tuple[str, str]]:
"score",
]
)

for index, row in df.iterrows():
print(f"Row {index}:")
for col_name, value in row.items():
Expand Down

0 comments on commit 0804a9c

Please sign in to comment.