#github.com/xulang-org/packages/synth
Xu 0.16.0 API
导入方式: synth #github.com/xulang-org/packages/synth
公开 API: 12 函数, 0 方法, 4 类型, 0 常量, 0 方法集
扩展包 `synth #github.com/xulang-org/packages/synth`,由模块 github.com/xulang-org/packages 提供。
github.com/xulang-org/packages · 1.17.2 · 安装与使用
struct SftExample
pub struct SftExample {
pub instruction string
pub input string
pub output string
pub system string
}
用途
承载 instruction、input、output、system 等属性的结构体。
公开字段
instruction string- 字段(string)
input string- 字段(string)
output string- 字段(string)
system string- 字段(string)
struct DpoPair
pub struct DpoPair {
pub prompt string
pub chosen string
pub rejected string
}
用途
承载 prompt、chosen、rejected 等属性的结构体。
公开字段
prompt string- 字段(string)
chosen string- 字段(string)
rejected string- 字段(string)
struct RlvrTask
pub struct RlvrTask {
pub id string
pub prompt string
pub expected string
pub verifier string
}
用途
承载 id、prompt、expected、verifier 等属性的结构体。
公开字段
id string- 字段(string)
prompt string- 字段(string)
expected string- 字段(string)
verifier string- 字段(string)
struct FilterStats
pub struct FilterStats {
pub total_input int
pub kept int
pub dropped_empty int
pub dropped_duplicate int
}
用途
承载 total_input、kept、dropped_empty、dropped_duplicate 等属性的结构体。
公开字段
total_input int- 字段(int)
kept int- 字段(int)
dropped_empty int- 字段(int)
dropped_duplicate int- 字段(int)
jaccard_ngram_similarity
pub fn jaccard_ngram_similarity(a &string, b &string, n int) f64
用途
执行 jaccard ngram similarity 操作。
参数
a &string- 值(只读借用,调用方仍持有原值;类型 &string)
b &string- b(只读借用,调用方仍持有原值;类型 &string)
n int- 数量、长度或上限(int)
返回值
f64 — 该类型的值
format_sft_jsonl
pub fn format_sft_jsonl(examples &[]SftExample) string
用途
格式化为 sft jsonl。
参数
examples &[]SftExample- examples(只读借用,调用方仍持有原值;类型 &[]SftExample)
返回值
string — 结果字符串
parse_sft_jsonl
pub fn parse_sft_jsonl(jsonl &string) []SftExample
用途
解析为 sft jsonl。失败时抛出错误,调用方需处理或继续传播。
参数
jsonl &string- jsonl(只读借用,调用方仍持有原值;类型 &string)
返回值
[]SftExample — 切片结果
format_dpo_jsonl
pub fn format_dpo_jsonl(pairs &[]DpoPair) string
用途
格式化为 dpo jsonl。
参数
pairs &[]DpoPair- pairs(只读借用,调用方仍持有原值;类型 &[]DpoPair)
返回值
string — 结果字符串
format_rlvr_jsonl
pub fn format_rlvr_jsonl(tasks &[]RlvrTask) string
用途
格式化为 rlvr jsonl。
参数
tasks &[]RlvrTask- tasks(只读借用,调用方仍持有原值;类型 &[]RlvrTask)
返回值
string — 结果字符串
save_jsonl
pub fn save_jsonl(path string, content &string) int
用途
执行 save jsonl 操作。失败时抛出错误,调用方需处理或继续传播。
参数
path string- 文件系统路径(string)
content &string- content(只读借用,调用方仍持有原值;类型 &string)
返回值
int — 该类型的值
dedup_exact
pub fn dedup_exact(items &[]string) []string
用途
执行 dedup exact 操作。
参数
items &[]string- 元素列表(只读借用,调用方仍持有原值;类型 &[]string)
返回值
[]string — 切片结果
dedup_near_jaccard
pub fn dedup_near_jaccard(items &[]string, ngram int, threshold f64) []string
用途
执行 dedup near jaccard 操作。
参数
items &[]string- 元素列表(只读借用,调用方仍持有原值;类型 &[]string)
ngram int- ngram(int)
threshold f64- threshold(f64)
返回值
[]string — 切片结果
filter_sft_quality
pub fn filter_sft_quality(examples &[]SftExample, min_output_chars int, dedup_jaccard f64, stats_out $&FilterStats) []SftExample
用途
执行 filter sft quality 操作。
参数
examples &[]SftExample- examples(只读借用,调用方仍持有原值;类型 &[]SftExample)
min_output_chars int- min_output_chars(int)
dedup_jaccard f64- dedup_jaccard(f64)
stats_out $&FilterStats- stats_out(独占借用,可修改原值;类型 $&FilterStats)
返回值
[]SftExample — 切片结果
generate_sft_openai
pub fn generate_sft_openai(client &openai.Client, model string, topic string, count int, system_hint string) []SftExample
用途
执行 generate sft openai 操作。失败时抛出错误,调用方需处理或继续传播。
参数
client &openai.Client- client(只读借用,调用方仍持有原值;类型 &openai.Client)
model string- model(string)
topic string- topic(string)
count int- count(int)
system_hint string- system_hint(string)
返回值
[]SftExample — 切片结果
generate_dpo_pair_openai
pub fn generate_dpo_pair_openai(client &openai.Client, strong_model string, weak_model string, prompt string) DpoPair
用途
执行 generate dpo pair openai 操作。失败时抛出错误,调用方需处理或继续传播。
参数
client &openai.Client- client(只读借用,调用方仍持有原值;类型 &openai.Client)
strong_model string- strong_model(string)
weak_model string- weak_model(string)
prompt string- prompt(string)
返回值
DpoPair — 该类型的值
distill_dataset_openai
pub fn distill_dataset_openai(teacher &openai.Client, teacher_model string, prompts &[]string, system_prompt string) []SftExample
用途
执行 distill dataset openai 操作。失败时抛出错误,调用方需处理或继续传播。
参数
teacher &openai.Client- teacher(只读借用,调用方仍持有原值;类型 &openai.Client)
teacher_model string- teacher_model(string)
prompts &[]string- prompts(只读借用,调用方仍持有原值;类型 &[]string)
system_prompt string- system_prompt(string)
返回值
[]SftExample — 切片结果