@cortexkit/pi-magic-context 0.41.0 → 0.41.1

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.
@@ -12,13 +12,15 @@ function finiteNumber(value) {
12
12
  function calibrateHistorianProviderPayload(payload, temperature, maxOutputTokens) {
13
13
  if (typeof payload !== "object" || payload === null || Array.isArray(payload))
14
14
  return payload;
15
+ if (temperature === undefined && maxOutputTokens === undefined)
16
+ return payload;
15
17
  const calibrated = { ...payload };
16
18
  const generationConfig = calibrated.generationConfig;
17
19
  if (typeof generationConfig === "object" && generationConfig !== null && !Array.isArray(generationConfig)) {
18
20
  calibrated.generationConfig = {
19
21
  ...generationConfig,
20
- temperature,
21
- maxOutputTokens
22
+ ...temperature !== undefined ? { temperature } : {},
23
+ ...maxOutputTokens !== undefined ? { maxOutputTokens } : {}
22
24
  };
23
25
  return calibrated;
24
26
  }
@@ -26,27 +28,31 @@ function calibrateHistorianProviderPayload(payload, temperature, maxOutputTokens
26
28
  if (typeof inferenceConfig === "object" && inferenceConfig !== null && !Array.isArray(inferenceConfig)) {
27
29
  calibrated.inferenceConfig = {
28
30
  ...inferenceConfig,
29
- temperature,
30
- maxTokens: maxOutputTokens
31
+ ...temperature !== undefined ? { temperature } : {},
32
+ ...maxOutputTokens !== undefined ? { maxTokens: maxOutputTokens } : {}
31
33
  };
32
34
  return calibrated;
33
35
  }
34
- calibrated.temperature = temperature;
35
- if ("max_output_tokens" in calibrated) {
36
- calibrated.max_output_tokens = maxOutputTokens;
37
- } else if ("max_completion_tokens" in calibrated) {
38
- calibrated.max_completion_tokens = maxOutputTokens;
39
- } else if ("max_tokens" in calibrated) {
40
- calibrated.max_tokens = maxOutputTokens;
41
- } else if ("maxTokens" in calibrated) {
42
- calibrated.maxTokens = maxOutputTokens;
36
+ if (temperature !== undefined) {
37
+ calibrated.temperature = temperature;
38
+ }
39
+ if (maxOutputTokens !== undefined) {
40
+ if ("max_output_tokens" in calibrated) {
41
+ calibrated.max_output_tokens = maxOutputTokens;
42
+ } else if ("max_completion_tokens" in calibrated) {
43
+ calibrated.max_completion_tokens = maxOutputTokens;
44
+ } else if ("max_tokens" in calibrated) {
45
+ calibrated.max_tokens = maxOutputTokens;
46
+ } else if ("maxTokens" in calibrated) {
47
+ calibrated.maxTokens = maxOutputTokens;
48
+ }
43
49
  }
44
50
  return calibrated;
45
51
  }
46
52
  function historianCalibrationExtension(pi) {
47
53
  const temperature = finiteNumber(process.env[HISTORIAN_TEMPERATURE_ENV]);
48
54
  const maxOutputTokens = finiteNumber(process.env[HISTORIAN_MAX_OUTPUT_TOKENS_ENV]);
49
- if (temperature === undefined || maxOutputTokens === undefined)
55
+ if (temperature === undefined && maxOutputTokens === undefined)
50
56
  return;
51
57
  pi.on("before_provider_request", (event) => calibrateHistorianProviderPayload(event.payload, temperature, maxOutputTokens));
52
58
  }