Skip to content

Commit

Permalink
feat: chat works
Browse files Browse the repository at this point in the history
  • Loading branch information
cs50victor committed Feb 25, 2024
1 parent 3896e50 commit 510062b
Show file tree
Hide file tree
Showing 12 changed files with 25 additions and 186 deletions.
3 changes: 1 addition & 2 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
*
!llm.py
!kitt.py
!server/**.py
4 changes: 2 additions & 2 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
LIVEKIT_API_KEY=""
LIVEKIT_API_SECRET=""
LIVEKIT_WS_URL=""
LIVEKIT_URL=""
NEXT_PUBLIC_LK_TOKEN_ENDPOINT=""

OPENAI_API_KEY=""
OPENAI_ORG_ID=""

ELEVENLABS_API_KEY=""
ELEVEN_API_KEY=""
DEEPGRAM_API_KEY=""
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,9 @@ yarn-error.log*

# typescript
*.tsbuildinfo

# python
.cenv
.venv
venv/
__pycache__
6 changes: 3 additions & 3 deletions app/api/get-participant-token/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { TokenResult } from '~/utils/types';

const apiKey = process.env.LIVEKIT_API_KEY;
const apiSecret = process.env.LIVEKIT_API_SECRET;
const livekitWsUrl = process.env.LIVEKIT_WS_URL;
const livekitWsUrl = process.env.LIVEKIT_URL;

const createToken = (userInfo: AccessTokenOptions, grant: VideoGrant) => {
const at = new AccessToken(apiKey, apiSecret, userInfo);
Expand All @@ -19,12 +19,12 @@ const createToken = (userInfo: AccessTokenOptions, grant: VideoGrant) => {
return at.toJwt();
};

const roomPattern = /\w{4}\-\w{4}\-\w{4}/;
const roomPattern = /\w{4}\-\w{4}/;

export async function GET(req: NextRequest) {
const room = req.nextUrl.searchParams.get('roomName');
const identity = req.nextUrl.searchParams.get('identity');
const name = req.nextUrl.searchParams.get('name');
const name = req.nextUrl.searchParams.get('name') ?? 'human';
const metadata = req.nextUrl.searchParams.get('metadata');

if (!room) {
Expand Down
11 changes: 5 additions & 6 deletions app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export default function Page() {
setMetadata(md);
}, [liveKitUrl, roomName, tokenOptions]);

const token = useToken('/api/token', roomName, tokenOptions);
const token = useToken('/api/get-participant-token', roomName, tokenOptions);
const appConfig = useAppConfig();
const outputs = [
appConfig?.outputs.audio && PlaygroundOutputs.Audio,
Expand All @@ -58,6 +58,8 @@ export default function Page() {
].filter((item) => typeof item !== 'boolean') as PlaygroundOutputs[];

const handleConnect = useCallback((connect: boolean, opts?: { url: string; token: string }) => {
console.log('connect', connect);
console.log('connect opts', opts);
if (connect && opts) {
setLiveKitUrl(opts.url);
}
Expand Down Expand Up @@ -97,10 +99,7 @@ export default function Page() {
}}
>
<Playground
title={appConfig?.title}
githubLink={appConfig?.github_link}
outputs={outputs}
showQR={appConfig?.show_qr}
themeColors={themeColors}
defaultColor={appConfig?.theme_color ?? 'cyan'}
onConnect={handleConnect}
Expand All @@ -114,6 +113,6 @@ export default function Page() {
);
}

function createRoomName() {
const createRoomName = () => {
return [generateRandomAlphanumeric(4), generateRandomAlphanumeric(4)].join('-');
}
};
118 changes: 0 additions & 118 deletions components/ActiveRoom.tsx

This file was deleted.

5 changes: 0 additions & 5 deletions components/Playground.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,7 @@ export interface PlaygroundProps {
const headerHeight = 56;

export default function Playground({
logo,
title,
githubLink,
outputs,
showQR,
themeColors,
defaultColor,
onConnect,
Expand Down Expand Up @@ -327,7 +323,6 @@ export default function Playground({
roomState,
themeColor,
themeColors,
showQR,
]);

let mobileTabs: PlaygroundTab[] = [];
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ livekit-api
livekit-agents>=0.4.0
livekit-plugins-deepgram>=0.2.0
livekit-plugins-elevenlabs>=0.2.0
openai
openai
7 changes: 5 additions & 2 deletions kitt.py → server/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.


import asyncio
from datetime import datetime
Expand All @@ -21,7 +22,7 @@

from livekit import rtc, agents
from livekit.agents.tts import SynthesisEvent, SynthesisEventType
from chatgpt import (
from llm import (
ChatGPTMessage,
ChatGPTMessageRole,
ChatGPTPlugin,
Expand All @@ -40,6 +41,8 @@
Feel free to ask me anything — I'm here to help! Just start talking."




# convert intro response to a stream
async def intro_text_stream(sip: bool):
if sip:
Expand Down Expand Up @@ -215,4 +218,4 @@ async def job_request_cb(job_request: agents.JobRequest):
)

worker = agents.Worker(request_handler=job_request_cb)
agents.run_app(worker)
agents.run_app(worker)
File renamed without changes.
45 changes: 0 additions & 45 deletions utils/lksdk.ts

This file was deleted.

4 changes: 2 additions & 2 deletions utils/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ export function getRoomClient(): RoomServiceClient {
}

export function getLiveKitURL(region?: string | string[]): string {
let targetKey = 'LIVEKIT_WS_URL';
let targetKey = 'LIVEKIT_URL';
if (region && !Array.isArray(region)) {
targetKey = `LIVEKIT_WS_URL_${region}`.toUpperCase();
targetKey = `LIVEKIT_URL_${region}`.toUpperCase();
}
const url = process.env[targetKey];
if (!url) {
Expand Down

0 comments on commit 510062b

Please sign in to comment.