-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from langx:xuelink/issue6
Add Appwrite Functionality for LangX Copilot with POST Request Support
- Loading branch information
Showing
8 changed files
with
167 additions
and
26 deletions.
There are no files selected for viewing
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 |
---|---|---|
|
@@ -130,4 +130,4 @@ dist | |
.pnp.* | ||
|
||
# instructions file | ||
/utils/instructions.js | ||
instructions.js |
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,88 @@ | ||
# :robot: LangX Copilot | ||
|
||
## Discord Bot Documentation | ||
|
||
LangX Copilot is an innovative AI-powered tool designed to enhance your language learning journey. This feature-rich platform offers personalized feedback to improve your language skills in real-time. LangX Copilot ensures your privacy while providing corrections and explanations directly to you. | ||
|
||
## Demo | ||
|
||
You can try out LangX Copilot in the [#copilot channel](https://discord.langx.io) on Discord. | ||
|
||
![Example](../assets/example.png) | ||
|
||
## Features | ||
|
||
- **Personalized Feedback**: Get real-time corrections and explanations to enhance your language learning. | ||
- **Grammar Correction**: Automatically corrects grammar mistakes and provides detailed explanations. | ||
- **Privacy Focused**: Feedback is provided confidentially, ensuring your privacy is maintained. | ||
- **Supports Multiple Languages**: Not limited to English, LangX Copilot supports various languages for grammar correction. | ||
|
||
## Getting Started | ||
|
||
### Prerequisites | ||
|
||
- Node.js (version 18 or later) | ||
- npm (Node Package Manager) | ||
- Cloudflare account with Workers enabled | ||
- Discord account and bot set up in the Discord Developer Portal | ||
|
||
### Installation | ||
|
||
1. **Clone the repository**: | ||
|
||
```sh | ||
git clone https://github.com/langx/copilot.git | ||
cd copilot | ||
``` | ||
|
||
2. **Install dependencies**: | ||
|
||
```sh | ||
npm install | ||
``` | ||
|
||
3. **Copy `.env` file** with the following environment variables: | ||
|
||
```sh | ||
cp .env.sample .env | ||
``` | ||
|
||
4. **Fill in the environment variables** in the `.env` file: | ||
|
||
```sh | ||
DISCORD_BOT_TOKEN=your_discord_token | ||
DISCORD_CLIENT_ID=your_discord_client_id | ||
GEMINI_API_KEY=your_gemini_api_key | ||
``` | ||
|
||
5. **Set up the system instructions:** | ||
|
||
```sh | ||
cp instructions.js.sample instructions.js | ||
``` | ||
|
||
Open the `instructions.js` file in your preferred text editor and edit the `systemInstruction` and `chatHistory` constant to include your own instructions. | ||
|
||
6. **Run the application**: | ||
|
||
```sh | ||
npm start discord | ||
``` | ||
|
||
7. **Deploy the Bot (Optional)**: | ||
|
||
```sh | ||
npm i pm2 -g | ||
node discord/registerCommands.js | ||
pm2 start discord/bot.js --name copilot | ||
``` | ||
|
||
## Contributing | ||
|
||
Feel free to contribute to this project and help us improve LangX Copilot. You can contribute by opening a PR or creating an issue easily. | ||
|
||
We welcome all contributions, including bug fixes, new features, and improvements to the documentation. | ||
|
||
## License | ||
|
||
This project is licensed under BSD 3-Clause License. See the [LICENSE](LICENSE) file for more details. |
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
File renamed without changes.
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,46 @@ | ||
import fs from "fs"; | ||
import { systemInstruction, chatHistory } from "./instructions.js"; | ||
|
||
const envFilePath = new URL(".env", import.meta.url); | ||
let envContent = ""; | ||
|
||
try { | ||
// Read the existing .env file content | ||
envContent = fs.readFileSync(envFilePath, "utf8"); | ||
} catch (error) { | ||
if (error.code !== "ENOENT") { | ||
throw error; | ||
} | ||
} | ||
|
||
// Convert the instructions to an environment variable format | ||
const systemInstructionValue = systemInstruction | ||
.replace(/'/g, "\\'") | ||
.replace(/\n/g, "\\n"); | ||
const chatHistoryValue = JSON.stringify(chatHistory) | ||
.replace(/'/g, "\\'") | ||
.replace(/\n/g, "\\n"); | ||
|
||
const systemInstructionEnv = `SYSTEM_INSTRUCTION='${systemInstructionValue}'`; | ||
const chatHistoryEnv = `CHAT_HISTORY='${chatHistoryValue}'`; | ||
|
||
// Function to update or add environment variable in .env content | ||
const updateEnvVariable = (content, variable, value) => { | ||
const regex = new RegExp(`^${variable}=.*$`, "m"); | ||
if (regex.test(content)) { | ||
return content.replace(regex, value); | ||
} else { | ||
return content + "\n" + value; | ||
} | ||
}; | ||
|
||
// Update or append the variables | ||
envContent = updateEnvVariable( | ||
envContent, | ||
"SYSTEM_INSTRUCTION", | ||
systemInstructionEnv | ||
); | ||
envContent = updateEnvVariable(envContent, "CHAT_HISTORY", chatHistoryEnv); | ||
|
||
// Write the updated .env file | ||
fs.writeFileSync(envFilePath, envContent, { flag: "w" }); |