From 30fe269575f9c324a99cba2f5abba235c80b6e28 Mon Sep 17 00:00:00 2001 From: Huu Le <39040748+leehuwuj@users.noreply.github.com> Date: Wed, 20 Nov 2024 17:26:42 +0700 Subject: [PATCH] Update duckduckgo tool option (#439) --- .changeset/khaki-cobras-heal.md | 5 ++++ .changeset/strange-icons-walk.md | 5 ++++ create-app.ts | 4 ++-- helpers/copy.ts | 3 +++ helpers/tools.ts | 2 +- helpers/{devcontainer.ts => vscode.ts} | 24 ++++++++++++++++++- questions/simple.ts | 2 +- .../components/services/python/suggestion.py | 8 ++++--- templates/vscode_settings.json | 3 +++ 9 files changed, 48 insertions(+), 8 deletions(-) create mode 100644 .changeset/khaki-cobras-heal.md create mode 100644 .changeset/strange-icons-walk.md rename helpers/{devcontainer.ts => vscode.ts} (69%) create mode 100644 templates/vscode_settings.json diff --git a/.changeset/khaki-cobras-heal.md b/.changeset/khaki-cobras-heal.md new file mode 100644 index 00000000..43b94a75 --- /dev/null +++ b/.changeset/khaki-cobras-heal.md @@ -0,0 +1,5 @@ +--- +"create-llama": patch +--- + +Deactive duckduckgo tool for TS diff --git a/.changeset/strange-icons-walk.md b/.changeset/strange-icons-walk.md new file mode 100644 index 00000000..4e877a43 --- /dev/null +++ b/.changeset/strange-icons-walk.md @@ -0,0 +1,5 @@ +--- +"create-llama": patch +--- + +Replace DuckDuckGo by Wikipedia tool for agentic template diff --git a/create-app.ts b/create-app.ts index c90c8c5d..8849c0fb 100644 --- a/create-app.ts +++ b/create-app.ts @@ -10,9 +10,9 @@ import { makeDir } from "./helpers/make-dir"; import terminalLink from "terminal-link"; import type { InstallTemplateArgs, TemplateObservability } from "./helpers"; import { installTemplate } from "./helpers"; -import { writeDevcontainer } from "./helpers/devcontainer"; import { templatesDir } from "./helpers/dir"; import { toolsRequireConfig } from "./helpers/tools"; +import { configVSCode } from "./helpers/vscode"; export type InstallAppArgs = Omit< InstallTemplateArgs, @@ -105,7 +105,7 @@ export async function createApp({ }); } - await writeDevcontainer(root, templatesDir, framework, frontend); + await configVSCode(root, templatesDir, framework); process.chdir(root); if (tryGitInit(root)) { diff --git a/helpers/copy.ts b/helpers/copy.ts index 8543c692..2568d836 100644 --- a/helpers/copy.ts +++ b/helpers/copy.ts @@ -61,6 +61,9 @@ export const assetRelocator = (name: string) => { case "README-template.md": { return "README.md"; } + case "vscode_settings.json": { + return "settings.json"; + } default: { return name; } diff --git a/helpers/tools.ts b/helpers/tools.ts index 2be92636..5d3ab929 100644 --- a/helpers/tools.ts +++ b/helpers/tools.ts @@ -65,7 +65,7 @@ export const supportedTools: Tool[] = [ version: "^6.3.5", }, ], - supportedFrameworks: ["fastapi", "nextjs", "express"], + supportedFrameworks: ["fastapi"], // TODO: Re-enable this tool once the duck-duck-scrape TypeScript library works again type: ToolType.LOCAL, envVars: [ { diff --git a/helpers/devcontainer.ts b/helpers/vscode.ts similarity index 69% rename from helpers/devcontainer.ts rename to helpers/vscode.ts index 153add21..e986a55b 100644 --- a/helpers/devcontainer.ts +++ b/helpers/vscode.ts @@ -1,5 +1,6 @@ import fs from "fs"; import path from "path"; +import { assetRelocator, copy } from "./copy"; import { TemplateFramework } from "./types"; function renderDevcontainerContent( @@ -29,7 +30,6 @@ export const writeDevcontainer = async ( root: string, templatesDir: string, framework: TemplateFramework, - frontend: boolean, ) => { const devcontainerDir = path.join(root, ".devcontainer"); if (fs.existsSync(devcontainerDir)) { @@ -46,3 +46,25 @@ export const writeDevcontainer = async ( devcontainerContent, ); }; + +export const copyVSCodeSettings = async ( + root: string, + templatesDir: string, +) => { + const vscodeDir = path.join(root, ".vscode"); + await copy("vscode_settings.json", vscodeDir, { + cwd: templatesDir, + rename: assetRelocator, + }); +}; + +export const configVSCode = async ( + root: string, + templatesDir: string, + framework: TemplateFramework, +) => { + await writeDevcontainer(root, templatesDir, framework); + if (framework === "fastapi") { + await copyVSCodeSettings(root, templatesDir); + } +}; diff --git a/questions/simple.ts b/questions/simple.ts index 16052b39..8571021f 100644 --- a/questions/simple.ts +++ b/questions/simple.ts @@ -131,7 +131,7 @@ const convertAnswers = async ( > = { rag: { template: "streaming", - tools: getTools(["duckduckgo"]), + tools: getTools(["wikipedia.WikipediaToolSpec"]), frontend: true, dataSources: [EXAMPLE_FILE], }, diff --git a/templates/components/services/python/suggestion.py b/templates/components/services/python/suggestion.py index 7959088e..015065fe 100644 --- a/templates/components/services/python/suggestion.py +++ b/templates/components/services/python/suggestion.py @@ -60,10 +60,12 @@ class NextQuestionSuggestion: return None @classmethod - def _extract_questions(cls, text: str) -> List[str]: + def _extract_questions(cls, text: str) -> List[str] | None: content_match = re.search(r"```(.*?)```", text, re.DOTALL) - content = content_match.group(1) if content_match else "" - return content.strip().split("\n") + content = content_match.group(1) if content_match else None + if not content: + return None + return [q.strip() for q in content.split("\n") if q.strip()] @classmethod async def suggest_next_questions( diff --git a/templates/vscode_settings.json b/templates/vscode_settings.json new file mode 100644 index 00000000..5be766aa --- /dev/null +++ b/templates/vscode_settings.json @@ -0,0 +1,3 @@ +{ + "python.envFile": "" +} -- GitLab