Skip to content

Commit d485818

Browse files
authored
Merge pull request #588 from linear-b/add-role-option
added role to askAI plugin + examples
2 parents a8555b2 + 1f8d7c7 commit d485818

File tree

6 files changed

+27
-27
lines changed

6 files changed

+27
-27
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: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
* @module askAI
33
* @description A gitStream plugin to interact with AI models. Currently works with `ChatGPR-4o-mini`.
44
* @param {Object} context - The context that will be attached to the prompt .
5+
* @param {string} role - Role instructions for the conversation.
56
* @param {string} prompt - The prompt string.
67
* @param {Object} token - The token to the AI model.
78
* @returns {Object} Returns the response from the AI model.
@@ -82,8 +83,8 @@ const buildContextForGPT = context => {
8283
return context;
8384
};
8485

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

8889
if (process.env[cacheKey]) {
8990
return callback(null, process.env[cacheKey]);
@@ -103,19 +104,17 @@ const askAI = async (context, prompt, token, callback) => {
103104
body: JSON.stringify({
104105
model: 'gpt-4o-2024-08-06',
105106
messages: [
107+
...(role ?
108+
[
109+
{
110+
role: 'system',
111+
content: `You are a ${role}. Answer only to the request, without any introductory or conclusion text.`
112+
}]
113+
: []),
106114
{
107-
role: 'system',
108-
content: 'You are a code reviewer.'
109-
},
110-
{
111-
role: 'system',
115+
role: 'user',
112116
content: JSON.stringify(formattedContext)
113117
},
114-
{
115-
role: 'assistant',
116-
content:
117-
'You are code reviewer for a project. please answer without introductory phrases.'
118-
},
119118
{ role: 'user', content: prompt }
120119
],
121120
max_tokens: maxTokens

plugins/filters/askAI/reference.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,15 @@ A gitStream plugin to interact with AI models. Currently works with `ChatGPR-4o-
55

66
![Example PR description](screenshots/askAI-describe-PR.png)
77

8-
**Returns**: <code>Object</code> - Returns the response from the AI model
8+
**Returns**: <code>Object</code> - Returns the AI-generated response based on the provided context and prompt.
99
**License**: MIT
1010

11-
| Param | Type | Description |
12-
| ------- | -------- | ----------------------------------------------- |
13-
| context | `Object` | The context that will be attached to the prompt |
14-
| prompt | `string` | The prompt string |
15-
| token | `Object` | The token to the AI model |
11+
| Param | Type | Description |
12+
| ------- | -------- | ------------------------------------------------------------------------------------------------------------------ |
13+
| context | `Object` | The context that needs to be sent to the AI model for analysis. |
14+
| role | `string` | Free text. If not empty, Defines the role or persona for the AI to adopt while generating the response. |
15+
| prompt | `string` | The specific request or question you want the AI to respond to, after the context has been provided. |
16+
| token | `Object` | The token to the AI model |
1617

1718

1819
**Example**
@@ -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)