fg-lib-gpt 1.1.1 → 1.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/main.js +9 -8
  2. package/package.json +1 -1
package/main.js CHANGED
@@ -13,12 +13,15 @@ const doGpt = async ({
13
13
  timeout = DEFAULT_TIMEOUT,
14
14
  temperature = DEFAULT_TEMPERATURE,
15
15
  validate,
16
- response_format = { 'type': 'text' }
16
+ response_format = { 'type': 'text' },
17
+ max_tokens
17
18
  }) => {
18
19
 
20
+ const json = response_format.type === 'json' || response_format.type === 'json_schema'
21
+
19
22
  try {
20
23
  const response = await Promise.race([
21
- getGptResponse({ messages, model, temperature, response_format }),
24
+ getGptResponse({ messages, model, temperature, response_format, max_tokens }),
22
25
  new Promise((_, reject) =>
23
26
  setTimeout(() => reject(new Error('Custom timeout')), timeout))
24
27
  ])
@@ -26,9 +29,6 @@ const doGpt = async ({
26
29
  if (typeof validate === 'function')
27
30
  validate(response)
28
31
 
29
-
30
- const json = response_format.type === 'json' || response_format.type === 'json_schema'
31
-
32
32
  // JSON.parse might also fail
33
33
  return {
34
34
  success: true,
@@ -38,7 +38,7 @@ const doGpt = async ({
38
38
  catch (e) {
39
39
  console.error('**** ERROR ***** OpenAI Error (1): ' + e.message)
40
40
  try {
41
- const response = await getGptResponse({ messages, model, temperature, response_format })
41
+ const response = await getGptResponse({ messages, model, temperature, response_format, max_tokens })
42
42
 
43
43
  return {
44
44
  success: true,
@@ -57,7 +57,7 @@ const doGpt = async ({
57
57
 
58
58
 
59
59
 
60
- const getGptResponse = async ({ messages, model, response_format, temperature }) => {
60
+ const getGptResponse = async ({ messages, model, response_format, temperature, max_tokens }) => {
61
61
 
62
62
  const res = await axios.post(
63
63
  'https://api.openai.com/v1/chat/completions',
@@ -65,7 +65,8 @@ const getGptResponse = async ({ messages, model, response_format, temperature })
65
65
  messages,
66
66
  model,
67
67
  response_format,
68
- temperature
68
+ temperature,
69
+ max_tokens
69
70
  },
70
71
  {
71
72
  headers: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fg-lib-gpt",
3
- "version": "1.1.1",
3
+ "version": "1.1.2",
4
4
  "main": "main.js",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"