@johnowennixon/diffdash 1.7.0 → 1.8.0
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.
- package/README.md +13 -16
- package/dist/package.json +21 -20
- package/dist/src/lib_datetime.js +4 -1
- package/dist/src/lib_diffdash_cli.js +1 -3
- package/dist/src/lib_diffdash_config.js +4 -13
- package/dist/src/lib_diffdash_llm.js +7 -13
- package/dist/src/lib_diffdash_sequence.js +12 -9
- package/dist/src/lib_git_message_generate.js +11 -11
- package/dist/src/lib_git_message_schema.js +3 -3
- package/dist/src/lib_llm_access.js +14 -53
- package/dist/src/lib_llm_api.js +2 -36
- package/dist/src/lib_llm_chat.js +26 -19
- package/dist/src/lib_llm_config.js +4 -14
- package/dist/src/lib_llm_list.js +10 -8
- package/dist/src/lib_llm_model.js +328 -228
- package/dist/src/lib_llm_results.js +47 -0
- package/dist/src/lib_tell.js +6 -5
- package/dist/src/lib_tui_none.js +15 -0
- package/dist/src/lib_tui_number.js +22 -0
- package/dist/src/lib_tui_table.js +13 -5
- package/package.json +21 -20
- package/dist/src/lib_assert_type.js +0 -30
- package/dist/src/lib_type_guard.js +0 -15
package/dist/src/lib_llm_chat.js
CHANGED
|
@@ -1,16 +1,15 @@
|
|
|
1
|
-
import { generateObject, generateText } from "ai";
|
|
1
|
+
import { generateObject, generateText, stepCountIs } from "ai";
|
|
2
2
|
import { debug_channels, debug_inspect_when } from "./lib_debug.js";
|
|
3
3
|
import { Duration } from "./lib_duration.js";
|
|
4
4
|
import { env_get_empty, env_get_substitute } from "./lib_env.js";
|
|
5
5
|
import { error_get_text } from "./lib_error.js";
|
|
6
6
|
import { llm_api_get_ai_sdk_language_model } from "./lib_llm_api.js";
|
|
7
|
-
import {
|
|
7
|
+
import { parse_int, parse_int_or_undefined } from "./lib_parse_number.js";
|
|
8
8
|
import { tell_debug } from "./lib_tell.js";
|
|
9
9
|
import { tui_block_string } from "./lib_tui_block.js";
|
|
10
10
|
function llm_chat_get_parameters() {
|
|
11
11
|
return {
|
|
12
|
-
|
|
13
|
-
temperature: parse_float_or_undefined(env_get_substitute("lib_llm_chat_temperature", "0.6")),
|
|
12
|
+
max_output_tokens: parse_int_or_undefined(env_get_empty("lib_llm_chat_max_output_tokens")),
|
|
14
13
|
timeout: parse_int(env_get_substitute("lib_llm_chat_timeout", "60")),
|
|
15
14
|
};
|
|
16
15
|
}
|
|
@@ -23,24 +22,26 @@ function llm_chat_debug_prompts({ llm_model_name, system_prompt, user_prompt, })
|
|
|
23
22
|
tui_block_string({ teller, title: `LLM user prompt (for ${llm_model_name}):`, content: user_prompt });
|
|
24
23
|
}
|
|
25
24
|
}
|
|
26
|
-
export async function llm_chat_generate_text({ llm_config,
|
|
27
|
-
const { llm_model_name,
|
|
25
|
+
export async function llm_chat_generate_text({ llm_config, system_prompt, user_prompt, tools, max_steps, min_steps, }) {
|
|
26
|
+
const { llm_model_name, llm_model_detail, llm_model_code, llm_api_code, llm_api_key } = llm_config;
|
|
28
27
|
llm_chat_debug_prompts({ system_prompt, user_prompt, llm_model_name });
|
|
29
28
|
const ai_sdk_language_model = llm_api_get_ai_sdk_language_model({
|
|
30
29
|
llm_model_code,
|
|
31
30
|
llm_api_code,
|
|
32
31
|
llm_api_key,
|
|
33
32
|
});
|
|
34
|
-
const {
|
|
33
|
+
const { recommended_temperature, provider_options } = llm_model_detail;
|
|
34
|
+
const temperature = recommended_temperature;
|
|
35
|
+
const { max_output_tokens, timeout } = llm_chat_get_parameters();
|
|
35
36
|
const llm_inputs = {
|
|
36
37
|
model: ai_sdk_language_model,
|
|
37
38
|
system: system_prompt,
|
|
38
39
|
prompt: user_prompt,
|
|
39
40
|
tools,
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
maxTokens: max_tokens,
|
|
41
|
+
stopWhen: max_steps === undefined ? undefined : stepCountIs(max_steps),
|
|
42
|
+
maxOutputTokens: max_output_tokens,
|
|
43
43
|
temperature,
|
|
44
|
+
providerOptions: provider_options,
|
|
44
45
|
abortSignal: AbortSignal.timeout(timeout * 1000),
|
|
45
46
|
};
|
|
46
47
|
debug_inspect_when(debug_channels.llm_inputs, llm_inputs, `LLM inputs object (for ${llm_model_name})`);
|
|
@@ -53,45 +54,51 @@ export async function llm_chat_generate_text({ llm_config, headers, system_promp
|
|
|
53
54
|
if (max_steps !== undefined && llm_outputs.steps.length === max_steps) {
|
|
54
55
|
throw new Error("Too many steps taken");
|
|
55
56
|
}
|
|
56
|
-
|
|
57
|
+
const { text: generated_text, reasoningText: reasoning_text, totalUsage: total_usage, providerMetadata: provider_metadata, } = llm_outputs;
|
|
58
|
+
return { generated_text, reasoning_text, total_usage, provider_metadata };
|
|
57
59
|
}
|
|
58
|
-
export async function
|
|
60
|
+
export async function llm_chat_generate_text_result({ llm_config, system_prompt, user_prompt, }) {
|
|
59
61
|
const duration = new Duration();
|
|
60
62
|
duration.start();
|
|
61
63
|
try {
|
|
62
|
-
const
|
|
64
|
+
const outputs = await llm_chat_generate_text({ llm_config, system_prompt, user_prompt });
|
|
63
65
|
duration.stop();
|
|
64
66
|
const seconds = duration.seconds_rounded();
|
|
65
|
-
return { llm_config, seconds,
|
|
67
|
+
return { llm_config, seconds, error_text: null, outputs };
|
|
66
68
|
}
|
|
67
69
|
catch (error) {
|
|
68
70
|
duration.stop();
|
|
69
71
|
const seconds = duration.seconds_rounded();
|
|
70
72
|
const error_text = error_get_text(error);
|
|
71
|
-
return { llm_config, seconds,
|
|
73
|
+
return { llm_config, seconds, error_text, outputs: null };
|
|
72
74
|
}
|
|
73
75
|
}
|
|
74
76
|
export async function llm_chat_generate_object({ llm_config, user_prompt, system_prompt, schema, }) {
|
|
75
|
-
const { llm_model_name,
|
|
77
|
+
const { llm_model_name, llm_model_detail, llm_model_code, llm_api_code, llm_api_key } = llm_config;
|
|
76
78
|
llm_chat_debug_prompts({ system_prompt, user_prompt, llm_model_name });
|
|
77
79
|
const ai_sdk_language_model = llm_api_get_ai_sdk_language_model({
|
|
78
80
|
llm_model_code,
|
|
79
81
|
llm_api_code,
|
|
80
82
|
llm_api_key,
|
|
81
83
|
});
|
|
82
|
-
const {
|
|
84
|
+
const { recommended_temperature, provider_options } = llm_model_detail;
|
|
85
|
+
const temperature = recommended_temperature;
|
|
86
|
+
const { max_output_tokens, timeout } = llm_chat_get_parameters();
|
|
83
87
|
const llm_inputs = {
|
|
84
88
|
model: ai_sdk_language_model,
|
|
85
89
|
system: system_prompt,
|
|
86
90
|
prompt: user_prompt,
|
|
91
|
+
output: "object",
|
|
87
92
|
schema,
|
|
88
|
-
|
|
93
|
+
maxOutputTokens: max_output_tokens,
|
|
89
94
|
temperature,
|
|
95
|
+
providerOptions: provider_options,
|
|
90
96
|
abortSignal: AbortSignal.timeout(timeout * 1000),
|
|
91
97
|
};
|
|
92
98
|
debug_inspect_when(debug_channels.llm_inputs, llm_inputs, `LLM inputs object (for ${llm_model_name})`);
|
|
93
99
|
// This is liable to throw an error
|
|
94
100
|
const llm_outputs = await generateObject(llm_inputs);
|
|
95
101
|
debug_inspect_when(debug_channels.llm_outputs, llm_outputs, `LLM outputs object (for ${llm_model_name})`);
|
|
96
|
-
|
|
102
|
+
const { object: generated_object, usage: total_usage, providerMetadata: provider_metadata } = llm_outputs;
|
|
103
|
+
return { generated_object, total_usage, provider_metadata };
|
|
97
104
|
}
|
|
@@ -1,23 +1,13 @@
|
|
|
1
1
|
import { llm_access_available, llm_access_get } from "./lib_llm_access.js";
|
|
2
|
-
import { llm_api_get_via } from "./lib_llm_api.js";
|
|
3
2
|
import { llm_model_find_detail, llm_model_get_choices } from "./lib_llm_model.js";
|
|
4
|
-
|
|
5
|
-
export function llm_config_get({ llm_model_details, llm_model_name, llm_router, }) {
|
|
3
|
+
export function llm_config_get({ llm_model_details, llm_model_name, }) {
|
|
6
4
|
const llm_model_detail = llm_model_find_detail({ llm_model_details, llm_model_name });
|
|
7
|
-
const access = llm_access_get({ llm_model_details, llm_model_name
|
|
5
|
+
const access = llm_access_get({ llm_model_details, llm_model_name });
|
|
8
6
|
const { llm_model_code, llm_api_code, llm_api_key } = access;
|
|
9
7
|
return { llm_model_name, llm_model_detail, llm_model_code, llm_api_code, llm_api_key };
|
|
10
8
|
}
|
|
11
|
-
export function llm_config_get_all({ llm_model_details,
|
|
9
|
+
export function llm_config_get_all({ llm_model_details, llm_include, llm_excludes, }) {
|
|
12
10
|
const choices = llm_model_get_choices({ llm_model_details });
|
|
13
11
|
const available = choices.filter((llm_model_name) => llm_access_available({ llm_model_details, llm_model_name, llm_include, llm_excludes }));
|
|
14
|
-
return available.map((llm_model_name) => llm_config_get({ llm_model_details, llm_model_name
|
|
15
|
-
}
|
|
16
|
-
export function llm_config_get_model_via({ llm_config }) {
|
|
17
|
-
const { llm_model_name, llm_api_code } = llm_config;
|
|
18
|
-
return `${llm_model_name} (${llm_api_get_via(llm_api_code)})`;
|
|
19
|
-
}
|
|
20
|
-
export function llm_config_show({ llm_config }) {
|
|
21
|
-
const model_via = llm_config_get_model_via({ llm_config });
|
|
22
|
-
tell_info(`Using LLM ${model_via}`);
|
|
12
|
+
return available.map((llm_model_name) => llm_config_get({ llm_model_details, llm_model_name }));
|
|
23
13
|
}
|
package/dist/src/lib_llm_list.js
CHANGED
|
@@ -1,18 +1,20 @@
|
|
|
1
1
|
import { DOLLAR } from "./lib_char_punctuation.js";
|
|
2
2
|
import { stdio_write_stdout_linefeed } from "./lib_stdio_write.js";
|
|
3
3
|
import { tell_info, tell_warning } from "./lib_tell.js";
|
|
4
|
-
import { tui_justify_right } from "./lib_tui_justify.js";
|
|
5
4
|
import { TuiTable } from "./lib_tui_table.js";
|
|
6
5
|
export function llm_list_models({ llm_model_details }) {
|
|
7
|
-
const headings = ["NAME", "CONTEXT", "INPUT", "OUTPUT"];
|
|
8
|
-
const
|
|
6
|
+
const headings = ["NAME", "API", "CONTEXT", "INPUT", "OUTPUT", "REASONING"];
|
|
7
|
+
const alignments = ["left", "left", "right", "right", "right", "left"];
|
|
8
|
+
const table = new TuiTable({ headings, alignments });
|
|
9
9
|
for (const detail of llm_model_details) {
|
|
10
|
-
const { llm_model_name, context_window, cents_input, cents_output } = detail;
|
|
10
|
+
const { llm_model_name, llm_api_code, context_window, cents_input, cents_output, default_reasoning } = detail;
|
|
11
11
|
const tui_name = llm_model_name;
|
|
12
|
-
const
|
|
13
|
-
const
|
|
14
|
-
const
|
|
15
|
-
const
|
|
12
|
+
const tui_api = llm_api_code;
|
|
13
|
+
const tui_context = context_window.toString();
|
|
14
|
+
const tui_input = DOLLAR + (cents_input / 100).toFixed(2);
|
|
15
|
+
const tui_output = DOLLAR + (cents_output / 100).toFixed(2);
|
|
16
|
+
const tui_reasoning = default_reasoning ? "True" : "False";
|
|
17
|
+
const row = [tui_name, tui_api, tui_context, tui_input, tui_output, tui_reasoning];
|
|
16
18
|
table.push(row);
|
|
17
19
|
}
|
|
18
20
|
stdio_write_stdout_linefeed(table.toString());
|