Spaces:
				
			
			
	
			
			
		Paused
		
	
	
	
			
			
	
	
	
	
		
		
		Paused
		
	File size: 1,613 Bytes
			
			| 388034d d433b55 388034d a1a6daf 388034d a1a6daf 388034d d433b55 388034d d433b55 388034d a1a6daf 388034d | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 | <script lang="ts">
	import { invalidateAll } from "$app/navigation";
	import { page } from "$app/state";
	import { base } from "$app/paths";
	import type { Model } from "$lib/types/Model";
	interface Props {
		models: Model[];
		currentModel: Model;
	}
	let { models, currentModel }: Props = $props();
	let selectedModelId = $state(
		models.map((m) => m.id).includes(currentModel.id) ? currentModel.id : models[0].id
	);
	async function handleModelChange() {
		if (!page.params.id) return;
		try {
			const response = await fetch(`${base}/conversation/${page.params.id}`, {
				method: "PATCH",
				headers: {
					"Content-Type": "application/json",
				},
				body: JSON.stringify({ model: selectedModelId }),
			});
			if (!response.ok) {
				throw new Error("Failed to update model");
			}
			await invalidateAll();
		} catch (error) {
			console.error(error);
		}
	}
</script>
<div
	class="mx-auto mt-0 flex w-fit flex-col items-center justify-center gap-2 rounded-lg border border-gray-200 bg-gray-500/20 p-4 dark:border-gray-800"
>
	<span>
		This model is no longer available. Switch to a new one to continue this conversation:
	</span>
	<div class="flex items-center space-x-2">
		<select
			bind:value={selectedModelId}
			class="rounded-md bg-gray-100 px-2 py-1 dark:bg-gray-900 max-sm:max-w-32"
		>
			{#each models as model}
				<option value={model.id}>{model.name}</option>
			{/each}
		</select>
		<button
			onclick={handleModelChange}
			disabled={selectedModelId === currentModel.id}
			class="rounded-md bg-gray-100 px-2 py-1 dark:bg-gray-900"
		>
			Accept
		</button>
	</div>
</div>
 | 
 
			
