-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Discord bot: Pythia model #2831
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
28d2e90
feat: inference system
MrlolDev bd110d4
fix: pre-commit
MrlolDev 7d107e5
fix: client from inference system
MrlolDev 1cf876e
Merge pull request #1 from LAION-AI/main
MrlolDev 48ca998
feat: default model on .env
MrlolDev f80596e
Merge branch 'main' of https://github.com/MrlolDev/Open-Assistant
MrlolDev 3e4c91c
ran pre-commit
yk e45727f
Merge branch 'LAION-AI:main' into main
MrlolDev 5ce6ed4
feat: added pythia model && improve model selector
MrlolDev 0cd7858
Fix pre-commit
olliestanley File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,45 @@ | ||
import { | ||
SlashCommandBuilder, | ||
ActionRowBuilder, | ||
StringSelectMenuBuilder, | ||
StringSelectMenuOptionBuilder, | ||
} from "discord.js"; | ||
import { createInferenceClient } from "../modules/inference/client.js"; | ||
import redis from "../modules/redis.js"; | ||
|
||
export default { | ||
data: { | ||
customId: "model", | ||
description: "Switch to another model.", | ||
}, | ||
async execute(interaction, client, userId) { | ||
if (interaction.user.id != userId) | ||
return interaction.reply({ | ||
content: "You don't have permission to do this.", | ||
ephemeral: true, | ||
}); | ||
// model selector | ||
let row = new ActionRowBuilder().addComponents( | ||
new StringSelectMenuBuilder() | ||
.setCustomId("modelselect") | ||
.setPlaceholder("Select a model") | ||
.setMinValues(1) | ||
.setMaxValues(1) | ||
.addOptions( | ||
new StringSelectMenuOptionBuilder() | ||
.setLabel("OA_SFT_Llama_30B") | ||
.setDescription("Llama (default)") | ||
.setValue("OA_SFT_Llama_30B"), | ||
new StringSelectMenuOptionBuilder() | ||
.setLabel("oasst-sft-4-pythia-12b") | ||
.setDescription("Pythia") | ||
.setValue("OpenAssistant/oasst-sft-4-pythia-12b-epoch-3.5") | ||
) | ||
); | ||
await interaction.reply({ | ||
content: "Select a model.", | ||
components: [row], | ||
ephemeral: true, | ||
}); | ||
}, | ||
}; |
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,28 @@ | ||
import { | ||
SlashCommandBuilder, | ||
ActionRowBuilder, | ||
StringSelectMenuBuilder, | ||
StringSelectMenuOptionBuilder, | ||
} from "discord.js"; | ||
import { createInferenceClient } from "../modules/inference/client.js"; | ||
import redis from "../modules/redis.js"; | ||
|
||
export default { | ||
data: { | ||
customId: "modelselect", | ||
description: "Switch to another model.", | ||
}, | ||
async execute(interaction, client) { | ||
// get selected value | ||
let model = interaction.values[0]; | ||
// set model | ||
await interaction.deferReply({ | ||
ephemeral: true, | ||
}); | ||
redis.set(`model_${interaction.user.id}`, model); | ||
await interaction.editReply({ | ||
content: `Model set to ${model}.`, | ||
ephemeral: true, | ||
}); | ||
}, | ||
}; |
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,75 @@ | ||
import { createInferenceClient } from "../modules/inference/client.js"; | ||
import { HfInference } from "@huggingface/inference"; | ||
const hf = new HfInference(process.env.HUGGINGFACE_TOKEN); | ||
|
||
export default async function chat( | ||
model, | ||
user, | ||
message, | ||
chatId?, | ||
parentId?, | ||
presets?, | ||
preset? | ||
) { | ||
if (model.includes("Llama")) { | ||
const OA = await createInferenceClient(user.username, user.id); | ||
if (!chatId) { | ||
let chat = await OA.create_chat(); | ||
chatId = chat.id; | ||
} | ||
let prompter_message = await OA.post_prompter_message({ | ||
chat_id: chatId, | ||
content: message, | ||
parent_id: parentId, | ||
}); | ||
|
||
let assistant_message = await OA.post_assistant_message({ | ||
chat_id: chatId, | ||
model_config_name: model, | ||
parent_id: prompter_message.id, | ||
sampling_parameters: presets[preset], | ||
}); | ||
return { assistant_message, OA }; | ||
} else { | ||
let result = await huggingface( | ||
model, | ||
`<|prompter|>${message}<|endoftext|>\n<|assistant|>` | ||
); | ||
if (result.error) { | ||
return { error: result.error }; | ||
} | ||
return { assistant_message: result.response }; | ||
} | ||
} | ||
|
||
export async function huggingface(model, input) { | ||
try { | ||
let oldText; | ||
let loop = true; | ||
while (loop) { | ||
let response = await hf.textGeneration({ | ||
model: model, | ||
inputs: input, | ||
}); | ||
let answer = response.generated_text.split("<|assistant|>")[1]; | ||
if (answer == oldText) { | ||
loop = false; | ||
} else { | ||
if (!oldText) { | ||
oldText = answer; | ||
input += answer; | ||
} else { | ||
oldText += answer; | ||
input += answer; | ||
} | ||
} | ||
} | ||
|
||
return { response: oldText }; | ||
} catch (err: any) { | ||
console.log(err); | ||
return { | ||
error: err.message, | ||
}; | ||
} | ||
} |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be best if the list of available models in the future would be requested at the inference-server (/models endpoint). It will be constantly changing .. you were probably irritated that so many are displayed in the staging environment .. but that's really only a "problem" in staging.