Skip to content

Commit

Permalink
feat(followups): adds alternate flavors for follow-ups; other minor t…
Browse files Browse the repository at this point in the history
…weaks
  • Loading branch information
Fortyseven committed Oct 13, 2024
1 parent c6b1c99 commit 70300ac
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 8 deletions.
33 changes: 27 additions & 6 deletions src/components/TabPages/Conversation/Chat/FollowUps.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,20 @@
import { chatTimeline, inputText } from '$stores/stores';
import { chatState } from '$stores/chatState';
import { Renew } from 'carbon-icons-svelte';
import Loading from '../../../UI/Loading.svelte';
import { scrollToBottom } from '$lib/chat';
import {
followUpSuggestions,
isLoadingFollowups
isLoadingFollowups,
followUpType
} from '../InputBox/ConvoTools.store.js';
/* ----------------------------------------------------------*/
const MAX_RETRIES = 3;
const PROMPT_FOLLOWUP = `You will be provided with a chat fragment between a user and an assistant. Generate a JSON array of 4 suggested follow-up queries written from the user's perspective..
const PROMPT_FOLLOWUP = {
questions: `You will be provided with a chat fragment between a user and an assistant. Generate a JSON array of 4 suggested follow-up queries written from the user's perspective..
For example, follow-up queries might be among:
- "Tell me more about..."
Expand All @@ -24,7 +27,19 @@ For example, follow-up queries might be among:
- "Why does..."
- "Does it say..."
Only respond with valid JSON in this format: ["suggestion", "suggestion2"]`;
Only respond with valid JSON in this format: ["suggestion", "suggestion2"]`,
rp_choices: `You will be provided with a role playing chat fragment between a user and an assistant. Generate a JSON array of 4 suggested ways the story can continue.
For example:
- "You decide to..."
- "You ask..."
- "Look closer at..."
- "Try to escape..."
- "Attack..."
- Or any other action that could possibly be taken.
Only respond with valid JSON in this format: ["suggestion", "suggestion2"]`
};
/* ----------------------------------------------------------*/
Expand All @@ -34,7 +49,7 @@ Only respond with valid JSON in this format: ["suggestion", "suggestion2"]`;
let response = await ollama().generate({
model: 'llama3.2:latest',
prompt: lastResponse,
system: PROMPT_FOLLOWUP,
system: PROMPT_FOLLOWUP[$followUpType],
// format: 'json',
options: {
temperature: 0.8,
Expand All @@ -53,7 +68,6 @@ Only respond with valid JSON in this format: ["suggestion", "suggestion2"]`;
const parsed = JSON.parse(response);
if (Array.isArray(parsed) && parsed.length > 0) {
parsed.sort();
// console.log('🟢 LLM returned followups:', parsed);
return parsed;
} else {
console.error(
Expand Down Expand Up @@ -155,6 +169,12 @@ Only respond with valid JSON in this format: ["suggestion", "suggestion2"]`;
</div>
{/each}
</div>
<div class="reroll w-full pt-4">
<button
class="m-auto flex items-center gap-3"
on:click={regenerateFollowUps}><Renew /> Reroll</button
>
</div>
{:else}
<div class="fail flex">
<div class="w-full col-span-2">
Expand Down Expand Up @@ -187,13 +207,14 @@ Only respond with valid JSON in this format: ["suggestion", "suggestion2"]`;
}
}
}
.reroll,
.fail {
opacity: 0.25;
text-align: center;
div {
margin-bottom: 1em;
}
button.retry {
button {
@apply transition-all;
@apply duration-300;
@apply rounded-md;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ import { writable } from 'svelte/store';
export const getFollowUps = writable(true);
export const followUpSuggestions = writable([]);
export const isLoadingFollowups = writable(false);
export const followUpType = writable('questions');
12 changes: 10 additions & 2 deletions src/components/TabPages/Conversation/InputBox/ConvoTools.svelte
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<script lang="ts">
<script>
import { Copy } from 'carbon-icons-svelte';
import {
pendingContinuedAssistantChat,
Expand All @@ -7,7 +7,7 @@
} from '$lib/api/api';
import { chatTimeline } from '$stores/stores';
import { getFollowUps } from './ConvoTools.store';
import { followUpType, getFollowUps } from './ConvoTools.store';
function copyChatToClipboard() {
const chatText = $chatTimeline
Expand All @@ -32,6 +32,14 @@
>
<input type="checkbox" bind:checked={$getFollowUps} />
Follow-ups
<select
bind:value={$followUpType}
disabled={!$getFollowUps}
style:opacity={!$getFollowUps ? '0.25' : '1'}
>
<option selected value="questions">Questions</option>
<option value="rp_choices">Story Choices</option>
</select>
</label>
</div>
<div class="flex-auto grid place-content-end">
Expand Down

0 comments on commit 70300ac

Please sign in to comment.