Skip to content

Commit d5e6a95

Browse files
committed
wip
1 parent 0dda04d commit d5e6a95

File tree

1 file changed

+31
-4
lines changed

1 file changed

+31
-4
lines changed

gpt/ctx.nu

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,8 @@ def frame-to-turn [frame: record] {
3838
}
3939

4040
{
41-
id: $frame.id
4241
role: $role
4342
content: $content
44-
options: $options_delta
4543
} | if $cache {
4644
insert cache $cache
4745
} else { $in }
@@ -70,6 +68,29 @@ def id-to-turns [ids] {
7068
$turns
7169
}
7270

71+
# Follow the continues chain to collect frames (for options extraction)
72+
def id-to-frames [ids] {
73+
mut frames = []
74+
mut stack = [] | append $ids
75+
76+
while not ($stack | is-empty) {
77+
let current_id = $stack | first
78+
let frame = .get $current_id
79+
$frames = ($frames | prepend $frame)
80+
$stack = ($stack | skip 1)
81+
82+
let next = $frame | get meta?.continues?
83+
match ($next | describe -d | get type) {
84+
"string" => { $stack = ($stack | append $next) }
85+
"list" => { $stack = ($stack | append $next) }
86+
"nothing" => { }
87+
_ => ( error make {msg: "Invalid continues value"})
88+
}
89+
}
90+
91+
$frames
92+
}
93+
7394
# Raw per-turn view
7495
export def list [headish?] {
7596
let ids = $headish | default [] | each { headish-to-id $in }
@@ -79,10 +100,16 @@ export def list [headish?] {
79100

80101
# Fully resolved context window
81102
export def resolve [headish?] {
82-
let turns = list $headish
83-
let options = $turns | get options? | compact --empty | if ($in | is-not-empty) {
103+
let ids = $headish | default [] | each { headish-to-id $in }
104+
let ids = if ($ids | is-empty) { (.head gpt.turn).id } else { $ids }
105+
106+
let turns = id-to-turns $ids
107+
let frames = id-to-frames $ids
108+
109+
let options = $frames | each { $in | get meta? | default {} | get options? | default {} } | if ($in | is-not-empty) {
84110
reduce {|it acc| $acc | merge deep $it }
85111
} else { null }
112+
86113
{
87114
messages: $turns
88115
options: $options

0 commit comments

Comments
 (0)