Skip to content

Commit

Permalink
view prompt and reponse
Browse files Browse the repository at this point in the history
  • Loading branch information
nbonamy committed Jan 17, 2024
1 parent 07e5532 commit 5a51786
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 5 deletions.
48 changes: 45 additions & 3 deletions public/js/code-viewer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,59 @@
<div class="modal-card" style="width: 800px; margin: 0 auto;">
<header class="modal-card-head"><p class="modal-card-title">{{ title }}</p></header>
<section class="modal-card-body">
<pre>{{ code }}</pre>
<pre>{{ formattedCode }}</pre>
</section>
<footer class="modal-card-foot">
<b-button label="Close" @click="$parent.close()" />
<b-button label="Close" @click="$parent.close()"></b-button>
<b-button label="Prompt" @click="showPrompt()" v-if="hasPrompt"></b-button>
<b-button label="Response" @click="showResponse()" v-if="hasResponse"></b-button>
</footer>
</div>
</template>

<script>
export default {
props: [ 'code', 'title' ],
name: 'CodeViewer',
props: [ 'code', 'title', 'asText' ],
computed: {
formattedCode() {
let formatted = JSON.stringify(this.code, null, 2)
if (this.asText) {
formatted = formatted.replace(/\\n/g, '\n')
formatted = formatted.slice(1, -1).trim()
}
return formatted
},
hasPrompt() {
let prompt = this.code['prompt'] ?? this.code['question']
return prompt != null && prompt.length > 0
},
hasResponse() {
let response = this.code['response'] ?? this.code['answer']
return response != null && response.length > 0
}
},
methods: {
showPrompt() {
this.showAsText('Prompt', this.code['prompt'] ?? this.code['question'])
},
showResponse() {
this.showAsText('Response', this.code['response'] ?? this.code['answer'])
},
showAsText(title, str) {
this.$buefy.modal.open({
parent: this,
trapFocus: true,
hasModalCard: true,
component: CodeViewer,
props: {
title: title,
asText: true,
code: str,
},
})
}
}
}
</script>
Expand Down
2 changes: 1 addition & 1 deletion public/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ var vm = new Vue({
component: CodeViewer,
props: {
title: 'Chain',
code: JSON.stringify(response, null, 2),
code: response,
},
})
},
Expand Down
2 changes: 1 addition & 1 deletion public/js/step.vue
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export default {
component: CodeViewer,
props: {
title: this.title,
code: JSON.stringify(clone, null, 2),
code: clone,
},
})
},
Expand Down

0 comments on commit 5a51786

Please sign in to comment.