Spaces:
Paused
Paused
better error
Browse files
src/lib/agents/generateCode.ts
CHANGED
@@ -18,9 +18,13 @@ export async function generateCode(
|
|
18 |
|
19 |
const textAnswer = await llm.call(fullprompt);
|
20 |
|
21 |
-
|
22 |
-
|
|
|
23 |
|
24 |
-
|
25 |
-
|
|
|
|
|
|
|
26 |
}
|
|
|
18 |
|
19 |
const textAnswer = await llm.call(fullprompt);
|
20 |
|
21 |
+
try {
|
22 |
+
const regex = /```(.*?)```/gs;
|
23 |
+
const matches = [...textAnswer.matchAll(regex)];
|
24 |
|
25 |
+
const codeBlocks = matches.map((match) => match[1]);
|
26 |
+
return codeBlocks[0].replace("js\n", "") ?? "nothing";
|
27 |
+
} catch {
|
28 |
+
throw new Error("The generated text doesn't contain any code blocks.");
|
29 |
+
}
|
30 |
}
|
src/lib/components/ApiKeyModal.svelte
CHANGED
@@ -1,6 +1,7 @@
|
|
1 |
<script lang="ts">
|
2 |
import { onMount } from "svelte";
|
3 |
import { HF_ACCESS_TOKEN, OPENAI_API_KEY } from "$lib/store";
|
|
|
4 |
|
5 |
let dialogElement: HTMLDialogElement;
|
6 |
|
@@ -21,6 +22,7 @@
|
|
21 |
} else {
|
22 |
localStorage.setItem("HF_ACCESS_TOKEN", $HF_ACCESS_TOKEN);
|
23 |
localStorage.setItem("OPENAI_API_KEY", $OPENAI_API_KEY);
|
|
|
24 |
}
|
25 |
}}
|
26 |
>
|
|
|
1 |
<script lang="ts">
|
2 |
import { onMount } from "svelte";
|
3 |
import { HF_ACCESS_TOKEN, OPENAI_API_KEY } from "$lib/store";
|
4 |
+
import { goto } from "$app/navigation";
|
5 |
|
6 |
let dialogElement: HTMLDialogElement;
|
7 |
|
|
|
22 |
} else {
|
23 |
localStorage.setItem("HF_ACCESS_TOKEN", $HF_ACCESS_TOKEN);
|
24 |
localStorage.setItem("OPENAI_API_KEY", $OPENAI_API_KEY);
|
25 |
+
goto("/");
|
26 |
}
|
27 |
}}
|
28 |
>
|
src/routes/+page.svelte
CHANGED
@@ -10,7 +10,6 @@
|
|
10 |
import LlmSelector from "$lib/components/LLMSelector.svelte";
|
11 |
import type { LLM } from "$lib/types";
|
12 |
import { HFLLM } from "$lib/agents/llm";
|
13 |
-
import { get } from "svelte/store";
|
14 |
import { OPENAI_API_KEY } from "$lib/store";
|
15 |
|
16 |
let prompt =
|
@@ -68,7 +67,7 @@
|
|
68 |
<h1 class="text-3xl font-semibold w-fit mx-auto">Agents.js</h1>
|
69 |
</div>
|
70 |
|
71 |
-
{#if
|
72 |
<div class="divider" />
|
73 |
<LlmSelector bind:llm />
|
74 |
{/if}
|
|
|
10 |
import LlmSelector from "$lib/components/LLMSelector.svelte";
|
11 |
import type { LLM } from "$lib/types";
|
12 |
import { HFLLM } from "$lib/agents/llm";
|
|
|
13 |
import { OPENAI_API_KEY } from "$lib/store";
|
14 |
|
15 |
let prompt =
|
|
|
67 |
<h1 class="text-3xl font-semibold w-fit mx-auto">Agents.js</h1>
|
68 |
</div>
|
69 |
|
70 |
+
{#if $OPENAI_API_KEY !== ""}
|
71 |
<div class="divider" />
|
72 |
<LlmSelector bind:llm />
|
73 |
{/if}
|