refactor: Add Cohere models to ModelList and names.ts

This commit is contained in:
kwaroran
2024-05-27 13:23:42 +09:00
parent 73eec2f018
commit 7f3434f8e4
4 changed files with 95 additions and 0 deletions

View File

@@ -115,6 +115,10 @@
<button class="p-2 hover:text-green-500" on:click={() => {changeModel('novellist')}}>SuperTrin</button>
<button class="p-2 hover:text-green-500" on:click={() => {changeModel('novellist_damsel')}}>Damsel</button>
</Arcodion>
<Arcodion name="Cohere">
<button class="p-2 hover:text-green-500" on:click={() => {changeModel('cohere-command-r')}}>Command R</button>
<button class="p-2 hover:text-green-500" on:click={() => {changeModel('cohere-command-r-plus')}}>Command R Plus</button>
</Arcodion>
<Arcodion name="NovelAI">
<button class="hover:bg-selected px-6 py-2 text-lg" on:click={() => {changeModel('novelai')}}>NovelAI Clio</button>
<button class="hover:bg-selected px-6 py-2 text-lg" on:click={() => {changeModel('novelai_kayra')}}>NovelAI Kayra</button>

View File

@@ -103,6 +103,10 @@ export function getModelName(name:string){
return 'Gemini 1.5 Flash'
case 'ollama-hosted':
return 'Ollama'
case 'cohere-command-r':
return 'Cohere Command-R'
case 'cohere-command-r-plus':
return 'Cohere Command-R Plus'
default:
if(name.startsWith("horde:::")){
const split = name.split(":::")
@@ -124,6 +128,9 @@ export function getModelShortName(model:string){
if(model.startsWith("gpt35")){
return "GPT-3.5"
}
if(model.startsWith("cohere-")){
return model.replace("cohere-", "")
}
if(model.startsWith("gpt4")){
return "GPT-4"
}

View File

@@ -1527,6 +1527,89 @@ export async function requestChatDataMain(arg:requestDataArgument, model:'model'
result: readableStream
}
}
case 'cohere-command-r':
case 'cohere-command-r-plus':{
const modelName = aiModel.replace('cohere-', '')
let lastChatPrompt = ''
let preamble = ''
const lastChat = formated[formated.length-1]
if(lastChat.role === 'user'){
lastChatPrompt = lastChat.content
formated.pop()
}
const firstChat = formated[0]
if(firstChat.role === 'system'){
preamble = firstChat.content
formated.shift()
}
let body = {
message: lastChatPrompt,
chat_history: formated.map((v) => {
if(v.role === 'assistant'){
return {
role: 'CHATBOT',
content: v.content
}
}
if(v.role === 'system'){
return {
role: 'SYSTEM',
content: v.content
}
}
if(v.role === 'user'){
return {
role: 'USER',
content: v.content
}
}
return null
}).filter((v) => v !== null),
temperature: temperature,
k: db.top_k,
p: (db.top_p > 0.99) ? 0.99 : (db.top_p < 0.01) ? 0.01 : db.top_p,
presence_penalty: arg.PresensePenalty || (db.PresensePenalty / 100),
frequency_penalty: arg.frequencyPenalty || (db.frequencyPenalty / 100),
}
if(preamble){
// @ts-ignore
body.preamble = preamble
}
const res = await globalFetch('https://api.cohere.com/v1/chat', {
method: "POST",
headers: {
"Authorization": "Bearer " + db.cohereAPIKey,
"Content-Type": "application/json"
},
body: body
})
if(!res.ok){
return {
type: 'fail',
result: JSON.stringify(res.data)
}
}
const result = res.data.text
if(!result){
return {
type: 'fail',
result: JSON.stringify(res.data)
}
}
return {
type: 'success',
result: result
}
}
default:{
if(raiModel.startsWith('claude-3')){
let replacerURL = (aiModel === 'reverse_proxy') ? (db.forceReplaceUrl) : ('https://api.anthropic.com/v1/messages')

View File

@@ -667,6 +667,7 @@ export interface Database{
templateDefaultVariables:string
hypaAllocatedTokens:number
hypaChunkSize:number
cohereAPIKey:string
}
export interface customscript{