forked from cocktailpeanut/dalai
-
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 cocktailpeanut#199 from keldenl/soft-prompts
[Web-UI] Add support for prompt templates via UI dropdown
- Loading branch information
Showing
9 changed files
with
469 additions
and
240 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 |
---|---|---|
@@ -1,25 +1,72 @@ | ||
const express = require('express') | ||
const os = require("os"); | ||
const http = require('http') | ||
const path = require('path') | ||
const os = require('os') | ||
const fs = require('fs') | ||
const Dalai = require("../../index") | ||
const app = express() | ||
const httpServer = http.Server(app); | ||
const start = (port, home) => { | ||
const dalai = new Dalai(home) | ||
dalai.http(httpServer) | ||
app.use(express.static(path.resolve(__dirname, 'public'))) | ||
app.use(express.json()); | ||
app.use(express.urlencoded({ extended: true })); | ||
app.set('view engine', 'ejs'); | ||
app.set('views', path.resolve(__dirname, "views")) | ||
app.get("/", (req, res) => { | ||
res.render("index", { | ||
threads: os.cpus().length | ||
const dalai = new Dalai(home) | ||
dalai.http(httpServer) | ||
app.use(express.static(path.resolve(__dirname, 'public'))) | ||
app.use(express.json()); | ||
app.use(express.urlencoded({ extended: true })); | ||
app.set('view engine', 'ejs'); | ||
app.set('views', path.resolve(__dirname, "views")) | ||
app.get("/", (req, res) => { | ||
res.render("index") | ||
}) | ||
|
||
const defaultDir = path.join(__dirname, "prompts"); | ||
const customDir = path.join(os.homedir(), "dalai", "config", "prompts"); | ||
|
||
if (!fs.existsSync(customDir)) { | ||
fs.mkdirSync(customDir, { recursive: true }); | ||
console.log(`Created custom directory: ${customDir}`); | ||
} | ||
|
||
app.get("/prompts", (req, res) => { | ||
let prompts = []; | ||
|
||
const filesToPrompts = (files, directory, editable) => | ||
files.flatMap((file) => { | ||
const filePath = path.join(directory, file); | ||
const stats = fs.statSync(filePath, "utf8"); | ||
|
||
// Filter out directories and non .txt files | ||
if (!stats.isFile() || !file.endsWith('.txt')) { | ||
return [] | ||
} | ||
const promptName = path.basename(file, ".txt"); | ||
const promptValue = fs.readFileSync(filePath, "utf8"); | ||
return { name: promptName, value: promptValue, editable }; | ||
}); | ||
|
||
// Read default prompts | ||
fs.readdir(defaultDir, (err, files) => { | ||
if (err) { | ||
console.error(err); | ||
return res.status(500).json({ error: "Internal server error" }); | ||
} | ||
prompts = filesToPrompts(files, defaultDir, false); | ||
|
||
// Read custom prompts | ||
fs.readdir(customDir, (err, files) => { | ||
if (err) { | ||
console.error(err); | ||
return res.status(500).json({ error: "Internal server error" }); | ||
} | ||
prompts = prompts.concat(filesToPrompts(files, customDir, true)); | ||
res.json(prompts); | ||
}); | ||
}); | ||
}); | ||
|
||
|
||
|
||
httpServer.listen(port, () => { | ||
console.log(`Server running on https://localhost:${port}/`) | ||
}) | ||
}) | ||
httpServer.listen(port, () => { | ||
console.log(`Server running on https://localhost:${port}/`) | ||
}) | ||
} | ||
module.exports = start | ||
module.exports = start |
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,12 @@ | ||
Below is a dialog, where User interacts with AI. AI is helpful, kind, obedient, honest, and knows its own limits. | ||
|
||
Instruction | ||
Write the last AI response to complete the dialog. | ||
|
||
Dialog | ||
User: Hello, AI. | ||
AI: Hello! How can I assist you today? | ||
User: >PROMPT | ||
|
||
Response | ||
AI: |
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,2 @@ | ||
The expected response for a highly intelligent chatbot to ">PROMPT" is | ||
" |
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,6 @@ | ||
Below is an instruction that describes a task, paired with an input that provides further context. Write a response that appropriately completes the request. | ||
|
||
### Instruction: | ||
>PROMPT | ||
|
||
### Response: |
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,9 @@ | ||
Below is an instruction that describes a task, paired with an input that provides further context. Write a response that appropriately completes the request. | ||
|
||
### Instruction: | ||
>PROMPT | ||
|
||
### Input: | ||
>PROMPT | ||
|
||
### Response: |
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,9 @@ | ||
Below is an instruction that describes a task, paired with an input that provides further context. Write a response that appropriately completes the request. | ||
|
||
### Instruction: | ||
Rephrase the sentence. | ||
|
||
### Input: | ||
>PROMPT | ||
|
||
### Response: |
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,4 @@ | ||
Here is how a professional Translator accurately translates the following English text to a grammatically correct >LANGUAGE text: | ||
|
||
English: >PROMPT | ||
>LANGUAGE: |
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,11 @@ | ||
Tweet: 'I hate it when my phone battery dies.' | ||
Sentiment: Negative | ||
### | ||
Tweet: 'My day has been 👍' | ||
Sentiment: Positive | ||
### | ||
Tweet: 'This is the link to the article' | ||
Sentiment: Neutral | ||
### | ||
Tweet: '>PROMPT' | ||
Sentiment: |
Oops, something went wrong.