Skip to content

Commit

Permalink
Better feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
polterguy committed Oct 13, 2023
1 parent cf60e32 commit 0109b7c
Show file tree
Hide file tree
Showing 11 changed files with 66 additions and 44 deletions.
10 changes: 8 additions & 2 deletions backend/files/system/openai/create-bot.post.hl
Original file line number Diff line number Diff line change
Expand Up @@ -316,8 +316,14 @@ try
// Providing feedback to caller.
sockets.signal:x:@.feedback-channel
args
message:Done creating your machine learning model, remember to vectorize it before attempting to use it
type:success
message:Remember to vectorize before attempting to use your model
type:info

// Informing user that we're done.
sockets.signal:x:@.arguments/*/feedback-channel
args
message:Done!
type:success

// Returning success to caller.
unwrap:x:+/*
Expand Down
2 changes: 1 addition & 1 deletion backend/files/system/openai/import-page.post.hl
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ fork
type:success
sockets.signal:x:@.arguments/*/feedback-channel
args
message:Done creating OpenAI training data from page
message:Done!
type:success

// Basic logging.
Expand Down
2 changes: 1 addition & 1 deletion backend/files/system/openai/import-url.post.hl
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ signal:magic.ai.crawl-site
.feedback-channel:x:@.arguments/*/feedback-channel
sockets.signal:x:@.arguments/*/feedback-channel
args
message:Successfull scraped URL(s), remember to vectorize your model before using it
message:Done!
type:success


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,21 +193,27 @@ slots.create:magic.ai.crawl-site
threshold:x:@.arguments/*/threshold
feedback-channel:x:@.arguments/*/feedback-channel

// Signaling frontend that we're waiting for n seconds.
strings.concat
.:"Waiting for "
math.divide:x:@.arguments/*/delay
.:int:1000
.:" seconds to avoid exhausting web server"
unwrap:x:+/**
sockets.signal:x:@.arguments/*/feedback-channel
args
message:x:@strings.concat
type:info
sleep:100
// Verifying we've got more snippets before applying Crawl-Delay
if
neq:x:@.dp/#
get-value:x:@signal/@signal/*/urls/0/-
.lambda

// Sleeping for [delay] milliseconds to avoid exhausting web server.
sleep:x:@.arguments/*/delay
// Signaling frontend that we're waiting for n seconds.
strings.concat
.:"Waiting for "
math.divide:x:@.arguments/*/delay
.:int:1000
.:" seconds to avoid exhausting web server"
unwrap:x:+/**
sockets.signal:x:@.arguments/*/feedback-channel
args
message:x:@strings.concat
type:info
sleep:100

// Sleeping for [delay] milliseconds to avoid exhausting web server.
sleep:x:@.arguments/*/delay

.catch

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,9 @@ select id, prompt, completion

// Signaling frontend.
strings.concat
.:"Vectorising "
.:"Vectorizing: \""
get-value:x:@.dp/#/*/prompt
.:"\""
unwrap:x:+/*/args/*/message
sockets.signal:x:@.arguments/*/feedback-channel
args
Expand Down Expand Up @@ -241,12 +242,6 @@ insert into vss_ml_training_snippets (rowid, embedding_vss)
not exists (select rowid from vss_ml_training_snippets vss2 where vss2.rowid = ts.id)"
type:x:@.arguments/*/type

// Done with everything, notifying frontend.
sockets.signal:x:@.arguments/*/feedback-channel
args
message:Your machine learning model was successfully vectorised
type:info

// Basic logging.
log.info:Done with creating vectors for model
type:x:@.arguments/*/type
Expand Down
5 changes: 5 additions & 0 deletions backend/files/system/openai/vectorise.post.hl
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ fork
add:x:./*/signal
get-nodes:x:@.arguments/*
signal:magic.ai.vectorise
.onafter
sockets.signal:x:@.arguments/*/feedback-channel
args
message:Done!
type:success

// Returning success to caller.
return
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/app/_general/services/openai.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,11 @@ export class OpenAIService {
/**
* Vectorises all snippets in the specified type.
*/
vectorise(type: string) {
vectorise(type: string, channel: string) {

return this.httpService.post<any>('/magic/system/openai/vectorise', {
type,
['feedback-channel']: channel,
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ export class ChatbotWizardComponent implements OnInit, OnDestroy {
* Too many snippets according to license, still we'll vectorise the model explicitly to make sure
* user gets at least a somewhat working chatbot to embed on page.
*/
this.openAIService.vectorise(this.model).subscribe({
this.openAIService.vectorise(this.model, feedbackChannel).subscribe({
next: () => {

console.log('Vectorising started');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,7 @@ export class MachineLearningImportFeedbackComponent implements OnInit, OnDestroy

this.hubConnection.start().then(() => {

this.generalService.showLoading();
if (this.data.site === true) {
if (this.data.mode === 'site') {
this.openAIService.importUrl(
this.data.url,
this.data.type,
Expand All @@ -96,7 +95,7 @@ export class MachineLearningImportFeedbackComponent implements OnInit, OnDestroy
this.generalService.showFeedback('Something went wrong as we tried to start import', 'errorMessage');
}
});
} else {
} else if (this.data.mode === 'single-page') {
this.openAIService.importPage(
this.data.url,
this.data.type,
Expand All @@ -112,7 +111,20 @@ export class MachineLearningImportFeedbackComponent implements OnInit, OnDestroy
this.generalService.showFeedback('Something went wrong as we tried to spice your model', 'errorMessage');
}
});
}
} else if (this.data.mode === 'vectorize') {

this.openAIService.vectorise(this.data.type, result.result).subscribe({
next: () => {

this.generalService.hideLoading();
},
error: () => {

this.generalService.hideLoading();
this.generalService.showFeedback('Something went wrong as we tried to create embeddings for model', 'errorMessage');
}
});
}
});
},
error: () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ export class MachineLearningModelsComponent implements OnInit {
max: result.max,
threshold: result.threshold,
summarize: result.summarize,
site: true,
mode: 'site'
}
});
}
Expand Down Expand Up @@ -233,17 +233,14 @@ export class MachineLearningModelsComponent implements OnInit {
}).afterClosed().subscribe((result: string) => {

if (result === 'confirm') {

this.openAIService.vectorise(el.type).subscribe({
next: () => {

this.generalService.showFeedback('Started creating embeddings of model', 'successMessage');
this.generalService.hideLoading();
},
error: () => {

this.generalService.hideLoading();
this.generalService.showFeedback('Something went wrong as we tried to create embeddings for model', 'errorMessage');
this.dialog
.open(MachineLearningImportFeedbackComponent, {
width: '80vw',
maxWidth: '1280px',
data: {
url: result,
type: el.type,
mode: 'vectorize'
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ export class MachineLearningTrainingDataComponent implements OnInit {
max: result.max,
threshold: result.threshold,
summarize: result.summarize,
site: false,
mode: 'single-page'
}
});
}
Expand Down

0 comments on commit 0109b7c

Please sign in to comment.