Skip to content
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

[Fix]: added try catch block to handle errors in createNewConversation function in Copilot.tsx #118

Merged
merged 2 commits into from
Jun 5, 2024
Merged
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
72 changes: 37 additions & 35 deletions src/app/components/Copilot/Copilot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,41 +14,43 @@ let GlobalConversationID: string;

// going to use get all conversations with a few extra steps to store the current conversations locally.
export function createNewConversation() {

// logs --> CREATING CONVERSATION
console.log('Begin creating conversation...')

// to create a new conversation, you need to first pass in a seeded conversation in the request body.
// the only mandatory parameter is the ConversationTypeEnum.Copilot value.
let seededConversation: SeededConversation = { type: ConversationTypeEnum.Copilot, name: "Demo Seeded Conversation" }

console.log('Conversation seeded')
console.log('Passing over the new conversation with name: ' + seededConversation.name)

// creates new conversation, .then is for confirmation on creation.
// note the usage of transfereables here to expose the full conversation data and give access to the id and other
// conversation values.
new Pieces.ConversationsApi().conversationsCreateSpecificConversationRaw({transferables: true, seededConversation}).then((_c) => {
console.log('Conversation created! : Here is the response:');
console.log(_c);

// check and ensure the response back is clean.
if (_c.raw.ok == true && _c.raw.status == 200) {
console.log('CLEAN RESPONSE BACK.')
_c.value().then(_conversation => {
console.log('Returning new conversation values.');
// console.log('ID | ' + _conversation.id);
// console.log('NAME | ' + _conversation.name);
// console.log('CREATED | ' + _conversation.created.readable);
// console.log('ID: ' + _conversation.);

// Set the conversation variable here for the local file:
GlobalConversationID = _conversation.id;
})
}


})
try {

// logs --> CREATING CONVERSATION
console.log('Begin creating conversation...')

// to create a new conversation, you need to first pass in a seeded conversation in the request body.
// the only mandatory parameter is the ConversationTypeEnum.Copilot value.
let seededConversation: SeededConversation = { type: ConversationTypeEnum.Copilot, name: "Demo Seeded Conversation" }

console.log('Conversation seeded')
console.log('Passing over the new conversation with name: ' + seededConversation.name)

// creates new conversation, .then is for confirmation on creation.
// note the usage of transfereables here to expose the full conversation data and give access to the id and other
// conversation values.
new Pieces.ConversationsApi().conversationsCreateSpecificConversationRaw({transferables: true, seededConversation}).then((_c) => {
console.log('Conversation created! : Here is the response:');
console.log(_c);

// check and ensure the response back is clean.
if (_c.raw.ok == true && _c.raw.status == 200) {
console.log('CLEAN RESPONSE BACK.')
_c.value().then(_conversation => {
console.log('Returning new conversation values.');
// console.log('ID | ' + _conversation.id);
// console.log('NAME | ' + _conversation.name);
// console.log('CREATED | ' + _conversation.created.readable);
// console.log('ID: ' + _conversation.);

// Set the conversation variable here for the local file:
GlobalConversationID = _conversation.id;
})
}
})
} catch (error) {
console.error('An error occurred while creating a conversation:', error);
}
}


Expand Down
Loading