-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 943f380
Showing
52 changed files
with
6,831 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
name: Deploy to GitHub Pages | ||
|
||
on: | ||
push: | ||
branches: | ||
- gh-deploy | ||
|
||
jobs: | ||
build_site: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
|
||
- name: Install Node.js | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: 18 | ||
cache: npm | ||
|
||
- name: Install dependencies | ||
run: npm install | ||
|
||
- name: build | ||
env: | ||
BASE_PATH: '/${{ github.event.repository.name }}' | ||
run: | | ||
npm run build | ||
- name: Upload Artifacts | ||
uses: actions/upload-pages-artifact@v2 | ||
with: | ||
# this should match the `pages` option in your adapter-static options | ||
path: 'build/' | ||
|
||
deploy: | ||
needs: build_site | ||
runs-on: ubuntu-latest | ||
|
||
permissions: | ||
pages: write | ||
id-token: write | ||
|
||
environment: | ||
name: github-pages | ||
url: ${{ steps.deployment.outputs.page_url }} | ||
|
||
steps: | ||
- name: Deploy | ||
id: deployment | ||
uses: actions/deploy-pages@v2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
.DS_Store | ||
node_modules | ||
/build | ||
/.svelte-kit | ||
/package | ||
.env | ||
.env.* | ||
!.env.example | ||
vite.config.js.timestamp-* | ||
vite.config.ts.timestamp-* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
engine-strict=true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# Ignore files for PNPM, NPM and YARN | ||
pnpm-lock.yaml | ||
package-lock.json | ||
yarn.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"useTabs": true, | ||
"singleQuote": true, | ||
"trailingComma": "none", | ||
"printWidth": 100, | ||
"plugins": ["prettier-plugin-svelte"], | ||
"overrides": [{ "files": "*.svelte", "options": { "parser": "svelte" } }] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License Copyright (c) 2024 flo-bit | ||
|
||
Permission is hereby granted, free of | ||
charge, to any person obtaining a copy of this software and associated | ||
documentation files (the "Software"), to deal in the Software without | ||
restriction, including without limitation the rights to use, copy, modify, merge, | ||
publish, distribute, sublicense, and/or sell copies of the Software, and to | ||
permit persons to whom the Software is furnished to do so, subject to the | ||
following conditions: | ||
|
||
The above copyright notice and this permission notice | ||
(including the next paragraph) shall be included in all copies or substantial | ||
portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF | ||
ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO | ||
EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR | ||
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
# sveltekit openai realtime api | ||
|
||
this is a sveltekit port of the [openai-realtime-console](https://github.com/openai/openai-realtime-console) repository. | ||
|
||
it allows you to easily use the openai realtime api in your sveltekit project. | ||
|
||
work in progress, but it should be functional. | ||
|
||
## how to use | ||
|
||
> [!WARNING] | ||
> this is the setup for the client side only version of the realtime api, you will need to use a relay server to use this in production. | ||
> see further down for more information on how to use a relay server. | ||
1. copy the `src/lib/realtime/` folder from this repository into your sveltekit projects `src/lib/` folder | ||
|
||
2. install the dependency: | ||
|
||
```bash | ||
$ npm i openai/openai-realtime-api-beta | ||
``` | ||
|
||
2. import the `Realtime` component into your svelte file and use it e.g. like so: | ||
|
||
```svelte | ||
<script lang="ts"> | ||
import Realtime from '$lib/realtime/realtime.svelte'; | ||
import type { ItemType } from '@openai/realtime-api-beta/dist/lib/client'; | ||
let startConversation: () => Promise<void>; | ||
let endConversation: () => Promise<void>; | ||
let turnDetection: 'server_vad' | 'none' = 'server_vad'; | ||
let items: ItemType[] = []; | ||
let isConnected = false; | ||
let isRecording = false; | ||
let startRecording: () => Promise<void>; | ||
let stopRecording: () => Promise<void>; | ||
// set your api key here | ||
let apiKey = ''; | ||
</script> | ||
{#if apiKey} | ||
<Realtime | ||
bind:startConversation | ||
bind:endConversation | ||
bind:isConnected | ||
bind:isRecording | ||
bind:startRecording | ||
bind:stopRecording | ||
bind:items | ||
{turnDetection} | ||
{apiKey} | ||
/> | ||
{/if} | ||
``` | ||
|
||
see `src/routes/+page.svelte` for a full example. | ||
|
||
## relay server | ||
|
||
for production use, you will need to use a relay server to use the realtime api. | ||
|
||
1. add `OPENAI_API_KEY` to your `.env` file | ||
|
||
2. tell the Realtime component to use the relay server: | ||
|
||
```svelte | ||
<Realtime useRelayServer /> | ||
``` | ||
|
||
then you have two options: | ||
|
||
### run the relay server with your sveltekit server | ||
|
||
change your `vite.config.ts` to this: | ||
|
||
```ts | ||
import { realtimeWebSocketServer } from './src/lib/realtime/realtime_server'; | ||
import { sveltekit } from '@sveltejs/kit/vite'; | ||
import { defineConfig } from 'vite'; | ||
|
||
export default defineConfig({ | ||
plugins: [sveltekit(), realtimeWebSocketServer] | ||
}); | ||
``` | ||
|
||
### run the relay server independently | ||
|
||
- copy the `relay-server/` folder (identical to the code in the | ||
[openai-realtime-console](https://github.com/openai/openai-realtime-console) repository) | ||
from this repository into your project | ||
|
||
- install the dependencies: | ||
|
||
```bash | ||
npm i dotenv openai/openai-realtime-api-beta | ||
``` | ||
|
||
- run the relay server: | ||
|
||
```bash | ||
$ node relay-server/index.js | ||
``` | ||
|
||
- add the relay server url to your Realtime component: | ||
|
||
``` | ||
<Realtime useRelayServer relayServer="http://localhost:8081" /> | ||
``` | ||
|
||
## todos | ||
|
||
- [ ] add tests | ||
- [ ] add more documentation | ||
- [ ] show waveforms | ||
- [ ] tool calling | ||
- [ ] update ui | ||
|
||
## license | ||
|
||
MIT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import js from '@eslint/js'; | ||
import ts from 'typescript-eslint'; | ||
import svelte from 'eslint-plugin-svelte'; | ||
import prettier from 'eslint-config-prettier'; | ||
import globals from 'globals'; | ||
|
||
/** @type {import('eslint').Linter.FlatConfig[]} */ | ||
export default [ | ||
js.configs.recommended, | ||
...ts.configs.recommended, | ||
...svelte.configs['flat/recommended'], | ||
prettier, | ||
...svelte.configs['flat/prettier'], | ||
{ | ||
languageOptions: { | ||
globals: { | ||
...globals.browser, | ||
...globals.node | ||
} | ||
} | ||
}, | ||
{ | ||
files: ['**/*.svelte'], | ||
languageOptions: { | ||
parserOptions: { | ||
parser: ts.parser | ||
} | ||
} | ||
}, | ||
{ | ||
ignores: ['build/', '.svelte-kit/', 'dist/'] | ||
} | ||
]; |
Oops, something went wrong.