Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

📦 NEW: Chat with text documents agent example using BaseAI #54

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions examples/agents/ask-my-text-documents-agent/.env.baseai.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# !! SERVER SIDE ONLY !!
# Keep all your API keys secret — use only on the server side.

# TODO: ADD: Both in your production and local env files.
# Langbase API key for your User or Org account.
# How to get this API key https://langbase.com/docs/api-reference/api-keys
LANGBASE_API_KEY=

# TODO: ADD: LOCAL ONLY. Add only to local env files.
# Following keys are needed for local pipe runs. For providers you are using.
# For Langbase, please add the key to your LLM keysets.
# Read more: Langbase LLM Keysets https://langbase.com/docs/features/keysets
OPENAI_API_KEY=
ANTHROPIC_API_KEY=
COHERE_API_KEY=
FIREWORKS_API_KEY=
GOOGLE_API_KEY=
GROQ_API_KEY=
MISTRAL_API_KEY=
PERPLEXITY_API_KEY=
TOGETHER_API_KEY=
58 changes: 58 additions & 0 deletions examples/agents/ask-my-text-documents-agent/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage

# next.js
/.next/
/out/

# production
/build

# misc
.DS_Store
*.pem

# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# local env files
.env
.env*.local
.copy.local.env
.copy.remote.env

# vercel
.vercel

# typescript
*.tsbuildinfo
next-env.d.ts

# Supabase
seed.sql
xseed.sql
xxseed.sql
-seed.sql
/supabase/seed.sql
/test-results/
/playwright-report/
/blob-report/
/playwright/.cache/

# No lock files.
package-lock.json
yarn.lock
dist
# baseai
**/.baseai/
# env file
.env
53 changes: 53 additions & 0 deletions examples/agents/ask-my-text-documents-agent/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
![Ask My Text Documents Agent by ⌘ Langbase][cover]

![License: MIT][mit] [![Fork on ⌘ Langbase][fork]][pipe]

## Build an Ask My Text Documents Agent with BaseAI framework — ⌘ Langbase

This AI Agent is built using the BaseAI framework. It leverages an agentic pipe that integrates over 30+ LLMs (including OpenAI, Gemini, Mistral, Llama, Gemma, etc.) and can handle any data, with context sizes of up to 10M+ tokens, supported by memory. The framework is compatible with any front-end framework (such as React, Remix, Astro, Next.js), giving you, as a developer, the freedom to tailor your AI application exactly as you envision.

## Features

- Ask My Text Documents Agent — Built with [BaseAI framework and agentic Pipe ⌘ ][qs].
- Composable Agents — build and compose agents with BaseAI.
- Add and Sync deployed pipe on Langbase locally npx baseai@latest add ([see the Code button][pipe]).

## Learn more

1. Check the [Learning path to build an agentic AI pipe with ⌘ BaseAI][learn]
2. Read the [source code on GitHub][gh] for this agent example
3. Go through Documentaion: [Pipe Quick Start][qs]
4. Learn more about [Memory features in ⌘ BaseAI][memory]
5. Learn more about [Tool calls support in ⌘ BaseAI][toolcalls]


> NOTE:
> This is a BaseAI project, you can deploy BaseAI pipes, memory and tool calls on Langbase.

---

## Authors

This project is created by [Langbase][lb] team members, with contributions from:

- Muhammad-Ali Danish - Software Engineer, [Langbase][lb] <br>
**_Built by ⌘ [Langbase.com][lb] — Ship hyper-personalized AI assistants with memory!_**


[lb]: https://langbase.com
[pipe]: https://langbase.com/examples/ask-my-text-documents-agent
[gh]: https://github.com/LangbaseInc/baseai/tree/main/examples/agents/ask-my-text-documents-agent
[cover]:https://raw.githubusercontent.com/LangbaseInc/docs-images/main/baseai/baseai-cover.png
[download]:https://download-directory.github.io/?url=https://github.com/LangbaseInc/baseai/tree/main/examples/agents/ask-my-text-documents-agent
[learn]:https://baseai.dev/learn
[memory]:https://baseai.dev/docs/memory/quickstart
[toolcalls]:https://baseai.dev/docs/tools/quickstart
[deploy]:https://baseai.dev/docs/deployment/authentication
[signup]: https://langbase.fyi/io
[qs]:https://baseai.dev/docs/pipe/quickstart
[docs]:https://baseai.dev/docs
[xaa]:https://x.com/MrAhmadAwais
[xab]:https://x.com/AhmadBilalDev
[local]:http://localhost:9000
[mit]: https://img.shields.io/badge/license-MIT-blue.svg?style=for-the-badge&color=%23000000
[fork]: https://img.shields.io/badge/FORK%20ON-%E2%8C%98%20Langbase-000000.svg?style=for-the-badge&logo=%E2%8C%98%20Langbase&logoColor=000000
23 changes: 23 additions & 0 deletions examples/agents/ask-my-text-documents-agent/app/api/chat/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
'use server'

