Skip to content

Commit

Permalink
Cleanup sample implementation and update thread runs method
Browse files Browse the repository at this point in the history
  • Loading branch information
Corina Gum committed Nov 19, 2024
1 parent 85ad37a commit baeab95
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
2 changes: 1 addition & 1 deletion js/packages/teams-ai/src/planners/AssistantsPlanner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ export class AssistantsPlanner<TState extends TurnState = TurnState> implements
}
}

const run = await this._client.beta.threads.runs.submitToolOutputs(
const run = await this._client.beta.threads.runs.submitToolOutputsAndPoll(
assistantsState.thread_id!,
assistantsState.run_id!,
{ tool_outputs: toolOutputs }
Expand Down
15 changes: 11 additions & 4 deletions js/samples/04.ai-apps/e.assistants-orderBot/src/bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ if (process.env.AZURE_OPENAI_KEY) {
}

const { AssistantsPlanner } = preview;
let assistantId = '';

// Create Assistant if no ID is provided, this will require you to restart the program and fill in the process.env.ASSISTANT_ID afterwards.
if (!process.env.ASSISTANT_ID) {
Expand All @@ -43,21 +44,24 @@ if (!process.env.ASSISTANT_ID) {
}
}
],
model: 'gpt-4'
model: 'gpt-4o-mini'
},
endpoint
endpoint ?? undefined,
endpoint ? { apiVersion: process.env.OPENAI_API_VERSION } : undefined
);

console.log(`Created a new assistant with an ID of: ${assistant.id}`);
process.exit();
console.log('Be sure to add this ID to your environment variables as ASSISTANT_ID before your next restart.');
assistantId = assistant.id;
process.env.ASSISTANT_ID = assistantId;
})();
}

// Create Assistant Planner
const planner = new AssistantsPlanner({
apiKey: apiKey,
endpoint: endpoint,
assistant_id: process.env.ASSISTANT_ID!
assistant_id: process.env.ASSISTANT_ID ?? assistantId
});

// Define storage and application
Expand All @@ -78,12 +82,15 @@ app.message('/reset', async (context, state) => {
});

app.ai.action<Order>('place_order', async (context, state, order) => {
console.log('place order');
const card = generateCardForOrder(order);
await context.sendActivity(MessageFactory.attachment(CardFactory.adaptiveCard(card)));
return `order placed`;
});

app.ai.action(AI.HttpErrorActionName, async (context, state, data) => {
// console.log(context);
console.log(data);
await context.sendActivity('An AI request failed. Please try again later.');
return AI.StopCommandName;
});

0 comments on commit baeab95

Please sign in to comment.