diff --git a/examples/career-prep-coach/.env.example b/examples/career-prep-coach/.env.example index 85d27328..f47f330a 100644 --- a/examples/career-prep-coach/.env.example +++ b/examples/career-prep-coach/.env.example @@ -1 +1,2 @@ -NEXT_LB_PIPE_API_KEY="" \ No newline at end of file +LANGBASE_PIPE_API_KEY="" + diff --git a/examples/career-prep-coach/README.md b/examples/career-prep-coach/README.md index d8bb31a4..c3035894 100755 --- a/examples/career-prep-coach/README.md +++ b/examples/career-prep-coach/README.md @@ -36,7 +36,7 @@ To get started with Langbase, you'll need to [create a free personal account on 6. Add the following environment variables (.env.local): ``` # Replace `PIPE_API_KEY` with the copied API key. - NEXT_LB_PIPE_API_KEY="PIPE_API_KEY" + LANGBASE_PIPE_API_KEY="PIPE_API_KEY" ``` 7. Issue the following in your CLI: @@ -65,7 +65,7 @@ This project is created by [Langbase][lb] team members, with contributions from: [demo]: https://career-prep-coach.langbase.dev [lb]: https://langbase.com -[pipe]: https://beta.langbase.com/examples/career-prep-coach +[pipe]: https://langbase.com/examples/career-prep-coach [gh]: https://github.com/LangbaseInc/langbase-examples/tree/main/examples/career-prep-coach [cover]:https://raw.githubusercontent.com/LangbaseInc/docs-images/main/examples/career-prep-coach/career-prep-coach.png [download]:https://download-directory.github.io/?url=https://github.com/LangbaseInc/langbase-examples/tree/main/examples/career-prep-coach diff --git a/examples/career-prep-coach/app/api/chat/route.ts b/examples/career-prep-coach/app/api/chat/route.ts index 70710650..4874861a 100755 --- a/examples/career-prep-coach/app/api/chat/route.ts +++ b/examples/career-prep-coach/app/api/chat/route.ts @@ -26,9 +26,9 @@ export async function POST(req: Request) { } - if (!process.env.NEXT_LB_PIPE_API_KEY) { + if (!process.env.LANGBASE_PIPE_API_KEY) { throw new Error( - 'Please set NEXT_LB_PIPE_API_KEY in your environment variables.' + 'Please set LANGBASE_PIPE_API_KEY in your environment variables.' ) } @@ -39,14 +39,14 @@ export async function POST(req: Request) { } else if (action === 'getMemorySets') { return handleGetMemorySets(userApiKey) } else if (action === 'updatePipe') { - const { memoryName } = await req.json() + const { memoryName } = body; return updatePipe(ownerLogin, memoryName, userApiKey) } else { const endpointUrl = 'https://api.langbase.com/beta/chat' const headers = { 'Content-Type': 'application/json', - Authorization: `Bearer ${process.env.NEXT_LB_PIPE_API_KEY}` + Authorization: `Bearer ${process.env.LANGBASE_PIPE_API_KEY}` } // Get chat prompt messages and threadId from the client. @@ -153,11 +153,18 @@ async function handleFileUpload(req: Request, userApiKey: string, ownerLogin: st } async function updatePipe(ownerLogin: string | undefined, memoryName: string, userApiKey: string) { - const url = `https://api.langbase.com/beta/pipes/${ownerLogin}/shoes-expert`; + + if (!ownerLogin || !memoryName || !userApiKey) { + return new Response(JSON.stringify({ error: 'Missing required parameters' }), { + status: 400, + headers: { 'Content-Type': 'application/json' } + }); + } + const url = `https://api.langbase.com/beta/pipes/${ownerLogin}/career-prep-coach`; const pipe = { - name: "shoes-expert", - description: "An AI-powered shoe expert that recommends Nike and Adidas footwear based on customer preferences and provides personalized shopping assistance.", + name: "career-prep-coach", + description: "Your AI-powered personal interview coach, expertly preparing you for success using proven techniques and tailored feedback.", status: "private", config: { memorysets: [memoryName] diff --git a/examples/career-prep-coach/components/chatbot-page.tsx b/examples/career-prep-coach/components/chatbot-page.tsx index bb7214f7..019ec0b0 100755 --- a/examples/career-prep-coach/components/chatbot-page.tsx +++ b/examples/career-prep-coach/components/chatbot-page.tsx @@ -7,6 +7,7 @@ import { useState, useCallback } from 'react' import { toast } from 'sonner' import { ChatInput } from './chat-input' import { Opening } from './opening' +import { Suggestions } from './suggestions' export interface ChatProps extends React.ComponentProps<'div'> { id?: string // Optional: Thread ID if you want to persist the chat in a DB @@ -38,10 +39,24 @@ export function Chatbot({ id, initialMessages, className }: ChatProps) { }) const fetchMemorySets = useCallback(async () => { + + if (!userApiKey || !ownerLogin) { + toast.error('Please set both API Key and Owner Login first'); + return; + } try { const response = await fetch('/api/chat?action=getMemorySets', { method: 'POST', - body: JSON.stringify({ userApiKey, ownerLogin }) + body: JSON.stringify({ userApiKey, ownerLogin, + pipe: { + name: "career-prep-coach", + description: "Your AI-powered personal interview coach", + status: "private", + config: { + memorysets: [] // This will be populated when memory is selected + }, + } + }) }) if (!response.ok) throw new Error('Failed to fetch memory sets') const data = await response.json() @@ -59,6 +74,11 @@ export function Chatbot({ id, initialMessages, className }: ChatProps) { const handleMemorySelect = useCallback((memoryUrl: string) => { setSelectedMemory(memoryUrl) }, []) + + const sendSuggestedPrompt = (prompt: string) => { + setInput(prompt) + } + return (
Learn more by checking out:
+ {suggestion.title} +
+