Skip to content

Commit

Permalink
refactor: make non-streaming chat as /chat/request route (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
thucpn authored Mar 27, 2024
1 parent c7a978e commit b08cad0
Show file tree
Hide file tree
Showing 27 changed files with 80 additions and 371 deletions.
25 changes: 5 additions & 20 deletions e2e/basic.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import type {
} from "../helpers";
import { createTestDir, runCreateLlama, type AppType } from "./utils";

const templateTypes: TemplateType[] = ["streaming", "simple"];
const templateTypes: TemplateType[] = ["streaming"];
const templateFrameworks: TemplateFramework[] = [
"nextjs",
"express",
Expand All @@ -30,20 +30,8 @@ for (const templateType of templateTypes) {
for (const templateEngine of templateEngines) {
for (const templateUI of templateUIs) {
for (const templatePostInstallAction of templatePostInstallActions) {
if (templateFramework === "nextjs" && templateType === "simple") {
// nextjs doesn't support simple templates - skip tests
continue;
}
const appType: AppType =
templateFramework === "express" || templateFramework === "fastapi"
? templateType === "simple"
? "--no-frontend" // simple templates don't have frontends
: "--frontend"
: "";
if (appType === "--no-frontend" && templateUI !== "html") {
// if there's no frontend, don't iterate over UIs
continue;
}
templateFramework === "nextjs" ? "" : "--frontend";
test.describe(`try create-llama ${templateType} ${templateFramework} ${templateEngine} ${templateUI} ${appType} ${templatePostInstallAction}`, async () => {
let port: number;
let externalPort: number;
Expand Down Expand Up @@ -79,7 +67,6 @@ for (const templateType of templateTypes) {
});
test("Frontend should have a title", async ({ page }) => {
test.skip(templatePostInstallAction !== "runApp");
test.skip(appType === "--no-frontend");
await page.goto(`http://localhost:${port}`);
await expect(page.getByText("Built by LlamaIndex")).toBeVisible();
});
Expand All @@ -88,7 +75,6 @@ for (const templateType of templateTypes) {
page,
}) => {
test.skip(templatePostInstallAction !== "runApp");
test.skip(appType === "--no-frontend");
await page.goto(`http://localhost:${port}`);
await page.fill("form input", "hello");
const [response] = await Promise.all([
Expand All @@ -109,14 +95,13 @@ for (const templateType of templateTypes) {
expect(response.ok()).toBeTruthy();
});

test("Backend should response when calling API", async ({
test("Backend frameworks should response when calling non-streaming chat API", async ({
request,
}) => {
test.skip(templatePostInstallAction !== "runApp");
test.skip(appType !== "--no-frontend");
const backendPort = appType === "" ? port : externalPort;
test.skip(templateFramework === "nextjs");
const response = await request.post(
`http://localhost:${backendPort}/api/chat`,
`http://localhost:${externalPort}/api/chat/request`,
{
data: {
messages: [
Expand Down
2 changes: 1 addition & 1 deletion helpers/types.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { PackageManager } from "../helpers/get-pkg-manager";
import { Tool } from "./tools";

export type TemplateType = "simple" | "streaming" | "community" | "llamapack";
export type TemplateType = "streaming" | "community" | "llamapack";
export type TemplateFramework = "nextjs" | "express" | "fastapi";
export type TemplateEngine = "simple" | "context";
export type TemplateUI = "html" | "shadcn";
Expand Down
13 changes: 3 additions & 10 deletions questions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -380,8 +380,7 @@ export const askQuestions = async (
name: "template",
message: "Which template would you like to use?",
choices: [
{ title: "Chat without streaming", value: "simple" },
{ title: "Chat with streaming", value: "streaming" },
{ title: "Chat", value: "streaming" },
{
title: `Community template from ${styledRepo}`,
value: "community",
Expand Down Expand Up @@ -450,13 +449,10 @@ export const askQuestions = async (
program.framework = getPrefOrDefault("framework");
} else {
const choices = [
{ title: "NextJS", value: "nextjs" },
{ title: "Express", value: "express" },
{ title: "FastAPI (Python)", value: "fastapi" },
];
if (program.template === "streaming") {
// allow NextJS only for streaming template
choices.unshift({ title: "NextJS", value: "nextjs" });
}

const { framework } = await prompts(
{
Expand All @@ -473,10 +469,7 @@ export const askQuestions = async (
}
}

if (
program.template === "streaming" &&
(program.framework === "express" || program.framework === "fastapi")
) {
if (program.framework === "express" || program.framework === "fastapi") {
// if a backend-only framework is selected, ask whether we should create a frontend
// (only for streaming backends)
if (program.frontend === undefined) {
Expand Down
56 changes: 0 additions & 56 deletions templates/types/simple/express/README-template.md

This file was deleted.

3 changes: 0 additions & 3 deletions templates/types/simple/express/eslintrc.json

This file was deleted.

3 changes: 0 additions & 3 deletions templates/types/simple/express/gitignore

This file was deleted.

44 changes: 0 additions & 44 deletions templates/types/simple/express/index.ts

This file was deleted.

27 changes: 0 additions & 27 deletions templates/types/simple/express/package.json

This file was deleted.

7 changes: 0 additions & 7 deletions templates/types/simple/express/src/controllers/engine/chat.ts

This file was deleted.

1 change: 0 additions & 1 deletion templates/types/simple/express/src/observability/index.ts

This file was deleted.

8 changes: 0 additions & 8 deletions templates/types/simple/express/src/routes/chat.route.ts

This file was deleted.

10 changes: 0 additions & 10 deletions templates/types/simple/express/tsconfig.json

This file was deleted.

Empty file.
Empty file.
Empty file.
54 changes: 0 additions & 54 deletions templates/types/simple/fastapi/app/api/routers/chat.py

This file was deleted.

5 changes: 0 additions & 5 deletions templates/types/simple/fastapi/app/engine/__init__.py

This file was deleted.

41 changes: 0 additions & 41 deletions templates/types/simple/fastapi/app/settings.py

This file was deleted.

3 changes: 0 additions & 3 deletions templates/types/simple/fastapi/gitignore

This file was deleted.

Loading

0 comments on commit b08cad0

Please sign in to comment.