@docupace/pipeline 1.0.0-alpha.60 → 1.0.0-alpha.62

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@docupace/pipeline",
3
- "version": "1.0.0-alpha.60",
3
+ "version": "1.0.0-alpha.62",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -16,6 +16,7 @@
16
16
  "dependencies": {
17
17
  "commander": "^12.1.0",
18
18
  "js-yaml": "^4.1.0",
19
+ "openai": "^4.76.3",
19
20
  "zx": "^8.2.4"
20
21
  },
21
22
  "devDependencies": {
@@ -4,6 +4,8 @@ import { $ } from 'zx';
4
4
  import path from 'path';
5
5
  import {validateChangesets} from "./validate.js";
6
6
  import fs from 'fs';
7
+ import { Configuration, OpenAIApi } from "openai";
8
+
7
9
 
8
10
  const program = new Command();
9
11
 
@@ -143,38 +145,65 @@ program
143
145
  const summary = jiraTicketData.fields.summary;
144
146
  console.log(`Jira ticket summary: ${summary}`);
145
147
 
146
- // Step 4: Call OpenAI to determine change type
147
- const openAiApiKey = process.env.OPENAI_API_KEY;
148
- const openAiResponse = await fetch('https://api.openai.com/v1/assistants/asst_ronjCuCINK5pjLusTB9XCGYG/completions', {
149
- method: 'POST',
150
- headers: {
151
- Authorization: `Bearer ${openAiApiKey}`,
152
- 'Content-Type': 'application/json',
153
- },
154
- body: JSON.stringify({
155
- schema: {
156
- name: 'change_request',
157
- strict: true,
158
- schema: {
159
- type: 'object',
160
- properties: {
161
- change_type: { type: 'string', enum: ['patch', 'minor'] },
162
- summary: { type: 'string' },
163
- jira_ticket_id: { type: 'string' },
164
- },
165
- required: ['change_type', 'summary', 'jira_ticket_id'],
166
- additionalProperties: false,
167
- },
148
+ // Step 4: Call OpenAI API to determine change type
149
+ const openAiConfiguration = new Configuration({
150
+ apiKey: process.env.OPENAI_API_KEY,
151
+ });
152
+ const openai = new OpenAIApi(openAiConfiguration);
153
+
154
+ const openAiResponse = await openai.createChatCompletion({
155
+ model: "gpt-4",
156
+ messages: [
157
+ {
158
+ role: "system",
159
+ content: `Process JSON from a Jira ticket to generate simple maximum 2 sentence release note for the ticket and determine the change type for bug it should be a patch for new feature it should be a minor change`,
168
160
  },
169
- data: jiraTicketData,
170
- }),
161
+ {
162
+ role: "user",
163
+ content: `Schema:
164
+ {
165
+ "name": "change_request",
166
+ "strict": true,
167
+ "schema": {
168
+ "type": "object",
169
+ "properties": {
170
+ "change_type": {
171
+ "type": "string",
172
+ "description": "The type of change requested, either a patch or minor update.",
173
+ "enum": [
174
+ "patch",
175
+ "minor"
176
+ ]
177
+ },
178
+ "summary": {
179
+ "type": "string",
180
+ "description": "A brief summary of the change being requested."
181
+ },
182
+ "jira_ticket_id": {
183
+ "type": "string",
184
+ "description": "The ID of the related Jira ticket associated with this change request."
185
+ }
186
+ },
187
+ "required": [
188
+ "change_type",
189
+ "summary",
190
+ "jira_ticket_id"
191
+ ],
192
+ "additionalProperties": false
193
+ }
194
+ }`,
195
+ },
196
+ {
197
+ role: "user",
198
+ content: jiraTicketData,
199
+ },
200
+ ],
171
201
  });
172
202
 
173
- if (!openAiResponse.ok) {
174
- throw new Error(`Failed to call OpenAI assistant. Status: ${openAiResponse.status}`);
175
- }
176
- const openAiData = await openAiResponse.json();
177
- const { change_type } = openAiData.result;
203
+ const assistantResponse = openAiResponse.data.choices[0].message.content;
204
+ const parsedResponse = JSON.parse(assistantResponse);
205
+
206
+ const { change_type } = parsedResponse;
178
207
  console.log(`Determined change type: ${change_type}`);
179
208
 
180
209
  // Step 5: Create a changeset using pnpm