Vercel + Morphic + Tavily:Build Your Custom AI Q&A System in 30 Minutes

Authors

OpenAI's recently launched SearchGPT might not have shaken Google's position, but it has certainly posed a significant threat to its investor, Microsoft, to the extent that Microsoft has directly listed OpenAI as a strategic competitor. At first glance, building a dedicated AI question-answering system seems like a complex and time-consuming task. However, with the help of existing SaaS tools, we can achieve this goal in a very short time. This article will show you how to quickly set up an efficient and intelligent AI Q&A system in just 30 minutes using Vercel, Morphic, and Tavily. Buckle up; the results will definitely exceed your expectations.

vercelmorphictavilyb-1

Component Overview

What is Vercel?

Vercel is a cloud platform, accessible at https://www.vercel.com/, focused on frontend development and deployment. It provides highly optimized infrastructure for building and deploying modern web applications. Initially launched as Zeit Now, the platform was later renamed Vercel. It supports automated deployment of static sites and dynamic applications and seamlessly integrates with many popular frontend frameworks like Next.js and React.

What is Morphic?

Morphic is an AI-driven search engine with a generative user interface, available at https://github.com/miurla/morphic, built with Next.js and without other dependencies.

What is Tavily?

Tavily is a search engine optimized for large language models (LLMs) and retrieval-augmented generation (RAG), available at https://app.tavily.com/home. It aims to provide efficient, fast, and persistent search results. Unlike other search APIs such as Serp or Google, Tavily focuses on optimizing search for AI developers and autonomous AI agents.

Preparation - Applying for API Keys on Various Platforms

Before setting up Morphic, we first need to apply for the necessary API keys on the relevant SaaS platforms according to our specific needs. These platforms are free for small-scale usage, allowing you to start experimenting without any worries. Morphic supports multiple environment variable configurations, and here we use OpenAI's native API key as an example, requiring the following four environment variables: OPENAI_API_KEY, TAVILY_API_KEY, UPSTASH_REDIS_REST_URL, and UPSTASH_REDIS_REST_TOKEN. Now, let's obtain these essential API keys from various platforms and easily start your AI Q&A system journey.

# OpenAI API key can be obtained here: https://platform.openai.com/api-keys
OPENAI_API_KEY=[Your OpenAI API key]

# Tavily API key can be obtained here: https://app.tavily.com/home
TAVILY_API_KEY=[Your Tavily API key]

# Upstash Redis URL and token can be obtained here: https://console.upstash.com/redis
UPSTASH_REDIS_REST_URL=[Your Upstash Redis REST URL]
UPSTASH_REDIS_REST_TOKEN=[Your Upstash Redis REST token]

# Optional settings
# These settings can be optionally used as needed.

# To set the base URL path for OpenAI API requests.
# Uncomment and set the following if you need to set the base URL:
# OPENAI_API_BASE=

# To set the model for OpenAI API requests.
# If not set, the default is gpt-4o.
# OPENAI_API_MODEL=gpt-4o-mini

# If you want to use Google Generative AI instead of OpenAI, enable the following settings.
# Google Generative AI API key can be obtained here: https://aistudio.google.com/app/apikey
# GOOGLE_GENERATIVE_AI_API_KEY=[Your Google Generative AI API key]

# If you want to use Anthropic instead of OpenAI, enable the following settings.
# ANTHROPIC_API_KEY=[Your Anthropic API key]

# [Unstable] If you want to use Ollama, enable the following variables.
# OLLAMA_MODEL=[Your Ollama model] # Primary model to use. Recommended: mistral or openhermes
# OLLAMA_SUB_MODEL=[Your Ollama sub-model] # Sub-model to use. Recommended: phi3 or llama3
# OLLAMA_BASE_URL=[Your Ollama URL] # Base URL to use. For example: http://localhost:11434

# Only writers can set a specific model. It must be compatible with the OpenAI API.
# USE_SPECIFIC_API_FOR_WRITER=true
# SPECIFIC_API_BASE=[Your API base URL] # For example: https://api.groq.com/openai/v1
# SPECIFIC_API_KEY=[Your API key]
# SPECIFIC_API_MODEL=[Your API model] # For example: llama-3.1-70b-versatile

# Enable share functionality
# If you enable this, you need to implement account management separately.
# ENABLE_SHARE=true

# Enable video search tool
# Serper API key can be obtained here: https://serper.dev/api-key
# SERPER_API_KEY=[Your Serper API key]

Applying for OpenAI API Key

There are many online tutorials for this. If you do not meet the relevant requirements, you can also use the OpenRouter platform I recommended earlier to apply for the corresponding API key.

Applying for Tavily AI API Key

Go to https://app.tavily.com/home, log in with your Google account, and follow the system prompts.

vercelmorphictavilyb-2

Applying for Redis - Upstash API Key

vercelmorphictavilyb-3
vercelmorphictavilyb-4

Deploying Morphic via Vercel

Go to Morphic: AI-powered answer engine – Vercel and click Deploy.

vercelmorphictavilyb-0

Select your GitHub repository and fill in the environment variables. Note that only two environment variables are prompted here, but four are actually required. Since this entry is not open, first fill in two environment variables, then modify the project in Vercel after creation.

vercelmorphictavilyb-6

After submitting the above steps, Vercel will fail to build. At this point, go to Vercel to modify the environment variables, fill in the API keys we applied for in the previous steps, and redeploy.

vercelmorphictavilyb-7
vercelmorphictavilyb-8

With this, the system deployment is complete, and we can use the service through the domain provided by Vercel.

Testing the System

Let's try inputting a few representative questions to test the system.

Who is the women's singles champion in tennis at the 2024 Olympics?

vercelmorphictavilyb-9

How did Zheng Qinwen perform in the women's singles tennis match at the 2024 Paris Olympics?

vercelmorphictavilyb-10

You will find that the system's response speed is astonishingly fast, and the timeliness of the information is also excellent. Content released last night can now be easily searched.

Conclusion

Through the above steps, we successfully used Vercel, Morphic, and Tavily to build a simple yet powerful AI Q&A system. This system not only has a solid architecture but can also be optimized and adjusted according to actual needs. For example, we can expand the sources of information and integrate specialized knowledge bases from various industries. The foundation has been laid; how to fully unleash the potential of these tools is entirely up to your creativity!

If you have any questions or suggestions about this article, feel free to leave a comment and share your thoughts.

Share this content