mirror of
https://github.com/wahyd4/SAI2.git
synced 2026-08-09 05:06:05 +10:00
docs: add readme & fix build error (#3)
This commit is contained in:
@@ -1,2 +1,64 @@
|
||||
# search_with_lepton
|
||||
Building a quick conversation-based search demo with Lepton AI.
|
||||
<div align="center">
|
||||
<h1 align="center">Search with Lepton</h1>
|
||||
Build your own Perplexity/Phind using less than 500 lines of code.
|
||||
<br/>
|
||||
<br/>
|
||||
<img width="645" src="https://github.com/leptonai/search_with_lepton/assets/1506722/845d7057-02cd-404e-bbc7-60f4bae89680" height="500">
|
||||
</div>
|
||||
|
||||
|
||||
## 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:
|
||||
|
||||
[](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).
|
||||
|
||||
@@ -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;
|
||||
@@ -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
|
||||
}
|
||||
];
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -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 }) => {
|
||||
<Link
|
||||
prefetch={false}
|
||||
title={query}
|
||||
href={`/search.html?q=${encodeURIComponent(query)}&rid=${rid}`}
|
||||
href={getSearchUrl(query, rid)}
|
||||
className="border border-zinc-200/50 text-ellipsis overflow-hidden text-nowrap items-center rounded-lg bg-zinc-100 hover:bg-zinc-200/80 hover:text-zinc-950 px-2 py-1 text-xs font-medium text-zinc-600"
|
||||
>
|
||||
{query}
|
||||
|
||||
@@ -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()));
|
||||
}
|
||||
}}
|
||||
>
|
||||
|
||||
@@ -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 }) => {
|
||||
<div className="flex-none">
|
||||
<button
|
||||
onClick={() => {
|
||||
router.push(
|
||||
`/search.html?q=${encodeURIComponent(query)}&rid=${nanoid()}`,
|
||||
);
|
||||
router.push(getSearchUrl(encodeURIComponent(query), nanoid()));
|
||||
}}
|
||||
type="button"
|
||||
className="rounded flex gap-2 items-center bg-transparent px-2 py-1 text-xs font-semibold text-blue-500 hover:bg-zinc-100"
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
export const getSearchUrl = (query: string, search_uuid: string) => {
|
||||
const prefix =
|
||||
process.env.NODE_ENV === "production" ? "/search.html" : "/search";
|
||||
return `${prefix}?q=${encodeURIComponent(query)}&rid=${search_uuid}`;
|
||||
};
|
||||
+18
-4
@@ -1,7 +1,11 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "es2015",
|
||||
"lib": ["dom", "dom.iterable", "esnext"],
|
||||
"lib": [
|
||||
"dom",
|
||||
"dom.iterable",
|
||||
"esnext"
|
||||
],
|
||||
"allowJs": true,
|
||||
"skipLibCheck": true,
|
||||
"strict": true,
|
||||
@@ -19,9 +23,19 @@
|
||||
}
|
||||
],
|
||||
"paths": {
|
||||
"@/*": ["./src/*"]
|
||||
"@/*": [
|
||||
"./src/*"
|
||||
]
|
||||
}
|
||||
},
|
||||
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
|
||||
"exclude": ["node_modules"]
|
||||
"include": [
|
||||
"next-env.d.ts",
|
||||
"**/*.ts",
|
||||
"**/*.tsx",
|
||||
".next/types/**/*.ts",
|
||||
"../ui/types/**/*.ts"
|
||||
],
|
||||
"exclude": [
|
||||
"node_modules"
|
||||
]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user