Skip to content

Commit 55e8a2f

Browse files
authored
Merge pull request #23 from CoolSpring8/token-probability
Implement token-level probability tracking and reroll UI
2 parents 954b09e + 788ad13 commit 55e8a2f

19 files changed

Lines changed: 1780 additions & 176 deletions

bun.lock

Lines changed: 9 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"@ai-sdk/react": "^2.0.98",
1414
"@base-ui-components/react": "^1.0.0-beta.4",
1515
"@built-in-ai/core": "^2.0.1",
16+
"@floating-ui/react": "^0.27.16",
1617
"@mantine/core": "^7.8.1",
1718
"@mantine/hooks": "^7.8.1",
1819
"@xyflow/react": "^12.9.1",

src/App.tsx

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ const App = () => {
8787
activeModel,
8888
openAIProvider,
8989
getBuiltInChatModel,
90+
baseURL: activeProvider?.config.baseURL ?? "",
91+
apiKey: activeProvider?.config.apiKey ?? "",
9092
});
9193

9294
const {
@@ -113,17 +115,21 @@ const App = () => {
113115
isTreeEmpty,
114116
createSystemMessage,
115117
setActiveTarget,
118+
rerollFromToken,
116119
} = useConversationController({
117120
defaultSystemPrompt,
118121
ensureChatReady,
119122
});
120123

121124
const {
122125
textContent,
123-
setTextContent,
126+
overwriteTextContent,
124127
isGenerating: isTextGenerating,
125128
predict,
126129
cancel,
130+
tokenLogprobs: textTokenLogprobs,
131+
rerollFromToken: rerollTextFromToken,
132+
seedText: textSeed,
127133
} = useTextCompletion({
128134
ensureCompletionReady,
129135
});
@@ -167,8 +173,8 @@ const App = () => {
167173
const handleClearConversation = useCallback(() => {
168174
clearConversation();
169175
cancel();
170-
setTextContent("");
171-
}, [cancel, clearConversation, setTextContent]);
176+
overwriteTextContent("");
177+
}, [cancel, clearConversation, overwriteTextContent]);
172178

173179
const handleImportPreparation = useCallback(() => {
174180
abortActiveStreams();
@@ -217,6 +223,7 @@ const App = () => {
217223
onEditCancel={cancelEdit}
218224
onPromptDirtyChange={setIsPromptDirty}
219225
resetSignal={resetSignal}
226+
onTokenReroll={rerollFromToken}
220227
/>
221228
</div>
222229
) : view === "diagram" ? (
@@ -238,10 +245,14 @@ const App = () => {
238245
: undefined
239246
}
240247
onChange={(value) => {
241-
setTextContent(value);
248+
overwriteTextContent(value);
242249
}}
243250
onPredict={predict}
244251
onCancel={cancel}
252+
tokenLogprobs={textTokenLogprobs}
253+
onTokenReroll={rerollTextFromToken}
254+
showTokenOverlay
255+
generatedPrefix={textSeed}
245256
/>
246257
)}
247258
<SettingsModal open={isSettingsOpen} onClose={onSettingsClose} />

src/ai/openaiCompatible.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { createOpenAICompatible } from "@ai-sdk/openai-compatible";
22
import type { ModelInfo } from "../types";
33

4+
export const OPENAI_COMPATIBLE_PROVIDER_NAME = "user-openai-compatible";
5+
46
const normalizeBaseURL = (baseURL: string) =>
57
baseURL.trim().replace(/\/+$/, "");
68

@@ -17,7 +19,7 @@ export const buildOpenAICompatibleProvider = ({
1719
}
1820
return createOpenAICompatible({
1921
baseURL: normalizedBaseURL,
20-
name: "user-openai-compatible",
22+
name: OPENAI_COMPATIBLE_PROVIDER_NAME,
2123
apiKey: apiKey || "_PLACEHOLDER_",
2224
});
2325
};

0 commit comments

Comments
 (0)