Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move requirements generation in playground to playground worker #10126

Merged
merged 4 commits into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/clear-hats-shout.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"website": minor
---

feat:Move requirements generation in playground to playground worker
31 changes: 6 additions & 25 deletions js/_website/src/lib/components/DemosLite/DemosLite.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,14 @@
import { onMount } from "svelte";
import SYSTEM_PROMPT from "$lib/json/system_prompt.json";
import WHEEL from "$lib/json/wheel.json";
import { excludeUnavailablePackages } from "./requirements-utils";

let generated = true;

let current_code = false;
let compare = false;

const workerUrl = "https://playground-worker.pages.dev/api/generate";
// const workerUrl = "http://localhost:5174/api/generate";
// const workerUrl = "http://localhost:5173/api/generate";
let model_info = "";

let abortController: AbortController | null = null;
Expand Down Expand Up @@ -87,6 +86,8 @@
// }
} else if (parsed.info) {
console.log(parsed.info);
} else if (parsed.requirements) {
yield { requirements: parsed.requirements };
} else if (parsed.choices && parsed.choices.length > 0) {
yield parsed;
}
Expand Down Expand Up @@ -125,7 +126,9 @@
SYSTEM_PROMPT.SYSTEM,
abortController.signal
)) {
if (chunk.choices && chunk.choices.length > 0) {
if (chunk.requirements) {
demos[queried_index].requirements = chunk.requirements;
} else if (chunk.choices && chunk.choices.length > 0) {
const content = chunk.choices[0].delta.content;
if (content) {
out += content;
Expand All @@ -151,28 +154,6 @@
}
}

const system_prompt_requirements_txt = `User gives Python code.
You return the required package list in the format of \`requirements.txt\` for pip.
You exclude \`gradio\` from the package list because it's already installed in the user's environment.
You only return the content of \`requirements.txt\`, without any other texts or messages.`;
const query_requirements_txt = demos[queried_index].code;
let generated_requirements_txt = "";
for await (const chunk of streamFromWorker(
query_requirements_txt,
system_prompt_requirements_txt,
abortController.signal
)) {
if (chunk.choices && chunk.choices.length > 0) {
const content = chunk.choices[0].delta.content;
if (content) {
generated_requirements_txt += content;
}
}
}
demos[queried_index].requirements = await excludeUnavailablePackages(
generated_requirements_txt.split("\n").filter((r) => r.trim() !== "")
);

generated = true;
if (selected_demo.name === demo_name) {
highlight_changes(code_to_compare, demos[queried_index].code);
Expand Down
45 changes: 0 additions & 45 deletions js/_website/src/lib/components/DemosLite/requirements-utils.ts

This file was deleted.

Loading