Skip to content

feat: support thinking mode for claude 4 #42

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions .github/workflows/release-template.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
name: Release Template

on:
workflow_dispatch:
inputs:
reason:
description: 'the reason for triggering this workflow'
required: false
default: 'manually publish the ecr images and templates'
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
jobs:
release_template:
runs-on: ubuntu-latest
Expand Down
5 changes: 5 additions & 0 deletions react-native/ios/SwiftChat/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@
<string>Support record videos, voice chat, and summarize content</string>
<key>NSPhotoLibraryUsageDescription</key>
<string>Support choose pictures and summarize it</string>
<key>UIBackgroundModes</key>
<array>
<string>audio</string>
<string>fetch</string>
</array>
<key>UILaunchStoryboardName</key>
<string>LaunchScreen</string>
<key>UIRequiredDeviceCapabilities</key>
Expand Down
4 changes: 2 additions & 2 deletions react-native/src/api/bedrock-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -299,12 +299,12 @@ export const requestAllModels = async (): Promise<AllModel> => {
return { imageModel: [], textModel: [] };
}
const allModel = await response.json();
allModel.imageModel.map((item: Model) => ({
allModel.imageModel = allModel.imageModel.map((item: Model) => ({
modelId: item.modelId,
modelName: item.modelName,
modelTag: ModelTag.Bedrock,
}));
allModel.textModel.map((item: Model) => ({
allModel.textModel = allModel.textModel.map((item: Model) => ({
modelId: item.modelId,
modelName: item.modelName,
modelTag: ModelTag.Bedrock,
Expand Down
50 changes: 18 additions & 32 deletions react-native/src/chat/ChatScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ import {
TextInput,
} from 'react-native';
import { voiceChatService } from './service/VoiceChatService';
import AudioWaveformComponent from './component/AudioWaveformComponent';
import AudioWaveformComponent, {
AudioWaveformRef,
} from './component/AudioWaveformComponent';
import { Colors } from 'react-native/Libraries/NewAppScreen';
import {
invokeBedrockWithCallBack as invokeBedrockWithCallBack,
Expand Down Expand Up @@ -108,7 +110,6 @@ function ChatScreen(): React.JSX.Element {
const [systemPrompt, setSystemPrompt] = useState<SystemPrompt | null>(
isNovaSonic ? getCurrentVoiceSystemPrompt : getCurrentSystemPrompt
);
const [audioVolume, setAudioVolume] = useState<number>(1); // Audio volume level (1-10)
const [showSystemPrompt, setShowSystemPrompt] = useState<boolean>(true);
const [screenDimensions, setScreenDimensions] = useState(
Dimensions.get('window')
Expand All @@ -132,31 +133,33 @@ function ChatScreen(): React.JSX.Element {
const usageRef = useRef(usage);
const systemPromptRef = useRef(systemPrompt);
const drawerTypeRef = useRef(drawerType);
const inputAudioLevelRef = useRef(1);
const outputAudioLevelRef = useRef(1);
const isVoiceLoading = useRef(false);
const contentHeightRef = useRef(0);
const containerHeightRef = useRef(0);
const isNovaSonicRef = useRef(isNovaSonic);
const [isShowVoiceLoading, setIsShowVoiceLoading] = useState(false);
const audioWaveformRef = useRef<AudioWaveformRef>(null);

const endVoiceConversationRef = useRef<(() => Promise<boolean>) | null>(null);

// End voice conversation and reset audio levels
const endVoiceConversation = useCallback(async () => {
audioWaveformRef.current?.resetAudioLevels();
if (isVoiceLoading.current) {
return Promise.resolve(false);
}
isVoiceLoading.current = true;
setIsShowVoiceLoading(true);
await voiceChatService.endConversation();
setAudioVolume(1);
inputAudioLevelRef.current = 1;
outputAudioLevelRef.current = 1;
setChatStatus(ChatStatus.Init);
isVoiceLoading.current = false;
setIsShowVoiceLoading(false);
return true;
}, []);

useEffect(() => {
endVoiceConversationRef.current = endVoiceConversation;
}, [endVoiceConversation]);

// update refs value with state
useEffect(() => {
messagesRef.current = messages;
Expand Down Expand Up @@ -187,31 +190,18 @@ function ChatScreen(): React.JSX.Element {
message => {
if (getTextModel().modelId.includes('nova-sonic')) {
handleVoiceChatTranscript('ASSISTANT', message);
endVoiceConversation().then();
endVoiceConversationRef.current?.();
saveCurrentMessages();
console.log('Voice chat error:', message);
}
},
// Handle audio level changes
(source, level) => {
if (source === 'microphone') {
inputAudioLevelRef.current = level;
} else {
outputAudioLevelRef.current = level;
}
const maxLevel = Math.max(
inputAudioLevelRef.current,
outputAudioLevelRef.current
);
setAudioVolume(maxLevel);
}
);

// Clean up on unmount
return () => {
voiceChatService.cleanup();
};
}, [endVoiceConversation]);
}, []);

// start new chat
const startNewChat = useRef(
Expand Down Expand Up @@ -300,7 +290,7 @@ function ChatScreen(): React.JSX.Element {
// click from history
setMessages([]);
if (isNovaSonicRef.current) {
endVoiceConversation().then();
endVoiceConversationRef.current?.();
}
setIsLoadingMessages(true);
const msg = getMessagesBySessionId(initialSessionId);
Expand All @@ -324,7 +314,7 @@ function ChatScreen(): React.JSX.Element {
}, 200);
}
}
}, [initialSessionId, mode, tapIndex, endVoiceConversation]);
}, [initialSessionId, mode, tapIndex]);

// deleteChat listener
useEffect(() => {
Expand Down Expand Up @@ -709,11 +699,7 @@ function ChatScreen(): React.JSX.Element {
}
renderComposer={props => {
if (isNovaSonic && mode === ChatMode.Text) {
return (
<AudioWaveformComponent
volume={audioVolume} // Use real-time audio volume level
/>
);
return <AudioWaveformComponent ref={audioWaveformRef} />;
}

// Default input box
Expand Down Expand Up @@ -778,14 +764,14 @@ function ChatScreen(): React.JSX.Element {
if (isNovaSonic) {
saveCurrentVoiceSystemPrompt(prompt);
if (chatStatus === ChatStatus.Running) {
endVoiceConversation().then();
endVoiceConversationRef.current?.();
}
} else {
saveCurrentSystemPrompt(prompt);
}
}}
onSwitchedToTextModel={() => {
endVoiceConversation().then();
endVoiceConversationRef.current?.();
}}
chatMode={modeRef.current}
isShowSystemPrompt={showSystemPrompt}
Expand Down
Loading