-
-
Notifications
You must be signed in to change notification settings - Fork 65
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
Showing
5 changed files
with
71 additions
and
83 deletions.
There are no files selected for viewing
14 changes: 7 additions & 7 deletions
14
docs/docs/examples/0011-theme-customization/example-custom-button-color/app.tsx
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
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
44 changes: 0 additions & 44 deletions
44
docs/docs/learn/_005-customize-theme/example-custom-button-color/adapter.tsx
This file was deleted.
Oops, something went wrong.
17 changes: 8 additions & 9 deletions
17
docs/docs/learn/_005-customize-theme/example-custom-button-color/app.tsx
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
47 changes: 47 additions & 0 deletions
47
docs/docs/learn/_005-customize-theme/example-custom-button-color/send.tsx
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,47 @@ | ||
export default `import { StreamSend, StreamingAdapterObserver } from '@nlux/react'; | ||
// A demo API by NLUX that connects to OpenAI | ||
// and returns a stream of Server-Sent events | ||
const demoProxyServerUrl = 'https://demo.api.nlux.ai/openai/chat/stream'; | ||
// Function to send query to the server and receive a stream of chunks as response | ||
export const send: StreamSend = async ( | ||
prompt: string, | ||
observer: StreamingAdapterObserver, | ||
) => { | ||
const body = {prompt}; | ||
const response = await fetch(demoProxyServerUrl, { | ||
method: 'POST', | ||
headers: {'Content-Type': 'application/json'}, | ||
body: JSON.stringify(body), | ||
}); | ||
if (response.status !== 200) { | ||
observer.error(new Error('Failed to connect to the server')); | ||
return; | ||
} | ||
if (!response.body) { | ||
return; | ||
} | ||
// Read a stream of server-sent events | ||
// and feed them to the observer as they are being generated | ||
const reader = response.body.getReader(); | ||
const textDecoder = new TextDecoder(); | ||
while (true) { | ||
const {value, done} = await reader.read(); | ||
if (done) { | ||
break; | ||
} | ||
const content = textDecoder.decode(value); | ||
if (content) { | ||
observer.next(content); | ||
} | ||
} | ||
observer.complete(); | ||
}; | ||
`; |