Skip to content

Commit

Permalink
chore: switch to text-davinci-003 model
Browse files Browse the repository at this point in the history
  • Loading branch information
tim-smart committed Apr 26, 2023
1 parent 5451367 commit cc95dea
Show file tree
Hide file tree
Showing 4 changed files with 133 additions and 7 deletions.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
},
"scripts": {
"build": "rm -rf dist && tsc",
"dev": "tsc-watch --onSuccess \"node --enable-source-maps dist/main.js\"",
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
Expand All @@ -17,6 +18,7 @@
"devDependencies": {
"@types/node": "^18.16.1",
"prettier": "^2.8.8",
"tsc-watch": "^6.0.0",
"typescript": "^5.0.4"
},
"dependencies": {
Expand Down
118 changes: 118 additions & 0 deletions pnpm-lock.yaml

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

9 changes: 7 additions & 2 deletions src/AutoThreads.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ export class NotValidMessageError extends Data.TaggedClass(
readonly reason: "non-default" | "from-bot" | "non-text-channel" | "disabled"
}> {}

const truncate = (str: string, len: number) =>
str.length > len ? str.substring(0, len - 3) + "..." : str

const make = Effect.gen(function* ($) {
const log = yield* $(Log.Log)
const openai = yield* $(OpenAI)
Expand Down Expand Up @@ -52,7 +55,7 @@ const make = Effect.gen(function* ($) {
),
Effect.flatMap(({ channel, title }) =>
rest.startThreadFromMessage(channel.id, message.id, {
name: title,
name: truncate(title, 100),
}),
),
Effect.flatMap(_ => _.json),
Expand All @@ -77,7 +80,9 @@ const make = Effect.gen(function* ($) {
NotValidMessageError: () => Effect.unit(),
DiscordRESTError: _ =>
"response" in _.error
? Effect.flatMap(_.error.response.json, log.info)
? Effect.flatMap(_.error.response.json, _ =>
Effect.logInfo(JSON.stringify(_, null, 2)),
)
: log.info(_.error),
}),
Effect.catchAllCause(Effect.logErrorCause),
Expand Down
11 changes: 6 additions & 5 deletions src/OpenAI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ const make = (params: OpenAIOptions) => {
call((_, signal) =>
_.createCompletion(
{
model: "text-curie-001",
model: "text-davinci-003",
prompt: `Create a short title summarizing the following text:
${prompt}
${prompt.split("\n")[0].trim()}
`,
temperature: 0.25,
Expand All @@ -51,9 +51,10 @@ ${prompt}
),
),
_ =>
Option.map(
Option.fromNullable(_.data.choices[0]?.text),
_ => _.trim().split("\n")[0],
Option.map(Option.fromNullable(_.data.choices[0]?.text), _ =>
_.trim()
.split("\n")[0]
.replace(/(^"|"$)/g, ""),
),
)

Expand Down

0 comments on commit cc95dea

Please sign in to comment.