Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Building layer
FROM node:16-alpine as development
FROM node:18-alpine as development
# Optional NPM automation (auth) token build argument
# ARG NPM_TOKEN
# Optionally authenticate NPM registry
Expand All @@ -15,7 +15,7 @@ COPY src/ src/
# Build application (produces dist/ folder)
RUN npm run build
# Runtime (production) layer
FROM node:16-alpine as production
FROM node:18-alpine as production
# Optional NPM automation (auth) token build argument
# ARG NPM_TOKEN
# Optionally authenticate NPM registry
Expand Down
22 changes: 0 additions & 22 deletions src/app.controller.spec.ts

This file was deleted.

17 changes: 11 additions & 6 deletions src/app.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { AppService } from './app.service';

@Controller()
export class AppController {
constructor(private readonly appService: AppService) { }
constructor(private readonly appService: AppService) {}

@Get('models')
models() {
Expand All @@ -15,7 +15,7 @@ export class AppController {

@Controller('chat')
export class ChatController {
constructor(private readonly appService: AppService) { }
constructor(private readonly appService: AppService) {}

@Get()
getHello(): string {
Expand All @@ -29,16 +29,22 @@ export class ChatController {
const [resource_id, deployment_id, azureApiKey] = apiKey.split(':');
const endpoint = `https://${resource_id}.openai.azure.com`;
const stream = request.body['stream'];
const response = await this.appService.getCompletions(endpoint, deployment_id, azureApiKey, request.body, stream);
const response = await this.appService.getCompletions(
endpoint,
deployment_id,
azureApiKey,
request.body,
stream,
);

// set response headers
for (const [key, value] of response.headers as AxiosHeaders) {
res.header[key] = value;
}
res.status(response.status);
if(stream) {
if (stream) {
const streamData = response.data;
streamData.on('data', data => {
streamData.on('data', (data) => {
res.write(data);
});
streamData.on('end', () => {
Expand All @@ -49,4 +55,3 @@ export class ChatController {
}
}
}

6 changes: 3 additions & 3 deletions src/app.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,16 @@ export class AppService {
body: any,
stream: boolean,
) {
let url = `${endpoint}/openai/deployments/${deployment_id}/chat/completions?api-version=2023-03-15-preview`;
let headers = {
const url = `${endpoint}/openai/deployments/${deployment_id}/chat/completions?api-version=2023-03-15-preview`;
const headers = {
'api-key': azureApiKey,
'Content-Type': 'application/json',
};
const config = { headers: headers };
if (stream) {
config['responseType'] = 'stream';
}
let ret = this.httpService.post(url, body, config);
const ret = this.httpService.post(url, body, config);
return await firstValueFrom(ret);
}
}