Skip to content

Commit

Permalink
Added streaming API
Browse files Browse the repository at this point in the history
  • Loading branch information
codemakerai-dev committed Jul 8, 2024
1 parent 430ae8e commit 1de1702
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 17 deletions.
18 changes: 9 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@
"test": "node ./out/test/runTest.js"
},
"dependencies": {
"codemaker-sdk": "^2.24.0"
"codemaker-sdk": "^2.25.0"
},
"devDependencies": {
"@types/glob": "^8.1.0",
Expand Down
17 changes: 10 additions & 7 deletions src/assistant/speechServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,16 @@ export default class SpeechServer {
const url = parse(req.url!, true);
const input = Buffer.from(url.query['input'] as string, 'base64url').toString('utf-8');

this.codemakerSerivce.assistantSpeech(input).then((result) => {
res.setHeader('Content-Type', 'audio/mp3');
res.writeHead(200);
res.write(result.audio);
res.end();
}).catch((err) => {
res.writeHead(500);
res.setHeader('Content-Type', 'audio/mp3');

const stream = this.codemakerSerivce.assistantSpeechStream(input);
stream.on('data', (data) => {
res.write(data.audio);
});
stream.on('error', (e) => {
res.statusCode = 500;
});
stream.on('end', () => {
res.end();
});
};
Expand Down
10 changes: 10 additions & 0 deletions src/service/codemakerService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,16 @@ class CodemakerService {
return this.getClient().assistantSpeech(this.createAssistantSpeechRequest(message));
}

/**
* Streams Assistant speech.
*
* @param message chat message
* @returns
*/
public assistantSpeechStream(message: string) {
return this.getClient().assistantSpeechStream(this.createAssistantSpeechRequest(message));
}

/**
* Registers assistant feedback.
*
Expand Down

0 comments on commit 1de1702

Please sign in to comment.