Skip to content
This repository was archived by the owner on Mar 6, 2024. It is now read-only.

Commit 74aa9b1

Browse files
authored
fetch latest desccription before updating (#26)
test comment <!-- This is an auto-generated comment: release notes by openai --> ### Summary by OpenAI **Release Notes** This pull request adds minor changes to the codebase to fetch the latest description before updating. The changes made are mostly related to removing unused code and simplifying function calls. No new features or bug fixes were introduced. <!-- end of auto-generated comment: release notes by openai -->
1 parent 468f076 commit 74aa9b1

File tree

5 files changed

+238
-224
lines changed

5 files changed

+238
-224
lines changed

dist/index.js

Lines changed: 48 additions & 37 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/bot.ts

Lines changed: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,94 +1,94 @@
1-
import "./fetch-polyfill.js";
1+
import './fetch-polyfill.js'
22

3-
import * as core from "@actions/core";
4-
import * as openai from "chatgpt";
5-
import * as optionsJs from "./options.js";
3+
import * as core from '@actions/core'
4+
import * as openai from 'chatgpt'
5+
import * as optionsJs from './options.js'
66

77
// define type to save parentMessageId and conversationId
88
export type Ids = {
9-
parentMessageId?: string;
10-
conversationId?: string;
11-
};
9+
parentMessageId?: string
10+
conversationId?: string
11+
}
1212

1313
export class Bot {
14-
private turbo: openai.ChatGPTAPI | null = null; // not free
14+
private turbo: openai.ChatGPTAPI | null = null // not free
1515

16-
private options: optionsJs.Options;
16+
private options: optionsJs.Options
1717

1818
constructor(options: optionsJs.Options) {
19-
this.options = options;
19+
this.options = options
2020
if (process.env.OPENAI_API_KEY) {
2121
this.turbo = new openai.ChatGPTAPI({
2222
systemMessage: options.system_message,
2323
apiKey: process.env.OPENAI_API_KEY,
2424
debug: options.debug,
2525
completionParams: {
26-
temperature: options.temperature,
27-
},
26+
temperature: options.temperature
27+
}
2828
// assistantLabel: " ",
2929
// userLabel: " ",
30-
});
30+
})
3131
} else {
3232
const err =
33-
"Unable to initialize the OpenAI API, both 'OPENAI_API_KEY' environment variable are not available";
34-
throw new Error(err);
33+
"Unable to initialize the OpenAI API, both 'OPENAI_API_KEY' environment variable are not available"
34+
throw new Error(err)
3535
}
3636
}
3737

3838
chat = async (message: string, ids: Ids): Promise<[string, Ids]> => {
39-
let new_ids: Ids = {};
40-
let response = "";
39+
let new_ids: Ids = {}
40+
let response = ''
4141
try {
42-
[response, new_ids] = await this.chat_(message, ids);
42+
;[response, new_ids] = await this.chat_(message, ids)
4343
} catch (e: any) {
44-
core.warning(`Failed to chat: ${e}, backtrace: ${e.stack}`);
44+
core.warning(`Failed to chat: ${e}, backtrace: ${e.stack}`)
4545
} finally {
46-
return [response, new_ids];
46+
return [response, new_ids]
4747
}
48-
};
48+
}
4949

5050
private chat_ = async (message: string, ids: Ids): Promise<[string, Ids]> => {
5151
if (!message) {
52-
return ["", {}];
52+
return ['', {}]
5353
}
5454
if (this.options.debug) {
55-
core.info(`sending to openai: ${message}`);
55+
core.info(`sending to openai: ${message}`)
5656
}
5757

58-
let response: openai.ChatMessage | null = null;
58+
let response: openai.ChatMessage | null = null
5959
if (this.turbo) {
60-
let opts: openai.SendMessageOptions = {};
60+
let opts: openai.SendMessageOptions = {}
6161
if (ids.parentMessageId) {
62-
opts.parentMessageId = ids.parentMessageId;
62+
opts.parentMessageId = ids.parentMessageId
6363
}
64-
response = await this.turbo.sendMessage(message, opts);
64+
response = await this.turbo.sendMessage(message, opts)
6565
try {
66-
core.info(`response: ${JSON.stringify(response)}`);
66+
core.info(`response: ${JSON.stringify(response)}`)
6767
} catch (e: any) {
6868
core.info(
69-
`response: ${response}, failed to stringify: ${e}, backtrace: ${e.stack}`,
70-
);
69+
`response: ${response}, failed to stringify: ${e}, backtrace: ${e.stack}`
70+
)
7171
}
7272
} else {
73-
core.setFailed("The OpenAI API is not initialized");
73+
core.setFailed('The OpenAI API is not initialized')
7474
}
75-
let response_text = "";
75+
let response_text = ''
7676
if (response) {
77-
response_text = response.text;
77+
response_text = response.text
7878
} else {
79-
core.warning("openai response is null");
79+
core.warning('openai response is null')
8080
}
8181
// remove the prefix "with " in the response
82-
if (response_text.startsWith("with ")) {
83-
response_text = response_text.substring(5);
82+
if (response_text.startsWith('with ')) {
83+
response_text = response_text.substring(5)
8484
}
8585
if (this.options.debug) {
86-
core.info(`openai responses: ${response_text}`);
86+
core.info(`openai responses: ${response_text}`)
8787
}
8888
const new_ids: Ids = {
8989
parentMessageId: response?.id,
90-
conversationId: response?.conversationId,
91-
};
92-
return [response_text, new_ids];
93-
};
90+
conversationId: response?.conversationId
91+
}
92+
return [response_text, new_ids]
93+
}
9494
}

0 commit comments

Comments
 (0)