Last active
September 18, 2024 06:16
-
-
Save freehuntx/331b1ce469b8be6d342c41054140602c to your computer and use it in GitHub Desktop.
KoboldCpp random chat
This file contains hidden or 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
const fetchRandomChar = async () => { | |
const corsPrefix = 'https://corsproxy.io/?' | |
const count = await fetch(corsPrefix + encodeURI('https://api.chub.ai/search?search=&first=1&page=1&nsfw=true')) | |
.then(res => res.json()) | |
.then(res => res.data.count) | |
const randId = Math.floor(Math.random() * count) | |
const project = await fetch(corsPrefix + encodeURI(`https://api.chub.ai/search?search=&first=1&page=${randId}&nsfw=true`)) | |
.then(res => res.json()) | |
.then(res => res.data.nodes[0]) | |
const character = await fetch(corsPrefix + encodeURI(`https://api.chub.ai/api/v4/projects/${project.id}/repository/files/raw%252Ftavern_raw.json/raw?ref=main&response_type=json`)) | |
.then(res => res.json()) | |
.then(res => res.data) | |
return character | |
} | |
setInterval(() => { | |
if (!document.querySelector('#random-char-styles')) { | |
const style = document.createElement('style') | |
style.id = 'random-char-styles' | |
style.innerHTML = ` | |
.AI-portrait-image:hover { | |
background-size: contain; | |
position: absolute; | |
scale: 4; | |
} | |
` | |
document.body.appendChild(style) | |
} | |
const sysMsgEl = document.querySelector('.chat_received_withd_msg') || document.querySelector('end_of_context_koboldlite_internal sys_context_koboldlite_internal') | |
if (!sysMsgEl) return | |
if (sysMsgEl.querySelector('button')) return | |
const btn = document.createElement('button') | |
btn.innerHTML = 'Random char' | |
sysMsgEl.appendChild(btn) | |
btn.onclick = async () => { | |
btn.innerHTML = 'Loading...' | |
btn.disabled = true | |
const character = await fetchRandomChar() | |
window.foo = character | |
console.error(character) | |
aestheticInstructUISettings.AI_portrait = character.avatar ?? 'default' | |
load_tavern_obj(character) | |
} | |
}, 1000) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment