Skip to content

Commit

Permalink
fix: biome-all
Browse files Browse the repository at this point in the history
Co-authored-by: Lukas Varga <[email protected]>
Signed-off-by: eloinoel <[email protected]>
  • Loading branch information
eloinoel and lukas-varga committed Jul 13, 2024
1 parent 2987be5 commit c0144b2
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 23 deletions.
12 changes: 6 additions & 6 deletions src/frontend/components/ChatBubble/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import Markdown from 'react-native-markdown-display';
import { ActivityIndicator, Button, IconButton, useTheme } from 'react-native-paper';
import type { MD3Colors } from 'react-native-paper/lib/typescript/types';
import type { conversationMessage } from 'src/frontend/types';
import { Style } from './style';
import { SpeakButton } from '../SpeakButton';
import { Style } from './style';

type ChatBubbleProps = {
message: conversationMessage;
Expand All @@ -19,8 +19,10 @@ export function ChatBubble({ message }: ChatBubbleProps) {
const AIResponses = !isUser ? Object.entries(message.message) : [];

// set default LLM to first LLM that has a response
const [llm, setLLM] = useState( AIResponses.length > 0 ?
AIResponses.find(([key, value]) => value !== 'Model Not Found')?.[0] || AIResponses[0][0] : 'error'
const [llm, setLLM] = useState(
AIResponses.length > 0
? AIResponses.find(([key, value]) => value !== 'Model Not Found')?.[0] || AIResponses[0][0]
: 'error'
);

//---------------Functions for buttons----------------
Expand All @@ -44,8 +46,6 @@ export function ChatBubble({ message }: ChatBubbleProps) {
setLLM(AIResponses[prevIndex][0]);
};



//---------------Render Chat Bubble----------------
if (isUser) {
return userBubble();
Expand Down Expand Up @@ -91,7 +91,7 @@ export function ChatBubble({ message }: ChatBubbleProps) {
disabled={AIResponses.length <= 1}
style={Style.chevronButtonRight}
/>
<SpeakButton response={response}/>
<SpeakButton response={response} />
</View>
);
}
Expand Down
10 changes: 5 additions & 5 deletions src/frontend/components/SpeakButton/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Style } from './style';
import { IconButton } from 'react-native-paper';
import * as Speech from 'expo-speech';
import React, { useEffect, useState } from 'react';
import { IconButton } from 'react-native-paper';
import { Style } from './style';

export function SpeakButton(props: { response: string }) {
const [isSpeaking, setIsSpeaking] = useState(false);
Expand Down Expand Up @@ -34,17 +34,17 @@ export function SpeakButton(props: { response: string }) {
pitch: 1,
rate: 1,
onDone: () => setIsSpeaking(false),
onError: () => setIsSpeaking(false),
onError: () => setIsSpeaking(false)
});
}
};

return (
<IconButton
icon= {!isSpeaking ? 'volume-up' : 'volume-mute'}
icon={!isSpeaking ? 'volume-up' : 'volume-mute'}
size={16}
onPress={handleSpeech}
style={Style.speakButton}
/>
)
);
}
2 changes: 1 addition & 1 deletion src/frontend/components/SpeakButton/style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ export const Style = StyleSheet.create({
speakButton: {
alignSelf: 'center',
margin: 0
},
}
});
26 changes: 15 additions & 11 deletions src/frontend/screens/ChatUI/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -153,27 +153,31 @@ export function ChatUI() {
}

// ------------- Helper functions -------------
function initResponses(){
const response: { [key: string]: string } = Object.keys(activeLLMs).reduce((acc, key) => {
if (activeLLMs[key].active) {
acc[key] = 'Could not retrieve answer from LLM';
}
return acc;
}, {} as { [key: string]: string });
if(Object.keys(response).length === 0) response['gpt-4'] = 'Could not retrieve answer from LLM';
function initResponses() {
const response: { [key: string]: string } = Object.keys(activeLLMs).reduce(
(acc, key) => {
if (activeLLMs[key].active) {
acc[key] = 'Could not retrieve answer from LLM';
}
return acc;
},
{} as { [key: string]: string }
);
if (Object.keys(response).length === 0)
response['gpt-4'] = 'Could not retrieve answer from LLM';
return response;
}

// returns currently selected LLMs and 'gpt-4' if no LLM is selected
function extractActiveLLMNames() {
const llms: string[] = [];
for(const llm of Object.keys(activeLLMs)) {
if(activeLLMs[llm].active) {
for (const llm of Object.keys(activeLLMs)) {
if (activeLLMs[llm].active) {
llms.push(llm);
}
}

if(llms.length === 0) llms.push('gpt-4');
if (llms.length === 0) llms.push('gpt-4');
return llms;
}

Expand Down

0 comments on commit c0144b2

Please sign in to comment.