Restore context fetching with parallel requests
- Fetch activity + dashboard context in parallel - Context embedded in question for better AI responses 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
6e6b6b6c5f
commit
84c17f68f7
@ -168,22 +168,40 @@ export default function ChatScreen() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Send message with full context - optimized for speed
|
// Send message with full context - fetches context in parallel for speed
|
||||||
const sendWithContext = async (question: string): Promise<string> => {
|
const sendWithContext = async (question: string): Promise<string> => {
|
||||||
const token = await SecureStore.getItemAsync('accessToken');
|
const token = await SecureStore.getItemAsync('accessToken');
|
||||||
const userName = await SecureStore.getItemAsync('userName');
|
const userName = await SecureStore.getItemAsync('userName');
|
||||||
|
|
||||||
if (!token || !userName) throw new Error('Please log in');
|
if (!token || !userName) throw new Error('Please log in');
|
||||||
|
if (!currentBeneficiary?.id) throw new Error('Please select a beneficiary');
|
||||||
|
|
||||||
const beneficiaryName = currentBeneficiary?.name || 'the patient';
|
const beneficiaryName = currentBeneficiary.name || 'the patient';
|
||||||
const deploymentId = currentBeneficiary?.id?.toString() || '';
|
const deploymentId = currentBeneficiary.id.toString();
|
||||||
|
|
||||||
// Skip context fetching for faster response - just send directly
|
// Fetch both contexts in PARALLEL for speed
|
||||||
const enhancedQuestion = currentBeneficiary?.id
|
const [activityContext, dashboardContext] = await Promise.all([
|
||||||
? `You are a caring assistant helping monitor ${beneficiaryName}'s wellbeing. Please answer: ${question}`
|
getActivityContext(token, userName, deploymentId),
|
||||||
: `You are a helpful AI assistant. Please answer: ${question}`;
|
getDashboardContext(token, userName, deploymentId),
|
||||||
|
]);
|
||||||
|
|
||||||
// Call API directly without pre-fetching context
|
// Use activity context, fallback to dashboard
|
||||||
|
const context = activityContext || dashboardContext;
|
||||||
|
|
||||||
|
// Build the question with embedded context
|
||||||
|
let enhancedQuestion: string;
|
||||||
|
if (context) {
|
||||||
|
enhancedQuestion = `You are a caring assistant helping monitor ${beneficiaryName}'s wellbeing.
|
||||||
|
|
||||||
|
Here is the current data about ${beneficiaryName}:
|
||||||
|
${context}
|
||||||
|
|
||||||
|
Based on this data, please answer the following question: ${question}`;
|
||||||
|
} else {
|
||||||
|
enhancedQuestion = `You are a caring assistant helping monitor ${beneficiaryName}'s wellbeing. Please answer: ${question}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Call API
|
||||||
const requestBody = new URLSearchParams({
|
const requestBody = new URLSearchParams({
|
||||||
function: 'voice_ask',
|
function: 'voice_ask',
|
||||||
clientId: '001',
|
clientId: '001',
|
||||||
@ -191,7 +209,7 @@ export default function ChatScreen() {
|
|||||||
token: token,
|
token: token,
|
||||||
question: enhancedQuestion,
|
question: enhancedQuestion,
|
||||||
deployment_id: deploymentId,
|
deployment_id: deploymentId,
|
||||||
context: '',
|
context: context || '',
|
||||||
}).toString();
|
}).toString();
|
||||||
|
|
||||||
const response = await fetch(API_URL, {
|
const response = await fetch(API_URL, {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user