Adrien Denat commited on
Commit
a974db9
1 Parent(s): 4791715

🐛 Vote not working with new messages (#249)

Browse files

* fix retry not working after vote changes

* once assistant answer is received, invalidate the messages so we get the update id

* pass response message id from client to server

* remove url dependency

src/lib/components/chat/ChatMessage.svelte CHANGED
@@ -182,7 +182,7 @@
182
  class="cursor-pointer rounded-lg border border-gray-100 p-1 text-xs text-gray-400 group-hover:block hover:text-gray-500 dark:border-gray-800 dark:text-gray-400 dark:hover:text-gray-300 md:hidden lg:-right-2"
183
  title="Retry"
184
  type="button"
185
- on:click={() => dispatch("retry")}
186
  >
187
  <CarbonRotate360 />
188
  </button>
 
182
  class="cursor-pointer rounded-lg border border-gray-100 p-1 text-xs text-gray-400 group-hover:block hover:text-gray-500 dark:border-gray-800 dark:text-gray-400 dark:hover:text-gray-300 md:hidden lg:-right-2"
183
  title="Retry"
184
  type="button"
185
+ on:click={() => dispatch("retry", { content: message.content, id: message.id })}
186
  >
187
  <CarbonRotate360 />
188
  </button>
src/routes/conversation/[id]/+page.svelte CHANGED
@@ -31,6 +31,7 @@
31
 
32
  async function getTextGenerationStream(inputs: string, messageId: string, isRetry = false) {
33
  const conversationId = $page.params.id;
 
34
 
35
  const response = textGenerationStream(
36
  {
@@ -43,6 +44,7 @@
43
  },
44
  {
45
  id: messageId,
 
46
  is_retry: isRetry,
47
  use_cache: false,
48
  } as Options
@@ -89,7 +91,7 @@
89
  messages = [
90
  ...messages,
91
  // id doesn't match the backend id but it's not important for assistant messages
92
- { from: "assistant", content: output.token.text.trimStart(), id: randomUUID() },
93
  ];
94
  } else {
95
  lastMessage.content += output.token.text;
 
31
 
32
  async function getTextGenerationStream(inputs: string, messageId: string, isRetry = false) {
33
  const conversationId = $page.params.id;
34
+ const responseId = randomUUID();
35
 
36
  const response = textGenerationStream(
37
  {
 
44
  },
45
  {
46
  id: messageId,
47
+ response_id: responseId,
48
  is_retry: isRetry,
49
  use_cache: false,
50
  } as Options
 
91
  messages = [
92
  ...messages,
93
  // id doesn't match the backend id but it's not important for assistant messages
94
+ { from: "assistant", content: output.token.text.trimStart(), id: responseId },
95
  ];
96
  } else {
97
  lastMessage.content += output.token.text;
src/routes/conversation/[id]/+server.ts CHANGED
@@ -38,12 +38,13 @@ export async function POST({ request, fetch, locals, params }) {
38
  const json = await request.json();
39
  const {
40
  inputs: newPrompt,
41
- options: { id: messageId, is_retry },
42
  } = z
43
  .object({
44
  inputs: z.string().trim().min(1),
45
  options: z.object({
46
  id: z.optional(z.string().uuid()),
 
47
  is_retry: z.optional(z.boolean()),
48
  }),
49
  })
@@ -110,7 +111,11 @@ export async function POST({ request, fetch, locals, params }) {
110
  }
111
  }
112
 
113
- messages.push({ from: "assistant", content: generated_text, id: crypto.randomUUID() });
 
 
 
 
114
 
115
  await collections.conversations.updateOne(
116
  {
 
38
  const json = await request.json();
39
  const {
40
  inputs: newPrompt,
41
+ options: { id: messageId, is_retry, response_id: responseId },
42
  } = z
43
  .object({
44
  inputs: z.string().trim().min(1),
45
  options: z.object({
46
  id: z.optional(z.string().uuid()),
47
+ response_id: z.optional(z.string().uuid()),
48
  is_retry: z.optional(z.boolean()),
49
  }),
50
  })
 
111
  }
112
  }
113
 
114
+ messages.push({
115
+ from: "assistant",
116
+ content: generated_text,
117
+ id: (responseId as Message["id"]) || crypto.randomUUID(),
118
+ });
119
 
120
  await collections.conversations.updateOne(
121
  {