Skip to content

Commit

Permalink
added /docs command for generating doc links from tags (using openai)
Browse files Browse the repository at this point in the history
  • Loading branch information
GhomKrosmonaute committed Oct 30, 2024
1 parent c3bbb15 commit 402a96a
Show file tree
Hide file tree
Showing 4 changed files with 116 additions and 32 deletions.
43 changes: 14 additions & 29 deletions package-lock.json

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

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
"ghom-eval": "^1.1.3",
"ghom-prettify": "^3.0.0",
"knex": "^3.0.1",
"openai": "^4.28.0",
"openai": "^4.68.4",
"pg": "^8.13.0",
"prettier": "^3.2.5",
"regex-parser": "^2.2.11",
Expand Down Expand Up @@ -126,4 +126,4 @@
"@types/pg": "^8.11.10",
"through2": "^4.0.2"
}
}
}
77 changes: 76 additions & 1 deletion src/namespaces/openai.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export async function generateThreadHint(
name:
message.author.id === threadOwner.id
? "The member we help"
: message.author.username.replace(/\s/g, "-"),
: `Another helper (${message.author.username.replace(/\s/g, "-")})`,
content: message.content,
})),
{
Expand All @@ -102,3 +102,78 @@ export async function generateThreadHint(

return hint.slice(0, 2000)
}

/**
* Demande à ChatGPT de poster une liste des liens vers des pages de documentation à propos des tags renseignés. <br>
* La liste doit être en markdown et aussi longue que ChatGPT le veut. <br>
* Les sources des liens doivent venir de ces sites et être en français si possible : <br>
* - https://developer.mozilla.org/fr/
* - https://www.typescriptlang.org/fr/docs/
* - https://fr.react.dev/reference/react/
* - https://nuxt.com/docs/
* - https://fr.vuejs.org/
* - https://discord.js.org/docs/packages/discord.js/
* - https://nodejs.org/docs/
* - https://svelte.dev/docs/
* - https://nextjs.org/docs/
* - https://www.electronjs.org/docs/
* - https://www.mongodb.com/docs/
* - https://www.postgresql.org/docs/
* - https://www.npmjs.com/ (pour les readme)
* - https://github.com/
* etc
*/
export async function generateDocURLList(tags: string): Promise<string> {
if (env.BOT_MODE === "test")
throw new Error("OpenAI is not available in test mode")

const response = await openai.chat.completions.create({
messages: [
{
role: "system",
content: `
We are in a JavaScript developer helping Discord server.
You are a helping bot on this Discord server.
Your role is to generate a list of links to documentation pages about the tags provided.
The list must be in markdown and as long as you want.
La liste ne doit pas être trop longue, elle doit être lisible dans un message Discord.
Each returned link must be on a new line and wrapped in <>. Example: <https://example.com>
Tu dois aussi ranger les liens par ordre d'importance et les grouper par tag relatif. Exemple:
### Tag 1
- <https://example.com>
- <https://example.com>
### Tag 2
- <https://example.com>
The sources of the links must come from these sites and be in French if possible:
- https://developer.mozilla.org/fr/
- https://www.typescriptlang.org/fr/docs/
- https://fr.react.dev/reference/react/
- https://nuxt.com/docs/
- https://fr.vuejs.org/
- https://discord.js.org/docs/packages/discord.js/
- https://nodejs.org/docs/
- https://svelte.dev/docs/
- https://nextjs.org/docs/
- https://www.electronjs.org/docs/
- https://www.mongodb.com/docs/
- https://www.postgresql.org/docs/
- https://www.npmjs.com/ (for readme)
- https://github.com/
etc (add more if you need)
`,
},
{
role: "user",
content: `Tags: ${tags}`,
},
],
max_tokens: 1500,
model: "gpt-3.5-turbo",
})

const list = response.choices[0].message.content

if (!list) throw new Error("An error occurred while generating the list")

return list.slice(0, 2000)
}
24 changes: 24 additions & 0 deletions src/slash/docs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import * as app from "#app"

export default new app.SlashCommand({
name: "docs",
description: "Send doc links for the provided tags",
guildOnly: true,
userPermissions: ["ManageMessages"],
build: (builder) =>
builder.addStringOption((option) =>
option
.setName("tags")
.setDescription("The tags to search for (separated by commas)")
.setAutocomplete(true)
.setRequired(true),
),
async run(interaction) {
await interaction.deferReply()

const tags = interaction.options.getString("tags") as string
const links = await app.generateDocURLList(tags)

await interaction.editReply(links)
},
})

0 comments on commit 402a96a

Please sign in to comment.