mirror of
https://github.com/enricoros/big-AGI.git
synced 2026-05-11 14:10:15 -07:00
Relocate some files
This commit is contained in:
@@ -8,6 +8,7 @@ import { CmdRunReact } from '~/modules/search/search.client';
|
||||
import { PasteGG } from '~/modules/pastegg/pastegg.types';
|
||||
import { PublishedModal } from '~/modules/pastegg/PublishedModal';
|
||||
import { callPublish } from '~/modules/pastegg/pastegg.client';
|
||||
import { imaginePromptFromText } from '~/modules/aifn/imagine/imaginePromptFromText';
|
||||
import { useModelsStore } from '~/modules/llms/llm.store';
|
||||
|
||||
import { ConfirmationModal } from '~/common/components/ConfirmationModal';
|
||||
@@ -26,10 +27,9 @@ import { ConversationItems } from './components/appbar/ConversationItems';
|
||||
import { Dropdowns } from './components/appbar/Dropdowns';
|
||||
import { Ephemerals } from './components/ephemerals/Ephemerals';
|
||||
import { ImportedModal, ImportedOutcome } from './components/appbar/ImportedModal';
|
||||
import { imaginePromptFromText } from './util/ai-functions';
|
||||
import { runAssistantUpdatingState } from './util/agi-immediate';
|
||||
import { runImageGenerationUpdatingState } from './util/imagine';
|
||||
import { runReActUpdatingState } from './util/agi-react';
|
||||
import { runAssistantUpdatingState } from './editors/chat-stream';
|
||||
import { runImageGenerationUpdatingState } from './editors/image-generate';
|
||||
import { runReActUpdatingState } from './editors/react-tangent';
|
||||
|
||||
|
||||
const SPECIAL_ID_ALL_CHATS = 'all-chats';
|
||||
|
||||
@@ -4,11 +4,11 @@ import { shallow } from 'zustand/shallow';
|
||||
import { Alert, Box, Button, CircularProgress, Divider, FormControl, FormHelperText, FormLabel, Modal, ModalClose, ModalDialog, Option, Select, Slider, Stack, Textarea, Typography } from '@mui/joy';
|
||||
|
||||
import { DLLM, DLLMId } from '~/modules/llms/llm.types';
|
||||
import { summerizeToFitContextBudget } from '~/modules/aifn/summarize/summerize';
|
||||
import { useModelsStore } from '~/modules/llms/llm.store';
|
||||
|
||||
import { Section } from '~/common/components/Section';
|
||||
import { countModelTokens } from '~/common/llm-util/token-counter';
|
||||
import { summerizeToFitContextBudget } from '~/common/llm-util/summerize';
|
||||
|
||||
import { TokenBadge } from './TokenBadge';
|
||||
|
||||
|
||||
@@ -2,13 +2,14 @@ import { SystemPurposeId, SystemPurposes } from '../../../data';
|
||||
|
||||
import { DLLMId } from '~/modules/llms/llm.types';
|
||||
import { OpenAI } from '~/modules/openai/openai.types';
|
||||
import { autoTitle } from '~/modules/aifn/autotitle/autoTitle';
|
||||
import { speakText } from '~/modules/elevenlabs/elevenlabs.client';
|
||||
|
||||
import { createDMessage, DMessage, useChatStore } from '~/common/state/store-chats';
|
||||
import { useSettingsStore } from '~/common/state/store-settings';
|
||||
|
||||
import { findOpenAILlmRefOrThrow } from '~/modules/llms/llm.store';
|
||||
import { updateAutoConversationTitle } from './ai-functions';
|
||||
|
||||
|
||||
|
||||
/**
|
||||
@@ -33,7 +34,7 @@ export const runAssistantUpdatingState = async (conversationId: string, history:
|
||||
startTyping(conversationId, null);
|
||||
|
||||
// update text, if needed
|
||||
await updateAutoConversationTitle(conversationId);
|
||||
await autoTitle(conversationId);
|
||||
};
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ import { prodiaDefaultModelId } from '~/modules/prodia/prodia.client';
|
||||
import { useChatStore } from '~/common/state/store-chats';
|
||||
import { useSettingsStore } from '~/common/state/store-settings';
|
||||
|
||||
import { createAssistantTypingMessage } from './agi-immediate';
|
||||
import { createAssistantTypingMessage } from './chat-stream';
|
||||
|
||||
|
||||
/**
|
||||
@@ -1,9 +1,9 @@
|
||||
import { Agent } from '~/modules/aifn/react/react';
|
||||
import { DLLMId } from '~/modules/llms/llm.types';
|
||||
|
||||
import { Agent } from '~/common/llm-util/react';
|
||||
import { createDEphemeral, DMessage, useChatStore } from '~/common/state/store-chats';
|
||||
|
||||
import { createAssistantTypingMessage } from './agi-immediate';
|
||||
import { createAssistantTypingMessage } from './chat-stream';
|
||||
|
||||
|
||||
/**
|
||||
@@ -1,91 +0,0 @@
|
||||
import { callChat } from '~/modules/openai/openai.client';
|
||||
import { useModelsStore } from '~/modules/llms/llm.store';
|
||||
|
||||
import { useChatStore } from '~/common/state/store-chats';
|
||||
|
||||
|
||||
/**
|
||||
* Creates the AI titles for conversations, by taking the last 5 first-lines and asking AI what's that about
|
||||
*/
|
||||
export async function updateAutoConversationTitle(conversationId: string) {
|
||||
|
||||
// external state
|
||||
const { fastLLMId } = useModelsStore.getState();
|
||||
const { conversations } = useChatStore.getState();
|
||||
|
||||
// only operate on valid conversations, without any title
|
||||
const conversation = conversations.find(c => c.id === conversationId) ?? null;
|
||||
if (!fastLLMId || !conversation || conversation.autoTitle || conversation.userTitle) return;
|
||||
|
||||
// first line of the last 5 messages
|
||||
const historyLines: string[] = conversation.messages.filter(m => m.role !== 'system').slice(-5).map(m => {
|
||||
let text = m.text.split('\n')[0];
|
||||
text = text.length > 50 ? text.substring(0, 50) + '...' : text;
|
||||
text = `${m.role === 'user' ? 'You' : 'Assistant'}: ${text}`;
|
||||
return `- ${text}`;
|
||||
});
|
||||
|
||||
// LLM
|
||||
callChat(fastLLMId, [
|
||||
{ role: 'system', content: `You are an AI conversation titles assistant who specializes in creating expressive yet few-words chat titles.` },
|
||||
{
|
||||
role: 'user', content:
|
||||
'Analyze the given short conversation (every line is truncated) and extract a concise chat title that ' +
|
||||
'summarizes the conversation in as little as a couple of words.\n' +
|
||||
'Only respond with the lowercase short title and nothing else.\n' +
|
||||
'\n' +
|
||||
'```\n' +
|
||||
historyLines.join('\n') +
|
||||
'```\n',
|
||||
},
|
||||
]).then(chatResponse => {
|
||||
|
||||
const title = chatResponse?.content
|
||||
?.trim()
|
||||
?.replaceAll('"', '')
|
||||
?.replace('Title: ', '')
|
||||
?.replace('title: ', '');
|
||||
|
||||
if (title)
|
||||
useChatStore.getState().setAutoTitle(conversationId, title);
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
// https://www.youtube.com/watch?v=XLG-qtZwxIw
|
||||
/*const promptNew =
|
||||
'I want you to act as a prompt engineer. You will help me write prompts for an ai art generator.\n' +
|
||||
'\n' +
|
||||
'I will provide you with short content ideas and your job is to elaborate these into full, detailed, coherent prompts.\n' +
|
||||
'\n' +
|
||||
'Prompts involve describing the content and style of images in concise accurate language. It is useful to be explicit and use references to popular culture, artists and mediums. Your focus needs to be on nouns and adjectives. I will give you some example prompts for your reference. Please define the exact camera that should be used\n' +
|
||||
'\n' +
|
||||
'Here is a formula for you to use(content insert nouns here)(medium: insert artistic medium here)(style: insert references to genres, artists and popular culture here)(lighting, reference the lighting here)(colours reference color styles and palettes here)(composition: reference cameras, specific lenses, shot types and positional elements here)\n' +
|
||||
'\n' +
|
||||
'when giving a prompt remove the brackets, speak in natural language and be more specific, use precise, articulate language.';
|
||||
*/
|
||||
|
||||
// NOTE: formerly using this for GPT3.5Turbo
|
||||
// 'You are an AI prompt writer for AI art generation. I will provide you with an input that may include ideas or context, and your task is to create coherent and complete prompts that guide the AI in creating visually captivating artwork.\n' +
|
||||
// 'Prompts involve crafting descriptive compelling captions that describe scenes, settings, or subjects at a high level, using mostly adjectives and nouns to provide clear and focused guidance. You may also include references to artistic styles, techniques, or cultural influences to help achieve the desired aesthetic.\n' +
|
||||
// 'To ensure the AI can interpret and generate the artwork based on the provided guidance, the output must be the lowercase prompt and nothing else.',
|
||||
const simpleImagineSystemPrompt = 'As an AI art prompt writer, create captivating prompts using adjectives, nouns, and artistic references that a non-technical person can understand. Craft creative, coherent and descriptive captions to guide the AI in generating visually striking artwork. Provide output as a lowercase prompt and nothing else.';
|
||||
|
||||
/**
|
||||
* Creates a caption for a drawing or photo given some description - used to elevate the quality of the imaging
|
||||
*/
|
||||
export async function imaginePromptFromText(messageText: string): Promise<string | null> {
|
||||
const { fastLLMId } = useModelsStore.getState();
|
||||
if (!fastLLMId) return null;
|
||||
try {
|
||||
const chatResponse = await callChat(fastLLMId, [
|
||||
{ role: 'system', content: simpleImagineSystemPrompt },
|
||||
{ role: 'user', content: 'Write a prompt, based on the following input.\n\n```\n' + messageText.slice(0, 1000) + '\n```\n' },
|
||||
]);
|
||||
return chatResponse.content?.trim() ?? null;
|
||||
} catch (error: any) {
|
||||
console.error('imaginePromptFromText: fetch request error:', error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -172,6 +172,7 @@ export const useSettingsStore = create<SettingsStore>()(
|
||||
|
||||
googleCSEId: '',
|
||||
setGoogleCSEId: (cseId: string) => set({ googleCSEId: cseId }),
|
||||
|
||||
}),
|
||||
{
|
||||
name: 'app-settings',
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
import { callChat } from '~/modules/openai/openai.client';
|
||||
import { useModelsStore } from '~/modules/llms/llm.store';
|
||||
|
||||
import { useChatStore } from '~/common/state/store-chats';
|
||||
|
||||
|
||||
/**
|
||||
* Creates the AI titles for conversations, by taking the last 5 first-lines and asking AI what's that about
|
||||
*/
|
||||
export async function autoTitle(conversationId: string) {
|
||||
|
||||
// external state
|
||||
const { fastLLMId } = useModelsStore.getState();
|
||||
const { conversations } = useChatStore.getState();
|
||||
|
||||
// only operate on valid conversations, without any title
|
||||
const conversation = conversations.find(c => c.id === conversationId) ?? null;
|
||||
if (!fastLLMId || !conversation || conversation.autoTitle || conversation.userTitle) return;
|
||||
|
||||
// first line of the last 5 messages
|
||||
const historyLines: string[] = conversation.messages.filter(m => m.role !== 'system').slice(-5).map(m => {
|
||||
let text = m.text.split('\n')[0];
|
||||
text = text.length > 50 ? text.substring(0, 50) + '...' : text;
|
||||
text = `${m.role === 'user' ? 'You' : 'Assistant'}: ${text}`;
|
||||
return `- ${text}`;
|
||||
});
|
||||
|
||||
// LLM
|
||||
callChat(fastLLMId, [
|
||||
{ role: 'system', content: `You are an AI conversation titles assistant who specializes in creating expressive yet few-words chat titles.` },
|
||||
{
|
||||
role: 'user', content:
|
||||
'Analyze the given short conversation (every line is truncated) and extract a concise chat title that ' +
|
||||
'summarizes the conversation in as little as a couple of words.\n' +
|
||||
'Only respond with the lowercase short title and nothing else.\n' +
|
||||
'\n' +
|
||||
'```\n' +
|
||||
historyLines.join('\n') +
|
||||
'```\n',
|
||||
},
|
||||
]).then(chatResponse => {
|
||||
|
||||
const title = chatResponse?.content
|
||||
?.trim()
|
||||
?.replaceAll('"', '')
|
||||
?.replace('Title: ', '')
|
||||
?.replace('title: ', '');
|
||||
|
||||
if (title)
|
||||
useChatStore.getState().setAutoTitle(conversationId, title);
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
import { callChat } from '~/modules/openai/openai.client';
|
||||
import { useModelsStore } from '~/modules/llms/llm.store';
|
||||
|
||||
|
||||
const simpleImagineSystemPrompt =
|
||||
`As an AI art prompt writer, create captivating prompts using adjectives, nouns, and artistic references that a non-technical person can understand.
|
||||
Craft creative, coherent and descriptive captions to guide the AI in generating visually striking artwork.
|
||||
Provide output as a lowercase prompt and nothing else.`;
|
||||
|
||||
/**
|
||||
* Creates a caption for a drawing or photo given some description - used to elevate the quality of the imaging
|
||||
*/
|
||||
export async function imaginePromptFromText(messageText: string): Promise<string | null> {
|
||||
const { fastLLMId } = useModelsStore.getState();
|
||||
if (!fastLLMId) return null;
|
||||
try {
|
||||
const chatResponse = await callChat(fastLLMId, [
|
||||
{ role: 'system', content: simpleImagineSystemPrompt },
|
||||
{ role: 'user', content: 'Write a prompt, based on the following input.\n\n```\n' + messageText.slice(0, 1000) + '\n```\n' },
|
||||
]);
|
||||
return chatResponse.content?.trim() ?? null;
|
||||
} catch (error: any) {
|
||||
console.error('imaginePromptFromText: fetch request error:', error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// https://www.youtube.com/watch?v=XLG-qtZwxIw
|
||||
/*const promptNext =
|
||||
'I want you to act as a prompt engineer. You will help me write prompts for an ai art generator.\n' +
|
||||
'\n' +
|
||||
'I will provide you with short content ideas and your job is to elaborate these into full, detailed, coherent prompts.\n' +
|
||||
'\n' +
|
||||
'Prompts involve describing the content and style of images in concise accurate language. It is useful to be explicit and use references to popular culture, artists and mediums. Your focus needs to be on nouns and adjectives. I will give you some example prompts for your reference. Please define the exact camera that should be used\n' +
|
||||
'\n' +
|
||||
'Here is a formula for you to use(content insert nouns here)(medium: insert artistic medium here)(style: insert references to genres, artists and popular culture here)(lighting, reference the lighting here)(colours reference color styles and palettes here)(composition: reference cameras, specific lenses, shot types and positional elements here)\n' +
|
||||
'\n' +
|
||||
'when giving a prompt remove the brackets, speak in natural language and be more specific, use precise, articulate language.';
|
||||
*/
|
||||
@@ -1,9 +1,9 @@
|
||||
import { DLLMId } from '~/modules/llms/llm.types';
|
||||
import { OpenAI } from '~/modules/openai/openai.types';
|
||||
import { callApiSearchGoogle } from '~/modules/search/search.client';
|
||||
import { callChat } from '~/modules/openai/openai.client';
|
||||
|
||||
import { currentDate, reActPrompt } from './prompts';
|
||||
import { DLLMId } from '~/modules/llms/llm.types';
|
||||
import { currentDate, reActPrompt } from '../prompts';
|
||||
|
||||
|
||||
const actionRe = /^Action: (\w+): (.*)$/;
|
||||
@@ -1,9 +1,9 @@
|
||||
import { DLLMId } from '~/modules/llms/llm.types';
|
||||
import { callChat } from '~/modules/openai/openai.client';
|
||||
|
||||
import { cleanupPrompt } from './prompts';
|
||||
import { findLLMOrThrow } from '~/modules/llms/llm.store';
|
||||
|
||||
import { cleanupPrompt } from '../prompts';
|
||||
|
||||
|
||||
function breakDownChunk(chunk: string, targetWordCount: number): string[] {
|
||||
const words = chunk.split(' ');
|
||||
Reference in New Issue
Block a user