import {NextRequest} from 'next/server';
import { Pipe } from '@baseai/core';
import { RunOptionsStream } from '@baseai/core';
import pipeAskMyTextDocumentsAgent from '@/baseai/pipes/ask-my-text-documents-agent';

export async function POST(req: NextRequest) {
const runOptions = await req.json() as RunOptionsStream;;

// 1. Initiate the Pipe.
const pipe = new Pipe(pipeAskMyTextDocumentsAgent());

// 2. Run the Pipe.
const {stream, threadId} = await pipe.run(runOptions);
// 3. Return the ReadableStream directly.
return new Response(stream, {
status: 200,
headers: {
'lb-thread-id': threadId ?? '',
},
});
}
Binary file not shown.
99 changes: 99 additions & 0 deletions examples/agents/ask-my-text-documents-agent/app/globals.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
@tailwind base;
@tailwind components;
@tailwind utilities;

/* Zinc */
/* --background: 240 10% 3.9%; */
/* --muted: 240 3.7% 15.9%; */
@layer base {
:root {
--background: 0 0% 100%;
--foreground: 240 10% 3.9%;
--card: 0 0% 100%;
--card-foreground: 240 10% 3.9%;
--popover: 0 0% 100%;
--popover-foreground: 240 10% 3.9%;
--primary: 240 5.9% 10%;
--primary-foreground: 0 0% 98%;
--secondary: 240 4.8% 95.9%;
--secondary-foreground: 240 5.9% 10%;
--muted: 240 4.8% 95.9%;
--muted-foreground: 240 3.8% 46.1%;
--accent: 240 4.8% 95.9%;
--accent-foreground: 240 5.9% 10%;
/* --destructive: 0 84.2% 60.2%; */
--destructive: 2.74 92.59% 62.94%;
--destructive-foreground: 0 0% 98%;
--warning: 46.38 70.61% 48.04%;
--warning-foreground: 120 12.5% 3.14%;
--border: 240 5.9% 90%;
--input: 240 5.9% 90%;
--ring: 240 5.9% 10%;
--radius: 6px;
--danger: 2.74 92.59% 62.94%;
}

.dark {
/* --background: 120 12.5% 3.14%; */
--background: 240, 3%, 9%;
--foreground: 0 0% 98%;
--card: 240 10% 3.9%;
--card-foreground: 0 0% 98%;
--popover: 240 10% 3.9%;
--popover-foreground: 0 0% 98%;
--primary: 0 0% 98%;
--primary-foreground: 240 5.9% 10%;
--secondary: 240 3.7% 15.9%;
--secondary-foreground: 0 0% 98%;
/* --muted: 165 10% 7.84%; */
--muted: 240 3.45% 11.37%;
--muted-foreground: 240 5% 64.9%;
--accent: 240 3.7% 15.9%;
--accent-foreground: 0 0% 98%;
/* --destructive: 0 62.8% 30.6%; */
--destructive: 356.18 70.61% 48.04%;
--destructive-foreground: 0 0% 98%;
--warning: 46.38 70.61% 48.04%;
--warning-foreground: 120 12.5% 3.14%;
/* --border: 240 3.7% 15.9%; */
--border: 240 2% 14%;
--border-muted: 240 2% 14%;
--input: 240 3.7% 15.9%;
--ring: 240 4.9% 83.9%;
--danger: 356.18 70.61% 48.04%;
}
}

@layer base {
* {
@apply border-border;
}
body {
@apply bg-background text-foreground;
}
}

::selection {
color: hsl(var(--background));
background: hsl(var(--foreground));
}

