diff --git a/README.md b/README.md index 30d386f..d0cd7d9 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,64 @@ -# search_with_lepton -Building a quick conversation-based search demo with Lepton AI. +
+

Search with Lepton

+Build your own Perplexity/Phind using less than 500 lines of code. +
+
+ +
+ + +## Features +- Built-in support for LLM +- Built-in support for search engine +- Customizable pretty UI interface +- Shareable, cached search results + +## Setup Search Engine API + +> [!NOTE] +> Visit [here](https://www.microsoft.com/en-us/bing/apis/bing-web-search-api) to get your Bing subscription key. + +## Setup LLM and KV + +> [!NOTE] +> We recommend using the built-in llm and kv functions with Lepton. +> Running the following commands to set up them automatically. + +```shell +pip install -U leptonai && lep login +``` + + +## Development / Build + +1. Set Bing subscription key +```shell +export BING_SEARCH_V7_SUBSCRIPTION_KEY=YOUR_BING_SUBSCRIPTION_KEY +``` +2. Run server +```shell +python search_with_lepton.py +``` +3. Run web +```shell +cd web && npm install && npm run dev # dev web +``` + +```shell +cd web && npm install && npm run build # build web +``` + + +## Deploy + +You can deploy this to Lepton AI with one click: + +[![Deploy with Lepton AI](https://github.com/leptonai/search_with_lepton/assets/1506722/bbd40afa-69ee-4acb-8974-d060880a183a)](https://dashboard.lepton.ai/workspace-redirect/explore/detail/search) + +You can also deploy your own version via + +```shell +lep photon run -n search-with-lepton-modified -m search_with_lepton.py +``` + +Learn more about `lep photon` [here](https://www.lepton.ai/docs). diff --git a/web/next.config.js b/web/next.config.js deleted file mode 100644 index e7849ba..0000000 --- a/web/next.config.js +++ /dev/null @@ -1,17 +0,0 @@ -/** @type {import('next').NextConfig} */ -const nextConfig = { - output: "export", - assetPrefix: "/ui/", - basePath: "/ui", - distDir: '../ui', - async rewrites() { - return [ - { - source: "/query", - destination: "http://localhost:8080/query", // Proxy to Backend - }, - ]; - }, -}; - -module.exports = nextConfig; diff --git a/web/next.config.mjs b/web/next.config.mjs new file mode 100644 index 0000000..911cdf7 --- /dev/null +++ b/web/next.config.mjs @@ -0,0 +1,25 @@ +export default (phase, { defaultConfig }) => { + const env = process.env.NODE_ENV; + /** + * @type {import("next").NextConfig} + */ + if (env === "production") { + return { + output: "export", + assetPrefix: "/ui/", + basePath: "/ui", + distDir: "../ui" + }; + } else { + return { + async rewrites() { + return [ + { + source: "/query", + destination: "http://localhost:8080/query" // Proxy to Backend + } + ]; + } + }; + } +} diff --git a/web/src/app/components/preset-query.tsx b/web/src/app/components/preset-query.tsx index c538bb8..dbe188c 100644 --- a/web/src/app/components/preset-query.tsx +++ b/web/src/app/components/preset-query.tsx @@ -1,3 +1,4 @@ +import { getSearchUrl } from "@/app/utils/get-search-url"; import { nanoid } from "nanoid"; import Link from "next/link"; import React, { FC, useMemo } from "react"; @@ -9,7 +10,7 @@ export const PresetQuery: FC<{ query: string }> = ({ query }) => { {query} diff --git a/web/src/app/components/search.tsx b/web/src/app/components/search.tsx index 58461be..e2955e1 100644 --- a/web/src/app/components/search.tsx +++ b/web/src/app/components/search.tsx @@ -1,4 +1,5 @@ "use client"; +import { getSearchUrl } from "@/app/utils/get-search-url"; import { ArrowRight } from "lucide-react"; import { nanoid } from "nanoid"; import { useRouter } from "next/navigation"; @@ -13,9 +14,7 @@ export const Search: FC = () => { e.preventDefault(); if (value) { setValue(""); - router.push( - `/search.html?q=${encodeURIComponent(value)}&rid=${nanoid()}`, - ); + router.push(getSearchUrl(encodeURIComponent(value), nanoid())); } }} > diff --git a/web/src/app/components/title.tsx b/web/src/app/components/title.tsx index ba89d6e..579d936 100644 --- a/web/src/app/components/title.tsx +++ b/web/src/app/components/title.tsx @@ -1,4 +1,5 @@ "use client"; +import { getSearchUrl } from "@/app/utils/get-search-url"; import { RefreshCcw } from "lucide-react"; import { nanoid } from "nanoid"; import { useRouter } from "next/navigation"; @@ -16,9 +17,7 @@ export const Title = ({ query }: { query: string }) => {