Skip to content

Commit

Permalink
Move requirements generation in playground to playground worker (#10126)
Browse files Browse the repository at this point in the history
* move requirements genereation

* formatting

* add changeset

---------

Co-authored-by: gradio-pr-bot <[email protected]>
  • Loading branch information
aliabd and gradio-pr-bot authored Dec 5, 2024
1 parent c5ae607 commit a623faf
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 70 deletions.
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.

0 comments on commit a623faf

Please sign in to comment.