Skip to content

Commit

Permalink
fix: ai response being stored in different format and not displayed c…
Browse files Browse the repository at this point in the history
…orrectly

Co-authored-by: Lukas Varga <lukas.varga128@gmail.com>
Signed-off-by: eloinoel <eloi.sandt.games@gmx.de>
  • Loading branch information
eloinoel and lukas-varga committed Jul 12, 2024
1 parent e63b767 commit ad8c032
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
15 changes: 12 additions & 3 deletions src/frontend/components/RenderChat/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,30 @@ import { useActiveChatId, useGetChat } from 'src/frontend/hooks';
import type { conversationMessage } from 'src/frontend/types';
import { Style } from './style';



export function RenderChat() {
const { activeChatId } = useActiveChatId();
const { chat, status } = useGetChat(activeChatId);
const { colors } = useTheme();
const { data: user } = useUser();

if (status === 'loading') return <ActivityIndicator />;

let id = 0;
return (
<>
{/* biome-ignore lint/suspicious/noExplicitAny: <explanation> */}

Check warning on line 22 in src/frontend/components/RenderChat/index.tsx

View workflow job for this annotation

GitHub Actions / Job: Check Lint and Format TS & TSX Code

Suppression comment is not being used
{chat?.conversation.map((item: conversationMessage) => {
const { type, message } = item;
let AIResponse = ""
if(type === 'AI') {
const entries = Object.entries(message)
if(entries.length > 0)
AIResponse = entries[0][1];
}
return (
<View
key={message}
key={type === 'USER' ? (message as string) + id++ : AIResponse + id++}
style={[Style.bubble, { backgroundColor: colors.surfaceVariant, marginBottom: 16 }]}
>
<View style={{ flexDirection: 'row', alignItems: 'center' }}>
Expand All @@ -34,7 +43,7 @@ export function RenderChat() {
{type === 'AI' ? 'AiLixir' : user?.displayName || 'User'}
</Text>
</View>
<Markdown>{message}</Markdown>
<Markdown>{type === 'AI' ? AIResponse : message as string}</Markdown>
</View>
);
})}
Expand Down
3 changes: 2 additions & 1 deletion src/frontend/screens/ChatUI/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,12 @@ export function ChatUI() {

useEffect(() => {
const create = async () => {
const { id } = await createChat({
const result = await createChat({
title: 'NewChat',
model: ['gpt-4'],
conversation: []
});
const id = result?.id
setActiveChatId(id || '');
};
if (activeChatId === 'default') create();
Expand Down
5 changes: 4 additions & 1 deletion src/frontend/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ export type LLM = {
active: boolean;
};

export type conversationMessage = { [key: string]: string };
export type conversationMessage = {
type: 'USER' | 'AI';
message: string | { [key: string]: string };
};

export type Chat = {
id?: string;
Expand Down

0 comments on commit ad8c032

Please sign in to comment.