|
1 | 1 | const { Configuration, OpenAIApi } = require('openai');
|
2 | 2 | const _ = require('lodash');
|
| 3 | +const { genAzureEndpoint } = require('../utils/genAzureEndpoints'); |
3 | 4 |
|
4 |
| -const proxyEnvToAxiosProxy = proxyString => { |
| 5 | +const proxyEnvToAxiosProxy = (proxyString) => { |
5 | 6 | if (!proxyString) return null;
|
6 | 7 |
|
7 | 8 | const regex = /^([^:]+):\/\/(?:([^:@]*):?([^:@]*)@)?([^:]+)(?::(\d+))?/;
|
@@ -47,9 +48,21 @@ const titleConvo = async ({ endpoint, text, response }) => {
|
47 | 48 | frequency_penalty: 0
|
48 | 49 | };
|
49 | 50 |
|
50 |
| - const titleGenClient = new ChatGPTClient(process.env.OPENAI_KEY, titleGenClientOptions); |
| 51 | + const azure = process.env.AZURE_OPENAI_API_KEY ? true : false; |
| 52 | + let apiKey = process.env.OPENAI_KEY; |
| 53 | + |
| 54 | + if (azure) { |
| 55 | + apiKey = process.env.AZURE_OPENAI_API_KEY; |
| 56 | + titleGenClientOptions.reverseProxyUrl = genAzureEndpoint({ |
| 57 | + azureOpenAIApiInstanceName: process.env.AZURE_OPENAI_API_INSTANCE_NAME, |
| 58 | + azureOpenAIApiDeploymentName: process.env.AZURE_OPENAI_API_DEPLOYMENT_NAME, |
| 59 | + azureOpenAIApiVersion: process.env.AZURE_OPENAI_API_VERSION |
| 60 | + }); |
| 61 | + } |
| 62 | + |
| 63 | + const titleGenClient = new ChatGPTClient(apiKey, titleGenClientOptions); |
51 | 64 | const result = await titleGenClient.getCompletion([instructionsPayload], null);
|
52 |
| - title = result.choices[0].message.content.replace(/\s+/g, ' ').trim(); |
| 65 | + title = result.choices[0].message.content.replace(/\s+/g, ' ').replaceAll('"', '').trim(); |
53 | 66 | } catch (e) {
|
54 | 67 | console.error(e);
|
55 | 68 | console.log('There was an issue generating title, see error above');
|
|
0 commit comments