added api route
This commit is contained in:
@@ -1,54 +1,11 @@
|
|||||||
FROM python:3.11-slim-bookworm
|
FROM pipecatai/cloud-base:latest
|
||||||
|
|
||||||
ARG DEBIAN_FRONTEND=noninteractive
|
|
||||||
ARG USE_PERSISTENT_DATA
|
|
||||||
ENV PYTHONUNBUFFERED=1
|
|
||||||
ENV NODE_MAJOR=20
|
|
||||||
|
|
||||||
# Expose FastAPI port
|
|
||||||
ENV FAST_API_PORT=7860
|
|
||||||
EXPOSE 7860
|
|
||||||
|
|
||||||
# Install system dependencies
|
|
||||||
RUN apt-get update && apt-get install --no-install-recommends -y \
|
|
||||||
build-essential \
|
|
||||||
git \
|
|
||||||
ffmpeg \
|
|
||||||
google-perftools \
|
|
||||||
ca-certificates curl gnupg \
|
|
||||||
&& apt-get clean && rm -rf /var/lib/apt/lists/*
|
|
||||||
|
|
||||||
# Install Node.js
|
|
||||||
RUN mkdir -p /etc/apt/keyrings
|
|
||||||
RUN curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg
|
|
||||||
RUN echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_${NODE_MAJOR}.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list > /dev/null
|
|
||||||
RUN apt-get update && apt-get install nodejs -y
|
|
||||||
|
|
||||||
# Set up a new user named "user" with user ID 1000
|
|
||||||
RUN useradd -m -u 1000 user
|
|
||||||
|
|
||||||
# Set home to the user's home directory
|
|
||||||
ENV HOME=/home/user \
|
|
||||||
PATH=/home/user/.local/bin:$PATH \
|
|
||||||
PYTHONPATH=$HOME/app \
|
|
||||||
PYTHONUNBUFFERED=1
|
|
||||||
|
|
||||||
# Switch to the "user" user
|
|
||||||
USER user
|
|
||||||
|
|
||||||
# Set the working directory to the user's home directory
|
|
||||||
WORKDIR $HOME/app
|
|
||||||
|
|
||||||
# Install Python dependencies
|
|
||||||
COPY ./requirements.txt requirements.txt
|
COPY ./requirements.txt requirements.txt
|
||||||
RUN pip3 install --no-cache-dir --upgrade -r requirements.txt
|
|
||||||
|
|
||||||
# Copy everything else
|
RUN pip install --no-cache-dir --upgrade -r requirements.txt
|
||||||
COPY --chown=user ./src/ src/
|
|
||||||
|
|
||||||
# Copy frontend app and build
|
COPY ./src/bot.py bot.py
|
||||||
COPY --chown=user ./frontend/ frontend/
|
COPY ./src/processors.py processors.py
|
||||||
RUN cd frontend && npm install && npm run build
|
COPY ./src/prompts.py prompts.py
|
||||||
|
COPY ./src/assets assets
|
||||||
# Start the FastAPI server
|
COPY ./src/utils utils
|
||||||
CMD python3 src/bot_runner.py --port ${FAST_API_PORT}
|
|
||||||
27
examples/storytelling-chatbot/frontend/app/api/route.ts
Normal file
27
examples/storytelling-chatbot/frontend/app/api/route.ts
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
// [POST] /api
|
||||||
|
|
||||||
|
export async function POST(request: Request) {
|
||||||
|
const params = await request.json();
|
||||||
|
console.log("in POST, params is ", params)
|
||||||
|
const url = process.env.BOT_START_URL || "http://localhost:7860"
|
||||||
|
const req = await fetch(url, {
|
||||||
|
method: "POST",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
Authorization: `Bearer ${process.env.PCC_API_KEY}`,
|
||||||
|
},
|
||||||
|
body: JSON.stringify(params),
|
||||||
|
});
|
||||||
|
|
||||||
|
const res = await req.json();
|
||||||
|
|
||||||
|
if (req.status !== 200) {
|
||||||
|
return Response.json(res, { status: req.status });
|
||||||
|
}
|
||||||
|
console.log({res});
|
||||||
|
return Response.json(res);
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function GET(request: Request) {
|
||||||
|
return Response.json({message: "Hello World"});
|
||||||
|
}
|
||||||
@@ -27,22 +27,26 @@ export default function Call() {
|
|||||||
|
|
||||||
// Create a new room for the story session
|
// Create a new room for the story session
|
||||||
try {
|
try {
|
||||||
const response = await fetch("/", {
|
console.log("POSTing to /api")
|
||||||
|
const response = await fetch("/api", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
},
|
},
|
||||||
|
body: JSON.stringify({
|
||||||
|
"createDailyRoom": true
|
||||||
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
const { room_url, token } = await response.json();
|
const {dailyRoom, dailyToken} = await response.json();
|
||||||
|
console.log({dailyRoom, dailyToken})
|
||||||
// Keep a reference to the room url for later
|
// Keep a reference to the room url for later
|
||||||
setRoom(room_url);
|
setRoom(dailyRoom);
|
||||||
|
|
||||||
// Join the WebRTC session
|
// Join the WebRTC session
|
||||||
await daily.join({
|
await daily.join({
|
||||||
url: room_url,
|
url: dailyRoom,
|
||||||
token,
|
token: dailyToken,
|
||||||
videoSource: false,
|
videoSource: false,
|
||||||
startAudioOff: true,
|
startAudioOff: true,
|
||||||
});
|
});
|
||||||
|
|||||||
3
examples/storytelling-chatbot/frontend/example.env.local
Normal file
3
examples/storytelling-chatbot/frontend/example.env.local
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
SITE_URL=
|
||||||
|
PCC_API_KEY=
|
||||||
|
BOT_START_URL=
|
||||||
2090
examples/storytelling-chatbot/frontend/package-lock.json
generated
2090
examples/storytelling-chatbot/frontend/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -33,6 +33,7 @@
|
|||||||
"eslint-config-next": "14.1.4",
|
"eslint-config-next": "14.1.4",
|
||||||
"postcss": "^8.4.47",
|
"postcss": "^8.4.47",
|
||||||
"tailwindcss": "^3.4.13",
|
"tailwindcss": "^3.4.13",
|
||||||
"typescript": "^5.6.2"
|
"typescript": "^5.6.2",
|
||||||
|
"vercel": "^41.0.1"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -150,6 +150,10 @@ async def main(room_url, token=None):
|
|||||||
await runner.run(main_task)
|
await runner.run(main_task)
|
||||||
|
|
||||||
|
|
||||||
|
async def bot(data, daily_room, daily_token):
|
||||||
|
await main(daily_room, daily_token)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
parser = argparse.ArgumentParser(description="Daily Storyteller Bot")
|
parser = argparse.ArgumentParser(description="Daily Storyteller Bot")
|
||||||
parser.add_argument("-u", type=str, help="Room URL")
|
parser.add_argument("-u", type=str, help="Room URL")
|
||||||
|
|||||||
@@ -127,8 +127,8 @@ async def start_bot(request: Request) -> JSONResponse:
|
|||||||
|
|
||||||
return JSONResponse(
|
return JSONResponse(
|
||||||
{
|
{
|
||||||
"room_url": room.url,
|
"dailyRoom": room.url,
|
||||||
"token": user_token,
|
"dailyToken": user_token,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user