Search with Lepton

Feb 22, 2024 | Educational

Build your own conversational search engine using less than 500 lines of code.

To see it in action, check out our Live Demo.

Search with Lepton Demo

Features

  • Built-in support for LLM
  • Built-in support for search engines
  • Customizable pretty UI interface
  • Shareable, cached search results

Setup Search Engine API

To power your search engine, you can choose from two default supported search engines: Bing and Google.

Bing Search

To use the Bing Web Search API, please visit this link to obtain your Bing subscription key.

Google Search

You have three options for Google Search:

Setup LLM and KV

We recommend using the built-in LLM and KV functions with Lepton. To set them up automatically, run the following commands:

pip install -U leptonai openai
lep login

Obtain Your Lepton AI Workspace Token

You can copy your workspace token from the Lepton AI Dashboard by navigating to Settings → Tokens.

Build Your Search Engine

Follow these steps to get your conversational search engine up and running:

  • Set your Bing subscription key:
  • export BING_SEARCH_V7_SUBSCRIPTION_KEY=YOUR_BING_SUBSCRIPTION_KEY
  • Set your Lepton AI workspace token:
  • export LEPTON_WORKSPACE_TOKEN=YOUR_LEPTON_WORKSPACE_TOKEN
  • Navigate to the web folder and install required packages:
  • cd web
    npm install
    npm run build
  • Run the server for Bing:
  • BACKEND=BING python search_with_lepton.py
  • For Google Search using SearchApi:
  • export SEARCHAPI_API_KEY=YOUR_SEARCHAPI_API_KEY
    BACKEND=SEARCHAPI python search_with_lepton.py
  • For Google Search using Serper:
  • export SERPER_SEARCH_API_KEY=YOUR_SERPER_API_KEY
    BACKEND=SERPER python search_with_lepton.py
  • For Google Search using Programmable Search Engine:
  • export GOOGLE_SEARCH_API_KEY=YOUR_GOOGLE_SEARCH_API_KEY
    export GOOGLE_SEARCH_CX=YOUR_GOOGLE_SEARCH_ENGINE_ID
    BACKEND=GOOGLE python search_with_lepton.py

Deploy Your Search Engine

You can deploy your search engine to Lepton AI with one click:

Deploy with Lepton AI

You can also deploy your own version with the following command:

lep photon run -n search-with-lepton-modified -m search_with_lepton.py --env BACKEND=BING --env BING_SEARCH_V7_SUBSCRIPTION_KEY=YOUR_BING_SUBSCRIPTION_KEY

To learn more about lep photon, visit their documentation.

Troubleshooting Ideas

If you encounter issues while setting up your conversational search engine, here are a few troubleshooting tips to consider:

  • Ensure that your API keys are correct and have not expired.
  • Check your internet connection; sometimes, connection issues can prevent successful API calls.
  • Confirm that you have the required permissions for using the APIs involved.
  • Make sure all environment variables are correctly set before running scripts.
  • If you receive specific error messages, look them up for targeted solutions.

For more insights, updates, or to collaborate on AI development projects, stay connected with fxis.ai.

At fxis.ai, we believe that such advancements are crucial for the future of AI, as they enable more comprehensive and effective solutions. Our team is continually exploring new methodologies to push the envelope in artificial intelligence, ensuring that our clients benefit from the latest technological innovations.

Understanding the Code

Think of building your search engine like crafting a recipe for a dish. In this case, each step in the command line is like an ingredient or a cooking method that contributes to the final flavor of your project. You start by gathering the key ingredients (API keys), then you prepare the base (installing packages), and as you build more layers (building the web application), you finally serve it up to your audience (deploying the search engine). Each command you run is an essential step in creating the delicious dish that will be your conversational search engine.

Stay Informed with the Newest F(x) Insights and Blogs

Tech News and Blog Highlights, Straight to Your Inbox