.google {
display: inline-block;
width: 20px;
height: 20px;
position: relative;
background-size: contain;
background-repeat: no-repeat;
background-position: 50%;
background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' viewBox='0 0 48 48'%3E%3Cdefs%3E%3Cpath id='a' d='M44.5 20H24v8.5h11.8C34.7 33.9 30.1 37 24 37c-7.2 0-13-5.8-13-13s5.8-13 13-13c3.1 0 5.9 1.1 8.1 2.9l6.4-6.4C34.6 4.1 29.6 2 24 2 11.8 2 2 11.8 2 24s9.8 22 22 22c11 0 21-8 21-22 0-1.3-.2-2.7-.5-4z'/%3E%3C/defs%3E%3CclipPath id='b'%3E%3Cuse xlink:href='%23a' overflow='visible'/%3E%3C/clipPath%3E%3Cpath clip-path='url(%23b)' fill='%23FBBC05' d='M0 37V11l17 13z'/%3E%3Cpath clip-path='url(%23b)' fill='%23EA4335' d='M0 11l17 13 7-6.1L48 14V0H0z'/%3E%3Cpath clip-path='url(%23b)' fill='%2334A853' d='M0 37l30-23 7.9 1L48 0v48H0z'/%3E%3Cpath clip-path='url(%23b)' fill='%234285F4' d='M48 48L17 24l-4-3 35-10z'/%3E%3C/svg%3E");
}

@keyframes spin {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
}
36 changes: 36 additions & 0 deletions examples/agents/ask-my-text-documents-agent/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { Header } from '@/components/header'
import cn from 'mxcn'
import type { Metadata } from 'next'
import { Inter } from 'next/font/google'
import { Toaster } from 'sonner'
import './globals.css'

const inter = Inter({ subsets: ['latin'] })

export const metadata: Metadata = {
title: 'Ask My Docs RAG',
description: 'Ask any query about my docs. Built using Langbase.',
keywords: ['AI', 'Chatbot', 'RAG', 'Docs', 'Langbase']
}

export default function RootLayout({
children
}: Readonly<{
children: React.ReactNode
}>) {
return (
<html lang="en">
<body className={cn(inter.className, 'bg-background light')}>
<div className="flex min-h-screen flex-col px-3 pr-0 pt-6">
<div className="rounded-l-[calc(var(--radius)+2px)] border border-r-0 pb-1 pl-1">
<Toaster />
<Header />
<main className="bg-muted rounded-l-[calc(var(--radius)+2px)]">
{children}
</main>
</div>
</div>
</body>
</html>
)
}
58 changes: 58 additions & 0 deletions examples/agents/ask-my-text-documents-agent/app/not-found.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
export const runtime = "edge";

export default function NotFound() {
return (
<>
<title>404: This page could not be found.</title>
<div style={styles.error}>
<div>
<style
dangerouslySetInnerHTML={{
__html: `body{color:#000;background:#fff;margin:0}.next-error-h1{border-right:1px solid rgba(0,0,0,.3)}@media (prefers-color-scheme:dark){body{color:#fff;background:#000}.next-error-h1{border-right:1px solid rgba(255,255,255,.3)}}`,
}}
/>
<h1 className="next-error-h1" style={styles.h1}>
404
</h1>
<div style={styles.desc}>
<h2 style={styles.h2}>This page could not be found.</h2>
</div>
</div>
</div>
</>
);
}

const styles = {
error: {
fontFamily:
'system-ui,"Segoe UI",Roboto,Helvetica,Arial,sans-serif,"Apple Color Emoji","Segoe UI Emoji"',
height: "100vh",
textAlign: "center",
display: "flex",
flexDirection: "column",
alignItems: "center",
justifyContent: "center",
},

desc: {
display: "inline-block",
},

h1: {
display: "inline-block",
margin: "0 20px 0 0",
padding: "0 23px 0 0",
fontSize: 24,
fontWeight: 500,
verticalAlign: "top",
lineHeight: "49px",
},

h2: {
fontSize: 14,
fontWeight: 400,
lineHeight: "49px",
margin: 0,
},
} as const;
7 changes: 7 additions & 0 deletions examples/agents/ask-my-text-documents-agent/app/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { Chatbot } from '@/components/chatbot-page'

export const runtime = 'edge'

export default function ChatPage() {
return <Chatbot />
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import type { BaseAIConfig } from 'baseai';

export const config: BaseAIConfig = {
log: {
isEnabled: true,
logSensitiveData: false,
pipe: true,
'pipe.completion': true,
'pipe.request': true,
'pipe.response': true,
tool: true,
memory: true
},
memory: {
useLocalEmbeddings: false
},
envFilePath: '.env'
};
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { MemoryI } from '@baseai/core';
import path from 'path';

const memoryAskMyTextDocuments = (): MemoryI => ({
name: 'ask-my-text-documents',
description: 'text documents as pdf',
config: {
useGitRepo: false,
dirToTrack: path.posix.join('.'),
extToTrack: ["*"]
}
});

export default memoryAskMyTextDocuments;
Loading