-
-
Notifications
You must be signed in to change notification settings - Fork 244
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
328 additions
and
76 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,7 +15,7 @@ jobs: | |
|
||
strategy: | ||
matrix: | ||
node-version: [ 18.x ] | ||
node-version: [ 20.x ] | ||
|
||
steps: | ||
- name: Checkout | ||
|
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import eslint from "@eslint/js"; | ||
import tseslint from "typescript-eslint"; | ||
|
||
export default tseslint.config({ | ||
extends: [ | ||
eslint.configs.recommended, | ||
...tseslint.configs.recommended, | ||
], | ||
languageOptions: { | ||
parser: tseslint.parser, | ||
parserOptions: { | ||
projectService: true, | ||
tsconfigRootDir: import.meta.dirname, | ||
}, | ||
sourceType: "module", | ||
}, | ||
files: [ "src/**/*.ts" ], | ||
rules: { | ||
indent: [ "warn", 4 ], | ||
"linebreak-style": [ "warn", "unix" ], | ||
quotes: [ "warn", "double" ], | ||
semi: [ "warn", "always" ], | ||
"@typescript-eslint/no-namespace": "off", | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
/*! | ||
* @author TRACTION (iamtraction) | ||
* @copyright 2024 | ||
*/ | ||
import { ApplicationCommandType, MessageContextMenuCommandInteraction } from "discord.js"; | ||
import { Client, Command } from "@bastion/tesseract"; | ||
import Anthropic from "@anthropic-ai/sdk"; | ||
import OpenAI from "openai"; | ||
import { GoogleGenerativeAI } from "@google/generative-ai"; | ||
|
||
import Settings from "../utils/settings.js"; | ||
|
||
class SentimentCommand extends Command { | ||
constructor() { | ||
super({ | ||
type: ApplicationCommandType.Message, | ||
name: "Sentiment", | ||
description: "", | ||
owner: true, | ||
}); | ||
} | ||
|
||
public async exec(interaction: MessageContextMenuCommandInteraction<"cached">): Promise<unknown> { | ||
if (!interaction.targetMessage.content) return; | ||
|
||
const systemPrompt = "You are a helpful and informative AI assistant. You will analyze the given text and provide an assessment of its sentiment. Consider the overall tone, specific words and phrases used, and any contextual clues. Your response should be short, concise, objective, and informative."; | ||
const sentimentPrompt = `Please analyze the following text and provide a assessment of its sentiment: ${ interaction.targetMessage.content }`; | ||
|
||
// use ChatGPT if OpenAI API key is present | ||
if (((interaction.client as Client).settings as Settings).get("openai").apiKey) { | ||
const openai = new OpenAI({ | ||
apiKey: ((interaction.client as Client).settings as Settings).get("openai").apiKey, | ||
}); | ||
|
||
const response = await openai.chat.completions.create({ | ||
model: ((interaction.client as Client).settings as Settings).get("openai").model, | ||
messages: [ | ||
{ | ||
role: "system", | ||
content: systemPrompt, | ||
}, | ||
{ | ||
role: "user", | ||
content: sentimentPrompt, | ||
}, | ||
], | ||
max_tokens: ((interaction.client as Client).settings as Settings).get("openai").maxTokens, | ||
user: interaction.member.id, | ||
}); | ||
|
||
return await interaction.reply({ | ||
content: response.choices[0].message.content, | ||
ephemeral: true, | ||
}); | ||
} | ||
|
||
// use Gemini if Gemini API key is present | ||
if (((interaction.client as Client).settings as Settings).get("gemini").apiKey) { | ||
const gemini = new GoogleGenerativeAI(((interaction.client as Client).settings as Settings).get("gemini").apiKey); | ||
const geminiModel = gemini.getGenerativeModel({ | ||
model: ((interaction.client as Client).settings as Settings).get("gemini").model, | ||
systemInstruction: systemPrompt, | ||
generationConfig: { | ||
maxOutputTokens: ((interaction.client as Client).settings as Settings).get("gemini").maxOutputTokens, | ||
}, | ||
}); | ||
|
||
const result = await geminiModel.generateContent(sentimentPrompt); | ||
|
||
return await interaction.reply({ | ||
content: result.response.text(), | ||
ephemeral: true, | ||
}); | ||
} | ||
|
||
// use Claude if Anthropic API key is present | ||
if (((interaction.client as Client).settings as Settings).get("anthropic").apiKey) { | ||
const anthropic = new Anthropic({ | ||
apiKey: ((interaction.client as Client).settings as Settings).get("anthropic").apiKey, | ||
}); | ||
|
||
const result = await anthropic.messages.create({ | ||
model: ((interaction.client as Client).settings as Settings).get("anthropic").model, | ||
system: systemPrompt, | ||
max_tokens: ((interaction.client as Client).settings as Settings).get("anthropic").maxTokens, | ||
messages: [ | ||
{ | ||
role: "user", | ||
content: [ | ||
{ | ||
type: "text", | ||
text: sentimentPrompt, | ||
}, | ||
], | ||
}, | ||
], | ||
metadata: { | ||
user_id: interaction.member.id, | ||
}, | ||
}); | ||
|
||
return await interaction.reply({ | ||
content: result.content[0].type === "text" && result.content[0].text, | ||
ephemeral: true, | ||
}); | ||
} | ||
} | ||
} | ||
|
||
export { SentimentCommand as Command }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/*! | ||
* @author TRACTION (iamtraction) | ||
* @copyright 2024 | ||
*/ | ||
import { ApplicationCommandType, MessageContextMenuCommandInteraction } from "discord.js"; | ||
import { Command } from "@bastion/tesseract"; | ||
// eslint-disable-next-line @typescript-eslint/no-require-imports | ||
import translate = require("@iamtraction/google-translate"); | ||
|
||
class TranslateCommand extends Command { | ||
constructor() { | ||
super({ | ||
type: ApplicationCommandType.Message, | ||
name: "Translate", | ||
description: "", | ||
}); | ||
} | ||
|
||
public async exec(interaction: MessageContextMenuCommandInteraction<"cached">): Promise<unknown> { | ||
if (!interaction.targetMessage.content) return; | ||
|
||
// fetch the translation | ||
const response = await translate(interaction.targetMessage.content, { to: "en" }); | ||
|
||
return await interaction.reply({ | ||
content: `${ response.text } | ||
-# Translated from ${ response.from.language.iso?.toUpperCase() } to English`, | ||
}); | ||
} | ||
} | ||
|
||
export { TranslateCommand as Command }; |
Oops, something went wrong.