### Install and Run Next.js Development Server
Source: https://github.com/nlkitai/nlux/blob/latest/examples/next-js-demos/nlux-with-app-router/README.md
Installs project dependencies and starts the development server for a Next.js application. Access the demo at http://localhost:3000.
```bash
npm install
npm run dev
```
--------------------------------
### Set up TypeScript Project with Vite
Source: https://github.com/nlkitai/nlux/blob/latest/docs/docs/learn/002-get-started/_002-nlux-with-langchain/
Use these npm commands to initialize a new project with the vanilla-ts template, install dependencies, and start the development server.
```bash
npm create vite@latest my-ai-chat-app -- --template vanilla-ts
cd my-ai-chat-app
npm install
npm run dev
```
--------------------------------
### Run Dev Server
Source: https://github.com/nlkitai/nlux/blob/latest/pipeline/README.md
Resets the repository, installs dependencies, and starts the dev server on port 9090. Ensure Node 18+ is installed.
```bash
yarn run reset
yarn run dev
```
--------------------------------
### Install Project Dependencies
Source: https://github.com/nlkitai/nlux/blob/latest/docs/README.md
Run this command to install all necessary project dependencies.
```bash
$ yarn
```
--------------------------------
### Install Dependencies
Source: https://github.com/nlkitai/nlux/blob/latest/examples/ui-components/shadcn/chatgpt-inspired-ui/README.md
Install project dependencies using npm, yarn, or pnpm.
```bash
npm install
# or
yarn
# or
pnpm install
```
--------------------------------
### Clone Repository
Source: https://github.com/nlkitai/nlux/blob/latest/examples/ui-components/shadcn/chatgpt-inspired-ui/README.md
Clone the demo repository to get started with the NLUX, shadcn/ui, and Tailwind CSS project.
```bash
git clone git@github.com:nlkitai/demos.git
```
--------------------------------
### Install @nlux/react with Yarn
Source: https://github.com/nlkitai/nlux/blob/latest/docs/docs/reference/002-ui/_001-ai-chat/
Use this command to install the package if you are using Yarn.
```bash
yarn add @nlux/react
```
--------------------------------
### Install @nlux/openai-react with NPM
Source: https://github.com/nlkitai/nlux/blob/latest/docs/docs/reference/005-adapters/_005-open-ai/
Use this command to install the package if you are using NPM.
```bash
npm install @nlux/openai-react
```
--------------------------------
### Install @nlux/langchain with Yarn
Source: https://github.com/nlkitai/nlux/blob/latest/docs/docs/reference/005-adapters/_003-langchain-langserve/
Use this command to install the package if you are using Yarn.
```bash
yarn add @nlux/langchain
```
--------------------------------
### Install @nlux/openai-react with Yarn
Source: https://github.com/nlkitai/nlux/blob/latest/docs/docs/reference/005-adapters/_005-open-ai/
Use this command to install the package if you are using Yarn.
```bash
yarn add @nlux/openai-react
```
--------------------------------
### Install @nlux/langchain with NPM
Source: https://github.com/nlkitai/nlux/blob/latest/docs/docs/reference/005-adapters/_003-langchain-langserve/
Use this command to install the package if you are using NPM.
```bash
npm install @nlux/langchain
```
--------------------------------
### Install @nlux/hf-react with NPM
Source: https://github.com/nlkitai/nlux/blob/latest/docs/docs/learn/003-adapters/002-hugging-face/_002-llama-2-chatbot/
Use this command to install the library if you are using npm.
```bash
npm install @nlux/hf-react
```
--------------------------------
### Start Local Development Server
Source: https://github.com/nlkitai/nlux/blob/latest/docs/README.md
Starts a local development server for live previewing changes. Changes are reflected live without server restarts.
```bash
$ yarn dev
```
--------------------------------
### Install @nlux/openai with NPM
Source: https://github.com/nlkitai/nlux/blob/latest/docs/docs/reference/005-adapters/_005-open-ai/
Use this command to install the package using NPM.
```bash
npm install @nlux/openai
```
--------------------------------
### Install @nlux/hf-react with Yarn
Source: https://github.com/nlkitai/nlux/blob/latest/docs/docs/learn/003-adapters/002-hugging-face/_002-llama-2-chatbot/
Use this command to install the library if you are using yarn.
```bash
yarn add @nlux/hf-react
```
--------------------------------
### Install @nlux/react with NPM
Source: https://github.com/nlkitai/nlux/blob/latest/docs/docs/reference/002-ui/_001-ai-chat/
Use this command to install the package if you are using NPM.
```bash
npm install @nlux/react
```
--------------------------------
### Install @nlux/openai with Yarn
Source: https://github.com/nlkitai/nlux/blob/latest/docs/docs/reference/005-adapters/_005-open-ai/
Use this command to install the package using Yarn.
```bash
yarn add @nlux/openai
```
--------------------------------
### Install @nlux/hf-react with PNPM
Source: https://github.com/nlkitai/nlux/blob/latest/docs/docs/learn/003-adapters/002-hugging-face/_002-llama-2-chatbot/
Use this command to install the library if you are using pnpm.
```bash
pnpm add @nlux/hf-react
```
--------------------------------
### Install @nlux/core with Yarn
Source: https://github.com/nlkitai/nlux/blob/latest/docs/docs/reference/002-ui/_001-ai-chat/
Use this command to install the package using Yarn.
```bash
yarn add @nlux/core
```
--------------------------------
### Install Dependencies with NPM
Source: https://github.com/nlkitai/nlux/blob/latest/docs/docs/learn/002-get-started/_003-nlux-nodejs-nlbridge-chatgpt/nodejs/002-create-express-server.mdx
Use these commands to initialize a new Node.js project and install development and production dependencies using NPM.
```bash
npm init --yes
npm install --dev typescript ts-node @types/node @types/express @types/cors
npm install express cors
npx tsc --init
```
--------------------------------
### Install @nlux/openai with PNPM
Source: https://github.com/nlkitai/nlux/blob/latest/docs/docs/reference/005-adapters/_005-open-ai/
Use this command to install the package using PNPM.
```bash
pnpm add @nlux/openai
```
--------------------------------
### Install @nlux/openai-react with PNPM
Source: https://github.com/nlkitai/nlux/blob/latest/docs/docs/reference/005-adapters/_005-open-ai/
Use this command to install the package if you are using PNPM.
```bash
pnpm add @nlux/openai-react
```
--------------------------------
### Install @nlux/core with NPM
Source: https://github.com/nlkitai/nlux/blob/latest/docs/docs/reference/002-ui/_001-ai-chat/
Use this command to install the package using NPM.
```bash
npm install @nlux/core
```
--------------------------------
### Run the Demo Application
Source: https://github.com/nlkitai/nlux/blob/latest/docs/docs/learn/008-context-aware-conversations.mdx
Start the NLUX demo application using npm.
```bash
npm run dev
```
--------------------------------
### Install Dependencies with Yarn
Source: https://github.com/nlkitai/nlux/blob/latest/docs/docs/learn/002-get-started/_003-nlux-nodejs-nlbridge-chatgpt/nodejs/002-create-express-server.mdx
Use these commands to initialize a new Node.js project and install development and production dependencies using Yarn.
```bash
yarn init --yes
yarn add --dev typescript ts-node @types/node @types/express @types/cors
yarn add express cors
yarn tsc --init
```
--------------------------------
### Install @nlux/react with PNPM
Source: https://github.com/nlkitai/nlux/blob/latest/docs/docs/reference/002-ui/_001-ai-chat/
Use this command to install the package if you are using PNPM.
```bash
pnpm add @nlux/react
```
--------------------------------
### Install @nlux/langchain with PNPM
Source: https://github.com/nlkitai/nlux/blob/latest/docs/docs/reference/005-adapters/_003-langchain-langserve/
Use this command to install the package if you are using PNPM.
```bash
pnpm add @nlux/langchain
```
--------------------------------
### Install Dependencies with PNPM
Source: https://github.com/nlkitai/nlux/blob/latest/docs/docs/learn/002-get-started/_003-nlux-nodejs-nlbridge-chatgpt/nodejs/002-create-express-server.mdx
Use these commands to initialize a new Node.js project and install development and production dependencies using PNPM.
```bash
pnpm init
pnpm install -D typescript ts-node @types/node @types/express @types/cors
pnpm install express cors
pnpm tsc --init
```
--------------------------------
### Install @nlux/core with PNPM
Source: https://github.com/nlkitai/nlux/blob/latest/docs/docs/reference/002-ui/_001-ai-chat/
Use this command to install the package using PNPM.
```bash
pnpm add @nlux/core
```
--------------------------------
### Install Dependencies
Source: https://github.com/nlkitai/nlux/blob/latest/docs/docs/learn/008-context-aware-conversations.mdx
Install the necessary dependencies for the NLUX demo application using npm.
```bash
npm install
```
--------------------------------
### Run Development Server
Source: https://github.com/nlkitai/nlux/blob/latest/examples/ui-components/shadcn/chatgpt-inspired-ui/README.md
Start the development server to view and interact with the chat interface.
```bash
npm run dev
# or
yarn dev
# or
pnpm dev
```
--------------------------------
### Setup for Conversation Starters
Source: https://github.com/nlkitai/nlux/blob/latest/docs/docs/examples/0009-conversation-starters.mdx
This setup file appears to be boilerplate or configuration for the NLUX application, potentially including initial state or component rendering logic related to conversation starters.
```typescript
import React from "react";
import ReactDOM from "react-dom/client";
import App from "./App";
const root = ReactDOM.createRoot(
document.getElementById("root") as HTMLElement
);
root.render(
);
```
--------------------------------
### Install NLUX Core and NL Bridge with NPM
Source: https://github.com/nlkitai/nlux/blob/latest/docs/docs/learn/002-get-started/_003-nlux-nodejs-nlbridge-chatgpt/javascript/004-install.mdx
Use this command to install the necessary packages with npm.
```bash
npm install @nlux/core @nlux/nlbridge
```
--------------------------------
### Run Development Server
Source: https://github.com/nlkitai/nlux/blob/latest/examples/dev-examples/aiChat/next/README.md
Use these commands to start the Next.js development server. Open http://localhost:3000 in your browser to view the application.
```bash
npm run dev
```
```bash
yarn dev
```
```bash
pnpm dev
```
```bash
bun dev
```
--------------------------------
### Install NLux Langchain React with Yarn
Source: https://github.com/nlkitai/nlux/blob/latest/docs/docs/reference/005-adapters/_003-langchain-langserve/
Use this command to install the package if you are using Yarn.
```bash
yarn add @nlux/langchain-react
```
--------------------------------
### Install NLux Langchain React with NPM
Source: https://github.com/nlkitai/nlux/blob/latest/docs/docs/reference/005-adapters/_003-langchain-langserve/
Use this command to install the package if you are using NPM.
```bash
npm install @nlux/langchain-react
```
--------------------------------
### Run Your App (JavaScript)
Source: https://github.com/nlkitai/nlux/blob/latest/docs/docs/learn/002-get-started/003-nlux-nodejs-nlbridge-chatgpt.mdx
Start your Node.js server and then run your JavaScript front-end application to test the chat integration.
```bash
# Start the Node.js server
npm run dev
# In a separate terminal, start the front-end app
npm start
```
--------------------------------
### Install NLUX Core and NL Bridge with Yarn
Source: https://github.com/nlkitai/nlux/blob/latest/docs/docs/learn/002-get-started/_003-nlux-nodejs-nlbridge-chatgpt/javascript/004-install.mdx
Use this command to install the necessary packages with yarn.
```bash
yarn add @nlux/core @nlux/nlbridge
```
--------------------------------
### Install NLUX Core and NL Bridge with PNPM
Source: https://github.com/nlkitai/nlux/blob/latest/docs/docs/learn/002-get-started/_003-nlux-nodejs-nlbridge-chatgpt/javascript/004-install.mdx
Use this command to install the necessary packages with pnpm.
```bash
pnpm add @nlux/core @nlux/nlbridge
```
--------------------------------
### Install NLux Langchain React with PNPM
Source: https://github.com/nlkitai/nlux/blob/latest/docs/docs/reference/005-adapters/_003-langchain-langserve/
Use this command to install the package if you are using PNPM.
```bash
pnpm add @nlux/langchain-react
```
--------------------------------
### Install NLUX Dependencies with NPM
Source: https://github.com/nlkitai/nlux/blob/latest/docs/docs/learn/002-get-started/001-vercel-ai.mdx
Install the necessary NLUX React and themes packages using npm.
```bash
npm install @nlux/react @nlux/themes
```
--------------------------------
### Install NLUX Themes with NPM
Source: https://github.com/nlkitai/nlux/blob/latest/docs/docs/learn/002-get-started/_002-nlux-with-langchain/javascript/005-style.mdx
Use this command to install the NLUX themes package if you are using NPM.
```bash
npm install @nlux/themes
```
--------------------------------
### Install NLUX Packages (JavaScript)
Source: https://github.com/nlkitai/nlux/blob/latest/docs/docs/learn/002-get-started/003-nlux-nodejs-nlbridge-chatgpt.mdx
Install the necessary NLUX packages for your JavaScript front-end application.
```bash
npm install @nlbridge/core @nlbridge/react
npm install --save-dev @nlbridge/react
```
--------------------------------
### Install NLux Hugging Face Adapter (NPM)
Source: https://github.com/nlkitai/nlux/blob/latest/docs/docs/learn/003-adapters/002-hugging-face/_002-llama-2-chatbot/
Install the NLux Hugging Face adapter using npm. This is the first step to connect to Llama models.
```bash
npm install @nlux/hf
```
--------------------------------
### Install NLUX Packages with NPM
Source: https://github.com/nlkitai/nlux/blob/latest/docs/docs/learn/002-get-started/_002-nlux-with-langchain/javascript/001-install.mdx
Use this command to install the core and Langchain packages for NLUX using npm.
```bash
npm install @nlux/core @nlux/langchain
```
--------------------------------
### Install NLUX Themes with Yarn
Source: https://github.com/nlkitai/nlux/blob/latest/docs/docs/learn/002-get-started/_002-nlux-with-langchain/javascript/005-style.mdx
Use this command to install the NLUX themes package if you are using Yarn.
```bash
yarn add @nlux/themes
```
--------------------------------
### Install NLUX Themes with PNPM
Source: https://github.com/nlkitai/nlux/blob/latest/docs/docs/learn/002-get-started/_002-nlux-with-langchain/javascript/005-style.mdx
Use this command to install the NLUX themes package if you are using PNPM.
```bash
pnpm add @nlux/themes
```
--------------------------------
### Install NLUX Packages with PNPM
Source: https://github.com/nlkitai/nlux/blob/latest/docs/docs/learn/002-get-started/_002-nlux-with-langchain/javascript/001-install.mdx
Use this command to install the core and Langchain packages for NLUX using pnpm.
```bash
pnpm add @nlux/core @nlux/langchain
```
--------------------------------
### Dev Server with UMD Bundling
Source: https://github.com/nlkitai/nlux/blob/latest/pipeline/README.md
Resets the repository and starts the dev server using Universal Module Definition (UMD) bundling. Requires Node 18+.
```bash
NLUX_BUNDLER_PACKAGE_TYPE=umd yarn reset
NLUX_BUNDLER_PACKAGE_TYPE=umd yarn dev
```
--------------------------------
### Install NLUX Core and HF Packages
Source: https://github.com/nlkitai/nlux/blob/latest/docs/docs/learn/002-get-started/_005-nlux-hugging-face-inference/javascript/002-install.mdx
Use npm, yarn, or pnpm to add the necessary NLUX packages to your project. These commands install the core library and the Hugging Face integration.
```bash
npm install @nlux/core @nlux/hf
```
```bash
yarn add @nlux/core @nlux/hf
```
```bash
pnpm add @nlux/core @nlux/hf
```
--------------------------------
### JSX and Reactivity Example (JavaScript)
Source: https://github.com/nlkitai/nlux/blob/latest/docs/docs/learn/005-chat-personas.mdx
This JavaScript code demonstrates JSX and reactivity concepts within the NLUX framework.
```javascript
const JsxAndReactivity = () => {
return (
JSX and Reactivity
This is a demonstration of JSX and reactivity.
);
};
```
--------------------------------
### Integrate NLUX Syntax Highlighter
Source: https://github.com/nlkitai/nlux/blob/latest/docs/docs/reference/002-ui/_001-ai-chat/config/
Install the `@nlux/highlighter` package and pass it to the `syntaxHighlighter` prop to enable syntax highlighting for AI-generated code.
```javascript
import { NLUX } from "@nlux/react";
import highlighter from "@nlux/highlighter";
function App() {
return (
);
}
```
--------------------------------
### Install Vercel AI SDK Dependencies with NPM
Source: https://github.com/nlkitai/nlux/blob/latest/docs/docs/learn/002-get-started/001-vercel-ai.mdx
Install the Vercel AI SDK core, OpenAI integration, React bindings, and Zod for validation using npm.
```bash
npm install ai @ai-sdk/openai @ai-sdk/react zod
```
--------------------------------
### Install NLUX Packages with Yarn
Source: https://github.com/nlkitai/nlux/blob/latest/docs/docs/learn/002-get-started/_002-nlux-with-langchain/javascript/001-install.mdx
Use this command to install the core and Langchain packages for NLUX using yarn.
```bash
yarn add @nlux/core @nlux/langchain
```
--------------------------------
### Install NLUX React Packages with NPM
Source: https://github.com/nlkitai/nlux/blob/latest/docs/docs/learn/002-get-started/_005-nlux-hugging-face-inference/react-js/002-install.mdx
Use this command to install the core React and Hugging Face React packages for NLUX using npm.
```bash
npm install @nlux/react @nlux/hf-react
```
--------------------------------
### Install Vercel AI SDK Dependencies with PNPM
Source: https://github.com/nlkitai/nlux/blob/latest/docs/docs/learn/002-get-started/001-vercel-ai.mdx
Install the Vercel AI SDK core, OpenAI integration, React bindings, and Zod for validation using PNPM.
```bash
pnpm install ai @ai-sdk/openai @ai-sdk/react zod
```
--------------------------------
### Dev Server with CJS Bundling
Source: https://github.com/nlkitai/nlux/blob/latest/pipeline/README.md
Resets the repository and starts the dev server using CommonJS (CJS) bundling. Requires Node 18+.
```bash
NLUX_BUNDLER_PACKAGE_TYPE=cjs yarn reset
NLUX_BUNDLER_PACKAGE_TYPE=cjs yarn dev
```
--------------------------------
### Install NLUX React Packages with Yarn
Source: https://github.com/nlkitai/nlux/blob/latest/docs/docs/learn/002-get-started/_005-nlux-hugging-face-inference/react-js/002-install.mdx
Use this command to install the core React and Hugging Face React packages for NLUX using Yarn.
```bash
yarn add @nlux/react @nlux/hf-react
```
--------------------------------
### Install NLUX React and LangChain Adapter
Source: https://github.com/nlkitai/nlux/blob/latest/pipeline/npm/react/README.md
Install the necessary packages for NLUX React and the LangChain adapter using npm. This is the first step to integrating NLUX with LangChain for LLM backends.
```sh
npm install @nlux/react @nlux/langchain-react
```
--------------------------------
### Install Vercel AI SDK Dependencies with Yarn
Source: https://github.com/nlkitai/nlux/blob/latest/docs/docs/learn/002-get-started/001-vercel-ai.mdx
Install the Vercel AI SDK core, OpenAI integration, React bindings, and Zod for validation using Yarn.
```bash
yarn add ai @ai-sdk/openai @ai-sdk/react zod
```
--------------------------------
### Create React App with NLUX
Source: https://github.com/nlkitai/nlux/blob/latest/README.md
Use this command to quickly spin up a new React project with NLUX integrated using Vite. Ensure you have npx installed.
```sh
npx nlux-cli create react my-react-app
```
--------------------------------
### Install @nlbridge/express with NPM
Source: https://github.com/nlkitai/nlux/blob/latest/docs/docs/learn/002-get-started/_003-nlux-nodejs-nlbridge-chatgpt/nodejs/003-nlbridge-endpoint.mdx
Use this command to add the @nlbridge/express library to your project using NPM.
```bash
npm install @nlbridge/express
```
--------------------------------
### Navigate to Project Directory
Source: https://github.com/nlkitai/nlux/blob/latest/examples/ui-components/shadcn/chatgpt-inspired-ui/README.md
Change into the specific project directory after cloning the repository.
```bash
cd demos/nlux-with-shadcn
```
--------------------------------
### Initialize NLUX Emulator with RequireJS
Source: https://github.com/nlkitai/nlux/blob/latest/examples/dev-examples/emulator/src/05-react-js-with-langserve/index.html
Loads the 'nluxEmulatorReactExample' module using RequireJS once the DOM is ready and executes it. This is the main entry point for the demo.
```javascript
document.addEventListener('DOMContentLoaded', () => {
requirejs(['nluxEmulatorReactExample'], function (nluxEmulatorReactExample) {
nluxEmulatorReactExample();
});
});
```
--------------------------------
### Run Demo Middleware with OpenAI
Source: https://github.com/nlkitai/nlux/blob/latest/docs/docs/learn/008-context-aware-conversations.mdx
Run the demo middleware using npx, specifying OpenAI as the API and setting the port. The OpenAI API key can be provided via an environment variable or a command-line flag.
```bash
npx @nlbridge/server --api openai --port 8899
```
```bash
npx @nlbridge/server --api openai --port 8899 --api-key YOUR_API_KEY
```
--------------------------------
### Install NLUX Dependencies with PNPM
Source: https://github.com/nlkitai/nlux/blob/latest/docs/docs/learn/002-get-started/001-vercel-ai.mdx
Install the necessary NLUX React and themes packages using PNPM.
```bash
pnpm add @nlux/react @nlux/themes
```
--------------------------------
### Install NLUX Dependencies with Yarn
Source: https://github.com/nlkitai/nlux/blob/latest/docs/docs/learn/002-get-started/001-vercel-ai.mdx
Install the necessary NLUX React and themes packages using Yarn.
```bash
yarn add @nlux/react @nlux/themes
```
--------------------------------
### Install NLUX React Packages
Source: https://github.com/nlkitai/nlux/blob/latest/docs/docs/learn/002-get-started/_002-nlux-with-langchain/react-js/001-install.mdx
Use your preferred package manager to install the necessary NLUX packages for your React application.
```bash
npm install @nlux/react @nlux/langchain-react
```
```bash
yarn add @nlux/react @nlux/langchain-react
```
```bash
pnpm add @nlux/react @nlux/langchain-react
```
--------------------------------
### NLUX LangChain LangServe Integration Example
Source: https://github.com/nlkitai/nlux/blob/latest/docs/docs/examples/0004-langchain-langserve-adapter.mdx
This example showcases the frontend integration between LangServe and NLUX. It requires 'App.tsx' and 'personas.tsx' files to function.
```typescript
import Link from '@docusaurus/Link';
import {CodeEditor} from '@site/src/components/CodeEditor/CodeEditor';
import app from './0004-langchain-langserve-adapter/app';
import personas from './0004-langchain-langserve-adapter/personas';
# LangChain LangServe Adapter
[LangChain](https://www.langchain.com/) is a new and popular framework for building services powered by
Large Language Models. It enables applications that are context-aware. It also provides a library called
[LangServe](https://python.langchain.com/docs/langserve) to create standardized APIs that can be used to
interact with LangChain runnables.
This example illustrates how to use `NLUX` to connect to a LangChain runnable made available through LangServe.
This example focuses on the frontend integration between LangServe and `NLUX`. If you are interested in seeing
the backend code that enabled this demo, you can check this [repository](https://github.com/nlkitai/pynlux),
which contains Python LangServe API code.
---
Learn More About NLUX LangChain Adapter
```
--------------------------------
### Clone NLUX Demos Repository
Source: https://github.com/nlkitai/nlux/blob/latest/docs/docs/learn/008-context-aware-conversations.mdx
Clone the NLUX demos repository to your local machine and navigate to the stock-wiz-ai directory to run the demo application.
```bash
git clone git@github.com:nlkitai/demos.git nlux-demos
cd nlux-demos/stock-wiz/stock-wiz-ai/
```
--------------------------------
### Install NLUX React Packages with PNPM
Source: https://github.com/nlkitai/nlux/blob/latest/docs/docs/learn/002-get-started/_005-nlux-hugging-face-inference/react-js/002-install.mdx
Use this command to install the core React and Hugging Face React packages for NLUX using pnpm.
```bash
pnpm add @nlux/react @nlux/hf-react
```
--------------------------------
### Initialize AI Chat with Syntax Highlighter
Source: https://github.com/nlkitai/nlux/blob/latest/docs/docs/reference/002-ui/_001-ai-chat/config/
Use this to create an AI chat instance and configure it to use a syntax highlighter for message formatting. Ensure '@nlux/highlighter' is installed.
```typescript
import {createAiChat} from '@nlux/core';
import {highlighter} from '@nlux/highlighter';
const aiChat = createAiChat().withMessageOptions({syntaxHighlighter: highlighter});
```
--------------------------------
### Navigate to App Directory with NPM
Source: https://github.com/nlkitai/nlux/blob/latest/docs/docs/learn/002-get-started/001-vercel-ai.mdx
Change the current directory to the newly created Next.js application using npm.
```bash
cd my-ai-app
```
--------------------------------
### Install NLux Hugging Face Adapter (Yarn)
Source: https://github.com/nlkitai/nlux/blob/latest/docs/docs/learn/003-adapters/002-hugging-face/_002-llama-2-chatbot/
Install the NLux Hugging Face adapter using Yarn. This package enables integration with Llama models.
```bash
yarn add @nlux/hf
```
--------------------------------
### Configuring Input Pre-processor
Source: https://github.com/nlkitai/nlux/blob/latest/docs/docs/reference/005-adapters/_003-langchain-langserve/
Demonstrates how to define and apply a custom input pre-processor function to a LangServe chat adapter.
```APIDOC
## Configure Input Pre-processor
### Description
This section details how to define a custom input pre-processor function and integrate it with a LangServe adapter using the `withInputPreProcessor` method. The pre-processor allows you to transform the user's input and conversation history into a specific format expected by your LangServe runnable, including adding additional dynamic data.
### Method
`withInputPreProcessor(inputPreProcessor)`
### Type
`LangServeInputPreProcessor`
### Usage
Define a function that accepts `input` (string) and optional `conversationHistory` (readonly ConversationItem[]) and returns an object that will be sent to the LangServe runnable. This returned object can include `user_prompt` and any other custom fields, such as `additional_data`.
```ts
const myInputPreProcessor: LangServeInputPreProcessor = (
input: string,
conversationHistory?: readonly ConversationItem[],
): any => {
return {
user_prompt: input,
// Additional data can be added here
additional_data: {
value_1: getDataDynamically(),
value_2: 'some string'
}
}
};
const adapter = createChatAdapter()
.withUrl('https://')
.withInputPreProcessor(myInputPreProcessor);
```
### Parameters
#### Request Body (Implicitly defined by `inputPreProcessor`)
- **user_prompt** (string) - Required - The user's current input.
- **additional_data** (object) - Optional - A custom object for any additional data required by the runnable.
- **value_1** (any) - Description depends on `getDataDynamically()` implementation.
- **value_2** (string) - A static string value.
### Response
(Response structure depends on the LangServe Runnable implementation.)
```
--------------------------------
### Use Chat Adapter for Llama 2
Source: https://github.com/nlkitai/nlux/blob/latest/docs/docs/learn/003-adapters/002-hugging-face/_002-llama-2-chatbot/
This example shows how to initialize the chat adapter with specific pre-processors for Llama 2. Ensure you replace placeholders like '' and '' with your actual values.
```tsx
import {
useChatAdapter,
llama2InputPreProcessor,
llama2OutputPreProcessor,
} from '@nlux/hf-react';
const Component = () => {
const adapter = useChatAdapter({
dataTransferMode: 'stream',
model: '',
systemMessage: '',
preProcessors: {
input: llama2InputPreProcessor,
output: llama2OutputPreProcessor,
},
maxNewTokens: 800,
});
return (
);
}
```
--------------------------------
### LangServe Adapter Configuration
Source: https://github.com/nlkitai/nlux/blob/latest/docs/docs/reference/005-adapters/_003-langchain-langserve/
Demonstrates how to create and configure a LangServe chat adapter using the `withConfig` method.
```APIDOC
## LangServe Adapter Configuration
### Description
This section shows how to initialize a LangServe chat adapter and apply custom configuration settings using the `withConfig` method. This is useful for setting session IDs, requester information, and other runtime parameters.
### Method
`withConfig(config: LangServeConfig)`
### Endpoint
N/A (This is a client-side configuration method)
### Parameters
#### Request Body (for `withConfig`)
- **config** (LangServeConfig) - Required - An object containing configuration options for the adapter.
- **session_id** (string) - Required - The unique identifier for the current session.
- **requester** (string) - Required - The name or identifier of the user or entity making the request.
### Request Example
```ts
const adapter = createChatAdapter()
.withUrl('https://')
.withConfig({
session_id: 'sesh1244',
requester: 'Alan Turing',
});
```
### Response
N/A (This method configures the adapter instance and does not return a direct response in the traditional API sense.)
```
--------------------------------
### Provide Stream Started Callback to AiChat
Source: https://github.com/nlkitai/nlux/blob/latest/docs/docs/reference/002-ui/_002-events/events/
Pass the defined `messageStreamStartedCallback` to the `AiChat` component via the `events` prop. This enables custom handling of the message stream start.
```tsx
// Provide the streamStarted callback as part of the events prop
```
--------------------------------
### Create and Configure NLX Langchain Adapter
Source: https://github.com/nlkitai/nlux/blob/latest/docs/docs/learn/003-adapters/001-langchain/_002-endpoints/urlConfig/
Use `createAdapter` to initialize the NLX Langchain adapter. Configure it with a specific API endpoint URL using `.withUrl()` for custom integrations.
```typescript
import {createAdapter} from '@nlux/langchain';
const adapter = createAdapter().withUrl('https://pynlux.api.nlkit.com/pirate-speak');
```
--------------------------------
### Install NLux Hugging Face Adapter (PNPM)
Source: https://github.com/nlkitai/nlux/blob/latest/docs/docs/learn/003-adapters/002-hugging-face/_002-llama-2-chatbot/
Install the NLux Hugging Face adapter using PNPM. This package is required for connecting to Hugging Face Llama models.
```bash
pnpm add @nlux/hf
```
--------------------------------
### Set up React JS Project with Vite
Source: https://github.com/nlkitai/nlux/blob/latest/docs/docs/learn/002-get-started/_002-nlux-with-langchain/
Use these npm commands to create a new React JS application with TypeScript using the Vite template. Ensure you have Node.js and npm installed.
```bash
npm create vite@latest my-ai-chat-app -- --template react-ts
cd my-ai-chat-app
npm install
npm run dev
```
--------------------------------
### Install NLUX React and NLBridge React Adapters
Source: https://github.com/nlkitai/nlux/blob/latest/docs/docs/learn/002-get-started/_003-nlux-nodejs-nlbridge-chatgpt/react-js/004-install.mdx
Use your preferred package manager to install the @nlux/react and @nlux/nlbridge-react packages. These are required to integrate NLUX and nlbridge into your React application.
```bash
npm install @nlux/react @nlux/nlbridge-react
```
```bash
yarn add @nlux/react @nlux/nlbridge-react
```
```bash
pnpm add @nlux/react @nlux/nlbridge-react
```
--------------------------------
### Create .env.local file
Source: https://github.com/nlkitai/nlux/blob/latest/docs/docs/learn/002-get-started/001-vercel-ai.mdx
Create a .env.local file in the project root to store environment variables.
```bash
touch .env.local
```
--------------------------------
### Run Specs/Unit Tests
Source: https://github.com/nlkitai/nlux/blob/latest/pipeline/README.md
Builds the project and runs unit tests. Use 'yarn run reset' if 'yarn run set' fails.
```bash
yarn run set
// or
yarn run reset
```
```bash
yarn run test
```
--------------------------------
### NLUX Theme Customization Example
Source: https://github.com/nlkitai/nlux/blob/latest/docs/docs/learn/007-customize-theme.mdx
This example demonstrates customizing the NLUX chat interface by modifying theme variables for background colors, border radius, and replacing the send icon. You can modify the 'theme-variables.css' file to see live changes.
```tsx
import {PlatformSelector} from '@site/src/components/PlatformSelector/PlatformSelector';
import {CodeEditor} from '@site/src/components/CodeEditor/CodeEditor';
import app from './_007-customize-theme/example-custom-button-color/app';
import send from './_007-customize-theme/example-custom-button-color/send';
import personas from './_007-customize-theme/example-custom-button-color/personas';
import themeVariables from './_007-customize-theme/example-custom-button-color/theme-variables';
import ThemeIdReactJs from './_007-customize-theme/#react/themeId.mdx';
import ThemeIdJavaScript from './_007-customize-theme/#js/themeId.mdx';
```
```css
/* Component background color */
--nlux-background-color: #060524;
/* Assistant message background color */
--nlux-message-assistant-background-color: #5F9EA0;
/* User message background color */
--nlux-message-user-background-color: #DC143C;
/* Border radius */
--nlux-border-radius: 5px;
/* Custom send icon (SVG) */
/* This would typically be handled in a separate component or by overriding an existing SVG */
```
```tsx
import React from 'react';
import { AiChat } from '@nlux/react';
// Assuming 'app' contains the main chat component setup
// and 'themeVariables' is imported for context, though not directly used here
// 'personas' and 'send' are also imported but their direct usage isn't shown in this snippet
const App = () => {
return (
);
};
export default App;
```
```tsx
import React from 'react';
interface SendProps {
// Define props for the send component if any
}
const Send: React.FC = () => {
// Custom SVG for send icon
return (
);
};
export default Send;
```
```tsx
const personas = [
{
id: 'default',
name: 'Default Persona',
// other persona properties
},
// other personas
];
export default personas;
```
--------------------------------
### Example Custom Batch Adapter using useAsBatchAdapter
Source: https://github.com/nlkitai/nlux/blob/latest/docs/docs/learn/003-adapters/004-custom-adapters/001-create-custom-adapter.mdx
This example demonstrates creating a custom batch adapter for a REST API using the `useAsBatchAdapter` hook. It defines a `batchText` function that sends a POST request and processes the JSON response.
```typescript
import {useAsBatchAdapter, AdapterExtras} from '@nlux/react';
export const myCustomAdapter = useAsBatchAdapter(
(message: string, extras: AdapterExtras): Promise => {
return fetch('http://localhost:8080', {
method: 'POST',
body: JSON.stringify({message})
})
.then(response => response.json())
.then(json => json.message);
}
);
```
--------------------------------
### AI Chat API and Events Integration Example
Source: https://github.com/nlkitai/nlux/blob/latest/docs/docs/examples/0005-ai-chat-api-and-events.mdx
This example demonstrates how to use the AI Chat API along with events to submit a message programmatically and use the response outside the AI Chat component. It includes App.tsx, setup.ts, and lastMessage.tsx files.
```typescript
import Link from '@docusaurus/Link';
import {CodeEditor} from '@site/src/components/CodeEditor/CodeEditor';
import app from './0005-ai-chat-api-and-events/app';
import setup from './0005-ai-chat-api-and-events/setup';
import lastMessage from './0005-ai-chat-api-and-events/lastMessage';
# API And Events
This example shows how to use the AI Chat API along with events to submit a message programmatically, and use the
response outside the AI Chat component.
---