-
Notifications
You must be signed in to change notification settings - Fork 5
feat: integrate ollama api with palette #42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 28 commits
b836ae5
8bf9fb4
2fc8ec1
4369d09
a118ce6
c1e2ddc
63058c7
aa726b8
2faf0f0
94fb28f
a30918c
fb33aa3
b670284
14227d4
fc50c27
ef019df
1e6ac7f
64be8a7
e0b7d2d
07d5318
4e7d1d0
751372d
ac981d7
c44ebc6
1e10fe5
c621a03
8df804e
f0b8d93
63427b1
aab3678
14aee33
bfd5478
2a4b6c6
b5a59be
76ed06e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| /* | ||
| * Copyright 2025 Inclusive Design Research Centre, OCAD University | ||
| * All rights reserved. | ||
| * | ||
| * Licensed under the New BSD license. You may not use this file except in | ||
| * compliance with this License. | ||
| * | ||
| * You may obtain a copy of the License at | ||
| * https://github.com/inclusive-design/adaptive-palette/blob/main/LICENSE | ||
| */ | ||
|
|
||
| .actionTextCell { | ||
| border: 2px solid black; | ||
| color: black; | ||
| background-color: white; | ||
| margin-left: 1rem; | ||
| padding-inline: 0.5rem; | ||
| text-align: left; | ||
| font-size: 1rem; | ||
| width: 50%; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| /* | ||
| * Copyright 2023-2024 Inclusive Design Research Centre, OCAD University | ||
| * All rights reserved. | ||
| * | ||
| * Licensed under the New BSD license. You may not use this file except in | ||
| * compliance with this License. | ||
| * | ||
| * You may obtain a copy of the License at | ||
| * https://github.com/inclusive-design/adaptive-palette/blob/main/LICENSE | ||
| */ | ||
|
|
||
| import { VNode } from "preact"; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There isn't a test for this component. Is it intentional?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No there should be a test. It's possible I misplaced it. If not, I will write one. |
||
| import { html } from "htm/preact"; | ||
|
|
||
| import { generateGridStyle, speak } from "./GlobalUtils"; | ||
| import { BlissSymbolInfoType, LayoutInfoType } from "./index.d"; | ||
| import "./ActionTextCell.scss"; | ||
|
|
||
| type ActionTextCellPropsType = { | ||
| id: string, | ||
| options: BlissSymbolInfoType & LayoutInfoType | ||
| }; | ||
|
|
||
| export function ActionTextCell (props: ActionTextCellPropsType): VNode { | ||
| const { | ||
| columnStart, columnSpan, rowStart, rowSpan, label | ||
| } = props.options; | ||
| const gridStyles = generateGridStyle(columnStart, columnSpan, rowStart, rowSpan); | ||
|
|
||
| const sentenceClicked = () => { | ||
| speak(label.replace(/^[0-9]+./,"").trim()); // remove any leading "1. " | ||
|
||
| }; | ||
|
|
||
| return html` | ||
| <button id="${props.id}" class="actionTextCell" style="${gridStyles}" onClick=${sentenceClicked}> | ||
| ${label} | ||
| </button> | ||
| `; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| /* | ||
| * Copyright 2025 Inclusive Design Research Centre, OCAD University | ||
| * All rights reserved. | ||
| * | ||
| * Licensed under the New BSD license. You may not use this file except in | ||
| * compliance with this License. | ||
| * | ||
| * You may obtain a copy of the License at | ||
| * https://github.com/inclusive-design/adaptive-palette/blob/main/LICENSE | ||
| */ | ||
|
|
||
| .commandTelegraphicCompletions { | ||
| button { | ||
| font-size: 1rem; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| /* | ||
| * Copyright 2025 Inclusive Design Research Centre, OCAD University | ||
| * All rights reserved. | ||
| * | ||
| * Licensed under the New BSD license. You may not use this file except in | ||
| * compliance with this License. | ||
| * | ||
| * You may obtain a copy of the License at | ||
| * https://github.com/inclusive-design/adaptive-palette/blob/main/LICENSE | ||
| */ | ||
|
|
||
| import { render, screen } from "@testing-library/preact"; | ||
| import "@testing-library/jest-dom"; | ||
| import { html } from "htm/preact"; | ||
|
|
||
| import { | ||
| CommandTelegraphicCompletions, TELEGRPAHIC_BUTTON_LABEL, CANCEL_BUTTON_LABEL | ||
| } from "./CommandTelegraphicCompletions"; | ||
|
|
||
| describe("CommandTelegraphicCompletions component", (): void => { | ||
|
|
||
| test("Render telegraphic buttons", async(): Promise<void> => { | ||
| render(html` | ||
| <${CommandTelegraphicCompletions} model="llama3.1:latest" stream=false />` | ||
| ); | ||
| const triggerButton = await screen.findByText(TELEGRPAHIC_BUTTON_LABEL); | ||
| expect(triggerButton).toBeInTheDocument(); | ||
| expect(triggerButton).toBeInstanceOf(HTMLButtonElement); | ||
|
|
||
| const cancelButton = await screen.findByText(CANCEL_BUTTON_LABEL); | ||
| expect(cancelButton).toBeInTheDocument(); | ||
| expect(cancelButton).toBeInstanceOf(HTMLButtonElement); | ||
| }); | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| /* | ||
| * Copyright 2025 Inclusive Design Research Centre, OCAD University | ||
| * All rights reserved. | ||
| * | ||
| * Licensed under the New BSD license. You may not use this file except in | ||
| * compliance with this License. | ||
| * | ||
| * You may obtain a copy of the License at | ||
| * https://github.com/inclusive-design/adaptive-palette/blob/main/LICENSE | ||
| */ | ||
|
|
||
| import { VNode } from "preact"; | ||
| import { html } from "htm/preact"; | ||
|
|
||
| import { changeEncodingContents, sentenceCompletionsSignal } from "./GlobalData"; | ||
| import { TEXTAREA_ID } from "./DialogPromptEntries"; | ||
| import { queryChat } from "./ollamaApi"; | ||
|
|
||
| import "./CommandTelegraphicCompletions.scss"; | ||
|
|
||
| export const TELEGRPAHIC_BUTTON_LABEL = "Telegraphic Completions"; | ||
| export const CANCEL_BUTTON_LABEL = "Cancel"; | ||
|
|
||
| type CommandTelegraphicCompletionsProps = { | ||
| id: string, | ||
| model: string, | ||
| // This should be a boolean type, but for Preact/html the type of the value is | ||
| // string. It should be "true" or "false". | ||
| stream: ("true" | "false") | ||
|
||
| }; | ||
|
|
||
| export function CommandTelegraphicCompletions (props: CommandTelegraphicCompletionsProps): VNode { | ||
|
|
||
| const { model, stream } = props; | ||
| const streamAsBoolean = ( stream === "true" ? true : false ); | ||
|
|
||
| // Handler for getting completions from ollama and into the | ||
| // `sentenceCompletionsSignal` signal's value. | ||
| const getTelegraphicCompletions = async (event): Promise<void> => { | ||
| event.preventDefault(); | ||
| // Empty out the response area | ||
| sentenceCompletionsSignal.value = ["Working ..."]; | ||
|
|
||
| // Get the label texts from each symbol in `changeEncodingContents` | ||
| const labelText = []; | ||
| changeEncodingContents.value.payloads.forEach( (value) => { | ||
| labelText.push(value.label); | ||
| }); | ||
| const systemPrompt = (document.getElementById(TEXTAREA_ID) as HTMLTextAreaElement).value; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same concern about using
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In this case, I don't see what the Preact way is, exactly. The I'm leaving it as it is for now, but still thinking about it. |
||
| const response = await queryChat( | ||
| labelText.join(" "), model, streamAsBoolean, systemPrompt | ||
| ); | ||
| // Parse the query response messages into an array of strings. Note that | ||
| // with Llama3.1 each message is one of the suggested sentence completions. | ||
| // That might just be luck. | ||
| sentenceCompletionsSignal.value = response.message.content.split("\n"); | ||
| console.log(`getTelegraphicCompletions(), ${sentenceCompletionsSignal.value}`); | ||
| }; | ||
|
|
||
| // Handler to remove all of the suggested completions. | ||
| const removeSuggestions = (): void => { | ||
| sentenceCompletionsSignal.value = []; | ||
| }; | ||
|
|
||
| return html` | ||
| <p class="commandTelegraphicCompletions"> | ||
| <button onClick=${getTelegraphicCompletions}> | ||
| ${TELEGRPAHIC_BUTTON_LABEL} | ||
| </button> | ||
| <span style="visibility: hidden">F</span> | ||
|
||
| <button onClick=${removeSuggestions}> | ||
| ${CANCEL_BUTTON_LABEL} | ||
| </button> | ||
| </p> | ||
| `; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| /* | ||
| * Copyright 2025 Inclusive Design Research Centre, OCAD University | ||
| * All rights reserved. | ||
| * | ||
| * Licensed under the New BSD license. You may not use this file except in | ||
| * compliance with this License. | ||
| * | ||
| * You may obtain a copy of the License at | ||
| * https://github.com/inclusive-design/adaptive-palette/blob/main/LICENSE | ||
| */ | ||
|
|
||
| form.dialogPromptEntries { | ||
| display: inline-grid; | ||
| background:white; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The copyright can be up to 2026 now. :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
RIght.