Code clean-up

This commit is contained in:
Cohee 2024-04-14 19:31:38 +03:00
parent 5ce625fb6b
commit 607e85639c
3 changed files with 42 additions and 66 deletions

View File

@ -458,17 +458,14 @@
</span>
</div>
</div>
<div class="range-block">
<div class="range-block" data-source="cohere">
<label for="websearch_toggle" title="Enable Cohere web-search connector" data-i18n="[title]Enable Cohere web-search connector" class="checkbox_label widthFreeExpand">
<input id="websearch_toggle" type="checkbox" /><span data-i18n="Web-search">
Web-search</span>
<input id="websearch_toggle" type="checkbox" />
<span data-i18n="Web-search">Web-search</span>
</label>
<div class="toggle-description justifyLeft">
<span data-i18n="Allow the model to use the web-search connector.">
Allow the model to use the web-search connector.
</span><br>
<span data-i18n="When this is off, the model won't use the web-search connector.">
This is only available for the Cohere API.
</span>
</div>
</div>

View File

@ -1618,7 +1618,6 @@ async function sendOpenAIRequest(type, messages, signal) {
const isImpersonate = type === 'impersonate';
const isContinue = type === 'continue';
const stream = oai_settings.stream_openai && !isQuiet && !isScale && !isAI21 && !(isGoogle && oai_settings.google_model.includes('bison'));
const websearch = oai_settings.websearch_cohere && isCohere;
const useLogprobs = !!power_user.request_token_probabilities;
const canMultiSwipe = oai_settings.n > 1 && !isContinue && !isImpersonate && !isQuiet && (isOAI || isCustom);
@ -1665,7 +1664,6 @@ async function sendOpenAIRequest(type, messages, signal) {
'top_p': Number(oai_settings.top_p_openai),
'max_tokens': oai_settings.openai_max_tokens,
'stream': stream,
'websearch': websearch,
'logit_bias': logit_bias,
'stop': getCustomStoppingStrings(openai_max_stop_strings),
'chat_completion_source': oai_settings.chat_completion_source,
@ -1757,6 +1755,7 @@ async function sendOpenAIRequest(type, messages, signal) {
generate_data['frequency_penalty'] = Math.min(Math.max(Number(oai_settings.freq_pen_openai), 0), 1);
generate_data['presence_penalty'] = Math.min(Math.max(Number(oai_settings.pres_pen_openai), 0), 1);
generate_data['stop'] = getCustomStoppingStrings(5);
generate_data['websearch'] = oai_settings.websearch_cohere;
}
if ((isOAI || isOpenRouter || isMistral || isCustom || isCohere) && oai_settings.seed >= 0) {
@ -2257,7 +2256,7 @@ export class ChatCompletion {
const shouldSquash = (message) => {
return !excludeList.includes(message.identifier) && message.role === 'system' && !message.name;
}
};
if (shouldSquash(message)) {
if (lastMessage && shouldSquash(lastMessage)) {
@ -3338,7 +3337,7 @@ function onSettingsPresetChange() {
personality_format: ['#personality_format_textarea', 'personality_format', false],
group_nudge_prompt: ['#group_nudge_prompt_textarea', 'group_nudge_prompt', false],
stream_openai: ['#stream_toggle', 'stream_openai', true],
websearch_cohere: ['#websearch_toggle', 'websearch_cohere', false],
websearch_cohere: ['#websearch_toggle', 'websearch_cohere', true],
prompts: ['', 'prompts', false],
prompt_order: ['', 'prompt_order', false],
api_url_scale: ['#api_url_scale', 'api_url_scale', false],
@ -4033,7 +4032,7 @@ export function isImageInliningSupported() {
'gemini-1.0-pro-vision-latest',
'gemini-1.5-pro-latest',
'gemini-pro-vision',
'claude-3'
'claude-3',
];
switch (oai_settings.chat_completion_source) {

View File

@ -537,12 +537,16 @@ async function sendCohereRequest(request, response) {
try {
const convertedHistory = convertCohereMessages(request.body.messages);
// https://docs.cohere.com/reference/chat
requestBody = {};
const connectors = [];
if (request.body.websearch) {
requestBody = {
connectors.push({
id: 'web-search',
});
}
// https://docs.cohere.com/reference/chat
const requestBody = {
stream: Boolean(request.body.stream),
model: request.body.model,
message: convertedHistory.userPrompt,
@ -557,36 +561,12 @@ async function sendCohereRequest(request, response) {
frequency_penalty: request.body.frequency_penalty,
presence_penalty: request.body.presence_penalty,
prompt_truncation: 'AUTO_PRESERVE_ORDER',
connectors: [{"id": "web-search"}], // TODO
connectors: connectors,
documents: [],
tools: [],
tool_results: [],
search_queries_only: false,
};
}
else {
requestBody = {
stream: Boolean(request.body.stream),
model: request.body.model,
message: convertedHistory.userPrompt,
preamble: convertedHistory.systemPrompt,
chat_history: convertedHistory.chatHistory,
temperature: request.body.temperature,
max_tokens: request.body.max_tokens,
k: request.body.top_k,
p: request.body.top_p,
seed: request.body.seed,
stop_sequences: request.body.stop,
frequency_penalty: request.body.frequency_penalty,
presence_penalty: request.body.presence_penalty,
prompt_truncation: 'AUTO_PRESERVE_ORDER',
connectors: [], // TODO
documents: [],
tools: [],
tool_results: [],
search_queries_only: false,
};
}
console.log('Cohere request:', requestBody);