This is a Next.js application providing backend API endpoints for various AI-powered writing features, including chat interactions, text autocompletion, and blog post management.
- /api/chat: Handles chat interactions, allowing users to interact with an AI model. It supports different modes like agent-based document modification and conversational assistance. Integrates with Composio tools.
- /api/autocomplete: Provides text autocompletion suggestions based on the current text and context, powered by an AI model.
- /api/blogs: Manages blog posts, allowing fetching and saving posts (stored as JSON files locally).
- Next.js - React framework for server-side rendering and API routes.
- TypeScript - Typed superset of JavaScript.
- Vercel AI SDK - For integrating AI models and features.
- OpenAI / Google AI - Language models used for generation.
- Composio - For integrating third-party tools via Vercel AI SDK.
- dotenv - For loading environment variables.
-
Clone the repository:
git clone <your-repository-url> cd <repository-directory>
-
Install dependencies:
npm install # or yarn install
-
Set up environment variables: Create a
.env
file in the root directory and add the necessary API keys:# Required for /api/chat and /api/autocomplete OPENAI_API_KEY=your_openai_api_key # Optional alternative model for /api/chat and /api/autocomplete (uncomment if used) # GOOGLE_GENERATIVE_AI_API_KEY=your_google_api_key # Required for Composio tool integration in /api/chat COMPOSIO_API_KEY=your_composio_api_key NEXT_PUBLIC_LOCAL_ENV=False #Change to True for full functionality # Add any other keys used by Composio tools or other services # Example: GROQ_API_KEY, MISTRAL_API_KEY, SOLANA keys... # (Only include if actively used by your Composio-integrated tools)
Replace
your_..._key
with your actual API keys. -
Run the development server:
npm run dev # or yarn dev
The application will start, typically on
http://localhost:3000
.
POST /api/chat
: Accepts JSON body withmessage
,currentContent
(optional),selections
(optional),mode
('agent' or 'ask'), andcomposioApiKey
. Returns AI-generated chat responses or document modifications.POST /api/autocomplete
: Accepts JSON body withtext
,cursorPosition
, andcontext
(optional). Returns AI-generated text completion suggestions.GET /api/blogs
: Fetches all blog posts stored in theblogs/
directory.POST /api/blogs
: Saves a new blog post. Accepts JSON body representing the post structure.