-
Notifications
You must be signed in to change notification settings - Fork 211
[PARKED] feature: Image Description With AI #2791
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: develop
Are you sure you want to change the base?
Changes from 43 commits
ec91193
abde71f
304ead2
6458089
be50812
8edac42
4e3de86
6560f0e
e7f5f1a
0fbfee1
90fcdbc
38dec4c
4ff6dbd
d4e5f82
7a07406
fadd73b
71b33ba
30f1544
b67d3ab
66e2b15
4be6e2f
c27be39
44750fa
40fcf13
e16cea9
cac192b
bf0582d
f1e69fe
98cea84
4ba3dfe
8b700cd
94ed44d
553f023
9e61add
237d8dd
5169948
468a8f8
2742100
d2ac95f
8b6d2f2
b65d4bd
9bb1d3d
58c5527
e939e8c
89546cc
6d56d3a
205e132
830e05f
c8eac63
5e382fe
22ca998
7b7be88
1f01566
cb1d177
8e54507
155cf97
3ebd1a1
b78e981
eac8d0c
dc9b5d7
8c64220
ecf5a26
c67943f
4267641
18fd0b9
265ba4e
856ba13
efcb360
1fe25a2
f04886b
806a60d
83e3741
36bcb7a
cb0245e
a66b17e
4d97dc2
e786c21
07c188c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| // ==LICENSE-BEGIN== | ||
| // Copyright 2017 European Digital Reading Lab. All rights reserved. | ||
| // Licensed to the Readium Foundation under one or more contributor license agreements. | ||
| // Use of this source code is governed by a BSD-style license | ||
| // that can be found in the LICENSE file exposed on Github (readium) in the project repository. | ||
| // ==LICENSE-END== | ||
|
|
||
| export const DEFAULT_SYSTEM_PROMPT = "Your goal is to describe the image, you should not answer on a topic other than this image. Answer all requests in {{languages}} unless I explicitly ask you otherwise."; | ||
| const ADVANCED_SYSTEM_PROMPT = { | ||
| goal: "describe the image, you should not answer on a topic other than this image. Answer all requests in {{languages}} unless I explicitly ask you otherwise", | ||
| context: { | ||
| title: "{{title}}", | ||
| author: "{{author}}", | ||
| publisher: "{{publisher}}", | ||
| languages: "{{languages}}", | ||
| text_before: "{{beforeText}}", | ||
| text_after: "{{afterText}}", | ||
| }, | ||
| }; | ||
|
|
||
| const ADVANCED_SYSTEM_PROMPT_STRING = JSON.stringify(ADVANCED_SYSTEM_PROMPT); | ||
|
|
||
| export interface IaiSdkModel { id: string, name: string, systemPrompt: string }; | ||
| export const aiSDKModelOptions: Array<IaiSdkModel> = [ | ||
| { | ||
| id: "openai__!__gpt-4o-mini__!__default-prompt", | ||
| name: "openAI gpt-4o-mini (default)", | ||
| systemPrompt: DEFAULT_SYSTEM_PROMPT, | ||
| }, | ||
| { | ||
| id: "openai__!__gpt-4o-mini__!__specific-prompt", | ||
| name: "openAI gpt-4o-mini (advanced)", | ||
| systemPrompt: ADVANCED_SYSTEM_PROMPT_STRING, | ||
| }, | ||
| { | ||
| id: "mistralai__!__pixtral-12b-2409", | ||
| name: "mistralAI Pixtral 12B", | ||
| systemPrompt: DEFAULT_SYSTEM_PROMPT, | ||
| }, | ||
| ]; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| // ==LICENSE-BEGIN== | ||
| // Copyright 2017 European Digital Reading Lab. All rights reserved. | ||
| // Licensed to the Readium Foundation under one or more contributor license agreements. | ||
| // Use of this source code is governed by a BSD-style license | ||
| // that can be found in the LICENSE file exposed on Github (readium) in the project repository. | ||
| // ==LICENSE-END== | ||
|
|
||
| // import * as enable from "./enable"; | ||
| import * as set from "./setKey"; | ||
| import * as removeKey from "./removeKey"; | ||
|
|
||
| export { | ||
| set, | ||
| removeKey, | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| // ==LICENSE-BEGIN== | ||
| // Copyright 2017 European Digital Reading Lab. All rights reserved. | ||
| // Licensed to the Readium Foundation under one or more contributor license agreements. | ||
| // Use of this source code is governed by a BSD-style license | ||
| // that can be found in the LICENSE file exposed on Github (readium) in the project repository. | ||
| // ==LICENSE-END== | ||
|
|
||
| import { Action } from "readium-desktop/common/models/redux"; | ||
| import { IApiKey } from "../../states/api_key"; | ||
|
|
||
| export const ID = "API_KEY_REMOVE"; | ||
|
|
||
| // eslint-disable-next-line @typescript-eslint/no-empty-interface | ||
| // interface IPayload extends Pick<IAnnotationState, "uuid"> { | ||
| interface IPayload extends IApiKey { | ||
| } | ||
|
|
||
| export function build(param: IApiKey): | ||
|
||
| Action<typeof ID, IPayload> { | ||
|
|
||
| return { | ||
| type: ID, | ||
| payload: {...param}, | ||
| }; | ||
| } | ||
| build.toString = () => ID; | ||
| export type TAction = ReturnType<typeof build>; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| // ==LICENSE-BEGIN== | ||
| // Copyright 2017 European Digital Reading Lab. All rights reserved. | ||
| // Licensed to the Readium Foundation under one or more contributor license agreements. | ||
| // Use of this source code is governed by a BSD-style license | ||
| // that can be found in the LICENSE file exposed on Github (readium) in the project repository. | ||
| // ==LICENSE-END== | ||
|
|
||
| import { Action } from "readium-desktop/common/models/redux"; | ||
| import { IApiKey } from "../../states/api_key"; | ||
|
|
||
| export const ID = "API_KEY_SET"; | ||
|
|
||
| export interface Payload extends IApiKey { | ||
| } | ||
|
|
||
| export function build(key: string, provider: string, submitted: boolean): Action<typeof ID, Payload> { | ||
arthur-lemeur marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| return { | ||
| type: ID, | ||
| payload: { | ||
| key, | ||
| provider, | ||
| submitted, | ||
| }, | ||
| }; | ||
| } | ||
| build.toString = () => ID; | ||
| export type TAction = ReturnType<typeof build>; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,6 +28,7 @@ import * as versionUpdateActions from "./version-update"; | |
| import * as annotationActions from "./annotation"; | ||
| import * as creatorActions from "./creator"; | ||
| import * as settingsActions from "./settings"; | ||
| import * as apiKeysActions from "./api_key"; | ||
|
||
|
|
||
| export { | ||
| historyActions, | ||
|
|
@@ -53,4 +54,5 @@ export { | |
| annotationActions, | ||
| creatorActions, | ||
| settingsActions, | ||
| apiKeysActions, | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| // ==LICENSE-BEGIN== | ||
| // Copyright 2017 European Digital Reading Lab. All rights reserved. | ||
| // Licensed to the Readium Foundation under one or more contributor license agreements. | ||
| // Use of this source code is governed by a BSD-style license | ||
| // that can be found in the LICENSE file exposed on Github (readium) in the project repository. | ||
| // ==LICENSE-END== | ||
|
|
||
| import { type Reducer } from "redux"; | ||
|
|
||
| import { apiKeysActions } from "../actions"; | ||
| import { IApiKeysArray } from "../states/api_key"; | ||
|
|
||
| const initialState: IApiKeysArray = []; | ||
|
|
||
| function apiKeysReducer_( | ||
| state = initialState, | ||
| action: apiKeysActions.set.TAction | apiKeysActions.removeKey.TAction, | ||
| ): IApiKeysArray { | ||
|
|
||
| switch (action.type) { | ||
| case apiKeysActions.set.ID: | ||
|
||
| return [ | ||
| ...state, | ||
| { | ||
| provider: action.payload.provider, | ||
| key: action.payload.key, | ||
| submitted: action.payload.submitted, | ||
| }, | ||
| ]; | ||
| case apiKeysActions.removeKey.ID: | ||
| return state.filter( | ||
| key => key.provider !== action.payload.provider || key.key !== action.payload.key, | ||
|
||
| ); | ||
| default: | ||
| return state; | ||
| } | ||
| } | ||
|
|
||
|
|
||
| export const apiKeysReducer = apiKeysReducer_ as Reducer<ReturnType<typeof apiKeysReducer_>>; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| // ==LICENSE-BEGIN== | ||
| // Copyright 2017 European Digital Reading Lab. All rights reserved. | ||
| // Licensed to the Readium Foundation under one or more contributor license agreements. | ||
| // Use of this source code is governed by a BSD-style license | ||
| // that can be found in the LICENSE file exposed on Github (readium) in the project repository. | ||
| // ==LICENSE-END== | ||
|
|
||
| export interface IApiKey { | ||
| key: string, | ||
| provider: string, | ||
arthur-lemeur marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| submitted: boolean, | ||
arthur-lemeur marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| export type IApiKeysArray = IApiKey[] | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -44,6 +44,7 @@ export const reduxPersistMiddleware: Middleware | |
| settings: prevState.settings, | ||
| creator: prevState.creator, | ||
| annotationImportQueue: prevState.annotationImportQueue, | ||
| apiKeys: prevState.apiKeys, | ||
|
||
| }; | ||
|
|
||
| const persistNextState: PersistRootState = { | ||
|
|
@@ -64,6 +65,7 @@ export const reduxPersistMiddleware: Middleware | |
| settings: nextState.settings, | ||
| creator: nextState.creator, | ||
| annotationImportQueue: nextState.annotationImportQueue, | ||
| apiKeys: nextState.apiKeys, | ||
| }; | ||
|
|
||
| // RangeError: Maximum call stack size exceeded | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.