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

Commit

Permalink
Timeout (#58)
Browse files Browse the repository at this point in the history
<!-- This is an auto-generated comment: release notes by openai -->
### Summary by OpenAI

**Release Notes**

- New Feature: Added `timeoutMs` option to the `opts` object passed to
the `sendMessage` method in the `Bot` class.
- Refactor: Renamed the `turbo` property to `api`.
- Refactor: Assigned the result of calling `this.api.sendMessage` to the
`response` variable instead of `this.turbo.sendMessage`.
- Chore: Added logging statements for debugging purposes. 

These changes improve the functionality and maintainability of the
codebase.
<!-- end of auto-generated comment: release notes by openai -->
  • Loading branch information
harjotgill authored Mar 19, 2023
1 parent a024c41 commit ba574b3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
12 changes: 7 additions & 5 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 7 additions & 5 deletions src/bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ export type Ids = {
}

export class Bot {
private turbo: openai.ChatGPTAPI | null = null // not free
private api: openai.ChatGPTAPI | null = null // not free

private options: optionsJs.Options

constructor(options: optionsJs.Options) {
this.options = options
if (process.env.OPENAI_API_KEY) {
this.turbo = new openai.ChatGPTAPI({
this.api = new openai.ChatGPTAPI({
systemMessage: options.system_message,
apiKey: process.env.OPENAI_API_KEY,
debug: options.debug,
Expand Down Expand Up @@ -58,13 +58,15 @@ export class Bot {
}

let response: openai.ChatMessage | null = null
if (this.turbo) {
const opts: openai.SendMessageOptions = {}
if (this.api) {
const opts: openai.SendMessageOptions = {
timeoutMs: 90000
}
if (ids.parentMessageId) {
opts.parentMessageId = ids.parentMessageId
}
response = await this.turbo.sendMessage(message, opts)
try {
response = await this.api.sendMessage(message, opts)
const end = Date.now()
core.info(`response: ${JSON.stringify(response)}`)
core.info(`openai response time: ${end - start} ms`)
Expand Down

0 comments on commit ba574b3

Please sign in to comment.