Skip to content

Commit b4a1ee8

Browse files
committed
with cmd
1 parent 3641239 commit b4a1ee8

File tree

3 files changed

+71
-21
lines changed

3 files changed

+71
-21
lines changed

.github/actions/extract_error/action.yml

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,27 @@
11
name: 'Extract Error'
22
description: 'extract test error messaget to pull request comment'
33
inputs:
4-
error_filepath:
5-
description: 'error mesasge file path'
6-
required: true
74
openai_api_key:
85
description: 'OpenAI API Key'
96
required: true
7+
cmd:
8+
description: 'test cmd'
9+
required: true
1010

1111
runs:
1212
using: "composite"
1313
steps:
14+
- name: Run Test
15+
shell: bash
16+
run: |
17+
`${{ inputs.cmd }}` | tee /tmp/test_output.txt
18+
1419
- name: Generate Test Output Summary
1520
shell: bash
16-
if: github.event_name == 'pull_request'
21+
env:
22+
OPENAI_API_KEY: ${{ inputs.openai_api_key }}
1723
run: |
18-
OPENAI_API_KEY=${{ inputs.openai_api_key }} python .github/actions/extract_error/extract_error.py ${{ inputs.error_filepath }} /tmp/output.txt
24+
python .github/actions/extract_error/extract_error.py /tmp/test_output.txt /tmp/output.txt
1925
2026
- name: Get Test Output Summary
2127
shell: bash

.github/actions/extract_error/extract_error.py

Lines changed: 59 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,78 @@
11
import argparse
2+
import csv
23
import os
3-
from prompttrail.agent.templates import LinearTemplate
4+
from io import StringIO
5+
46
from prompttrail.agent.runners import CommandLineRunner
5-
from prompttrail.models.openai import OpenAIChatCompletionModel, OpenAIModelConfiguration, OpenAIModelParameters
7+
from prompttrail.agent.templates import LinearTemplate
8+
from prompttrail.agent.templates.openai import (
9+
OpenAIGenerateTemplate,
10+
OpenAIMessageTemplate,
11+
)
612
from prompttrail.agent.user_interaction import UserInteractionTextCLIProvider
13+
from prompttrail.models.openai import (
14+
OpenAIChatCompletionModel,
15+
OpenAIModelConfiguration,
16+
OpenAIModelParameters,
17+
)
718

819

920
def extract(error_message: str):
10-
return f"""# Error Summary
21+
template = LinearTemplate(
22+
[
23+
OpenAIMessageTemplate(
24+
role="system",
25+
content="""
26+
You're an AI assistant that helps software engineer to understand test error message.
27+
Your input is error message that emitted by test codes.
28+
Your output is the summary csv of the error message.
29+
Each line in the summary csv descributes each error in the error message.
30+
the summary csv first column indicates where the error occurred, second column is summary of error.
31+
You emit ONLY the summary csv. No explanation is needed.
32+
""",
33+
),
34+
OpenAIMessageTemplate(
35+
role="user",
36+
content=error_message,
37+
),
38+
OpenAIGenerateTemplate(role="assistant"),
39+
]
40+
)
41+
runner = CommandLineRunner(
42+
model=OpenAIChatCompletionModel(
43+
configuration=OpenAIModelConfiguration(
44+
api_key=os.environ.get("OPENAI_API_KEY", "")
45+
)
46+
),
47+
parameters=OpenAIModelParameters(model_name="gpt-3.5-turbo-0301"),
48+
template=template,
49+
user_interaction_provider=UserInteractionTextCLIProvider(),
50+
)
51+
state = runner.run()
52+
last_message_content = state.get_last_message().content
53+
# remove response message header
54+
csv_str = "\n".join(last_message_content.splitlines()[2:])
55+
with StringIO() as f:
56+
f.write(csv_str)
57+
f.seek(0)
58+
csv_content = list(csv.reader(f))
59+
content = "\n".join([f"| {row[0]} | {row[1]} |" for row in csv_content])
60+
return f"""# Error Summaries
1161
12-
TODO: impl summarization of error_message by PromptTail.
13-
error_mesasge len: {len(error_message)}
62+
| where | summary |
63+
| ----- | ------- |
64+
{content}
1465
"""
1566

1667

1768
def main() -> None:
1869
parser = argparse.ArgumentParser()
19-
parser.add_argument('error_filepath')
20-
parser.add_argument('output_filepath')
70+
parser.add_argument("error_filepath")
71+
parser.add_argument("output_filepath")
2172
args = parser.parse_args()
2273
with open(args.error_filepath) as f:
2374
error_message = f.read()
24-
with open(args.output_filepath, 'w') as f:
75+
with open(args.output_filepath, "w") as f:
2576
f.write(extract(error_message))
2677

2778

.github/workflows/test.yml

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,12 @@ jobs:
2929
run: flake8 --ignore=E121,E123,E126,E226,E24,E704,E203,W503,W504,E501,F401,F403 src tests examples
3030
- name: Run black
3131
run: black --check src examples tests
32-
- name: Run pytest
33-
run: pytest --cov=src --cov-report=xml tests > /tmp/test_output.txt
34-
env:
35-
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
36-
GOOGLE_CLOUD_API_KEY: ${{ secrets.GOOGLE_CLOUD_API_KEY }}
3732

3833
- name: Extract Error
3934
uses: ./.github/actions/extract_error
40-
if: failure()
4135
with:
42-
error_filepath: /tmp/test_output.txt
4336
openai_api_key: ${{ secrets.OPENAI_API_KEY }}
44-
37+
cmd: OPENAI_API_KEY=${{ secrets.OPENAI_API_KEY }} GOOGLE_CLOUD_API_KEY=${{ secrets.GOOGLE_CLOUD_API_KEY }} pytest --cov=src --cov-report=xml tests
4538
- name: Upload coverage reports to Codecov
4639
uses: codecov/codecov-action@v3
4740
env:

0 commit comments

Comments
 (0)