Skip to content

Commit 45e4476

Browse files
committed
added role to askAI plugin + examples
1 parent 0ace09d commit 45e4476

File tree

6 files changed

+19
-20
lines changed

6 files changed

+19
-20
lines changed

docs/downloads/automation-library/integrations/askAI/askAI_CR.cm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ automations:
1515
args:
1616
comment: |
1717
# ✨ gitStream Review ✨
18-
{{ source | askAI("
19-
Review the PR code diff.
18+
{{ source | askAI("Code reviewer",
19+
"Review the PR code diff.
2020
- Identify bugs, security risks, and performance issues
2121
- Check for deprecated methods and style guide violations
2222
- Provide specific improvement suggestions based on the changes", env.OPEN_AI_TOKEN) | encode }}

docs/downloads/automation-library/integrations/askAI/askAI_summarize.cm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@ automations:
1515
args:
1616
comment: |
1717
# 📜 PR Summary 📜
18-
{{ source | askAI("
19-
Summarize the changes in this PR in bullet points.", env.OPEN_AI_TOKEN) | encode }}
18+
{{ source | askAI("Experienced developer",
19+
"Summarize the changes in this PR in bullet points.", env.OPEN_AI_TOKEN) | encode }}

docs/downloads/automation-library/integrations/askAI/askAI_tests.cm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ automations:
1515
args:
1616
comment: |
1717
# 🧪 Test Suggestions 🧪
18-
{{ source | askAI("
19-
Identify any new or modified functions without test coverage in this PR.
18+
{{ source | askAI("QA tester",
19+
"Identify any new or modified functions without test coverage in this PR.
2020
Suggest specific test cases to add, including edge cases.
2121
If all functions are covered, return 'No additional tests needed.'", env.OPEN_AI_TOKEN) | encode }}

plugins/filters/askAI/askAI.cm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ automations:
1313
- action: add-comment@v1
1414
args:
1515
comment: |
16-
{{ source | askAI("Based on the given context, search for new functions without tests and suggest the tests to add. If all functions are covered completely, return 'no tests to suggest.'", env.OPEN_AI_TOKEN) | encode }}
16+
{{ source | askAI("Experienced developer", "Summarize in simple terms the changes in this PR using bullet points.", env.OPEN_AI_TOKEN) | encode }}
1717

1818
generate_pr_desc_on_ask_ai_label:
1919
on:
@@ -24,4 +24,4 @@ automations:
2424
- action: add-comment@v1
2525
args:
2626
comment: |
27-
{{ source | askAI("Based on the given context, search for new functions without tests and suggest the tests to add. If all functions are covered completely, return 'no tests to suggest.'", env.OPEN_AI_TOKEN) | encode }}
27+
{{ source | askAI("qa tester", "Based on the given context, search for new functions without tests and suggest the tests to add. If all functions are covered completely, return 'no tests to suggest.'", env.OPEN_AI_TOKEN) | encode }}

plugins/filters/askAI/index.js

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ const buildContextForGPT = context => {
8282
return context;
8383
};
8484

85-
const askAI = async (context, prompt, token, callback) => {
85+
const askAI = async (context, role = '', prompt, token, callback) => {
8686
const cacheKey = `${__filename}${prompt}`;
8787

8888
if (process.env[cacheKey]) {
@@ -103,19 +103,17 @@ const askAI = async (context, prompt, token, callback) => {
103103
body: JSON.stringify({
104104
model: 'gpt-4o-2024-08-06',
105105
messages: [
106+
...(role ?
107+
[
108+
{
109+
role: 'system',
110+
content: `You are a ${role}. Answer only to the request, without any introductory or conclusion text.`
111+
}]
112+
: []),
106113
{
107-
role: 'system',
108-
content: 'You are a code reviewer.'
109-
},
110-
{
111-
role: 'system',
114+
role: 'user',
112115
content: JSON.stringify(formattedContext)
113116
},
114-
{
115-
role: 'assistant',
116-
content:
117-
'You are code reviewer for a project. please answer without introductory phrases.'
118-
},
119117
{ role: 'user', content: prompt }
120118
],
121119
max_tokens: maxTokens

plugins/filters/askAI/reference.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ A gitStream plugin to interact with AI models. Currently works with `ChatGPR-4o-
1111
| Param | Type | Description |
1212
| ------- | -------- | ----------------------------------------------- |
1313
| context | `Object` | The context that will be attached to the prompt |
14+
| role | `string` | Role instructions for the conversationThe |
1415
| prompt | `string` | The prompt string |
1516
| token | `Object` | The token to the AI model |
1617

@@ -21,5 +22,5 @@ A gitStream plugin to interact with AI models. Currently works with `ChatGPR-4o-
2122
The [`add-comment`](./automation-actions.md#add-comment) action automatically decodes encoded strings.
2223

2324
```yaml
24-
{{ source | askAI("Based on the given context, search for new functions without tests and suggest the tests to add. If all functions are covered completely, return 'no tests to suggest.'", env.OPEN_AI_TOKEN) | encode }}
25+
{{ source | askAI("QA tester", "Based on the given context, search for new functions without tests and suggest the tests to add. If all functions are covered completely, return 'no tests to suggest.'", env.OPEN_AI_TOKEN) | encode }}
2526
```

0 commit comments

Comments
 (0)