Add DeveloperRole flag and update role handling in OpenAIChatExtra

This commit is contained in:
Kwaroran
2024-12-18 03:37:41 +09:00
parent 6d3fdadf55
commit f09cb1bd69
2 changed files with 16 additions and 3 deletions

View File

@@ -15,7 +15,8 @@ export enum LLMFlags{
mustStartWithUserInput, mustStartWithUserInput,
poolSupported, poolSupported,
hasVideoInput, hasVideoInput,
OAICompletionTokens OAICompletionTokens,
DeveloperRole
} }
export enum LLMProvider{ export enum LLMProvider{
@@ -451,7 +452,8 @@ export const LLMModels: LLMModel[] = [
LLMFlags.hasStreaming, LLMFlags.hasStreaming,
LLMFlags.OAICompletionTokens, LLMFlags.OAICompletionTokens,
LLMFlags.hasFullSystemPrompt, LLMFlags.hasFullSystemPrompt,
LLMFlags.hasImageInput LLMFlags.hasImageInput,
LLMFlags.DeveloperRole
], ],
parameters: OpenAIParameters, parameters: OpenAIParameters,
tokenizer: LLMTokenizer.tiktokenO200Base tokenizer: LLMTokenizer.tiktokenO200Base

View File

@@ -237,7 +237,7 @@ interface OpenAIImageContents {
type OpenAIContents = OpenAITextContents|OpenAIImageContents type OpenAIContents = OpenAITextContents|OpenAIImageContents
export interface OpenAIChatExtra { export interface OpenAIChatExtra {
role: 'system'|'user'|'assistant'|'function' role: 'system'|'user'|'assistant'|'function'|'developer'
content: string|OpenAIContents[] content: string|OpenAIContents[]
memo?:string memo?:string
name?:string name?:string
@@ -555,6 +555,17 @@ async function requestOpenAI(arg:RequestDataArgumentExtended):Promise<requestDat
} }
} }
} }
if(arg.modelInfo.flags.includes(LLMFlags.DeveloperRole)){
reformatedChat = reformatedChat.map((v) => {
if(v.role === 'system'){
return {
...v,
role: 'developer'
}
}
})
}
const res = await globalFetch(arg.customURL ?? "https://api.mistral.ai/v1/chat/completions", { const res = await globalFetch(arg.customURL ?? "https://api.mistral.ai/v1/chat/completions", {
body: applyParameters({ body: applyParameters({