Skip to content

Commit

Permalink
Merge branch 'feat/ml-experementa' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
dasein108 committed Jun 30, 2024
2 parents 9632275 + 9ea833d commit 342ca1c
Show file tree
Hide file tree
Showing 28 changed files with 499 additions and 297 deletions.
7 changes: 5 additions & 2 deletions docs/scripting.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,14 @@ cyb::search_by_embedding(text:string, count: int) -> string[];

#### Experemental

OpenAI promts(beta, in developement)
OpenAI promts(beta)

- api key should be added using cyb-keys
- this is wrapper around [openai api](https://platform.openai.com/docs/api-reference/chat/create)

```
// Apply prompt OpenAI and get result
cyb::open_ai_prompt(prompt: string; params: json) -> string;
cyb::open_ai_completions(messages: object[]; apiKey: string; params: json) -> string | AsyncIterable<string>;
```

#### Debug
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@
"core-js": "^3.30.0",
"crypto": "^1.0.1",
"cyb-cozo-lib-wasm": "^0.7.145",
"cyb-rune-wasm": "^0.0.82",
"cyb-rune-wasm": "^0.0.841",
"datastore-core": "^9.2.3",
"datastore-idb": "^2.1.4",
"dateformat": "^3.0.3",
Expand Down Expand Up @@ -254,7 +254,6 @@
"tone": "^14.7.77",
"ts-jest": "^29.1.1",
"ts-jest-resolver": "^2.0.1",
"typeit-react": "^2.7.1",
"videostream": "^3.2.2",
"web3": "1.2.4",
"web3-utils": "^4.2.1",
Expand Down
23 changes: 16 additions & 7 deletions src/components/ledger/stageActionBar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { ActionBar, Pane, Text } from '@cybercongress/gravity';
import { BondStatus } from 'cosmjs-types/cosmos/staking/v1beta1/staking';
import { useBackend } from 'src/contexts/backend/backend';
import { CHAIN_ID, BASE_DENOM } from 'src/constants/config';
import { KEY_TYPE } from 'src/pages/Keys/types';

import { ContainetLedger } from './container';
import { Dots } from '../ui/Dots';
import Account from '../account/account';
Expand All @@ -22,6 +24,7 @@ import AddFileButton from '../buttons/AddFile/AddFile';

const imgKeplr = require('../../image/keplr-icon.svg');
const imgRead = require('../../image/duplicate-outline.svg');
const imgSecrets = require('../../image/secrets.svg');

const T = new LocalizedStrings(i18n);

Expand Down Expand Up @@ -405,24 +408,24 @@ export function ConnectAddress({
selectMethodFunc,
selectMethod,
selectNetwork,
connctAddress,
connectAddress,
keplr,
onClickBack,
}) {
return (
<ActionBarContainer
button={{
disabled: !selectNetwork || !selectMethod,
text: 'Connect',
onClick: connctAddress,
text: selectMethod === KEY_TYPE.secrets ? 'Add' : 'Connect',
onClick: connectAddress,
}}
onClickBack={onClickBack}
>
<Pane display="flex" alignItems="center" justifyContent="center" flex={1}>
{keplr ? (
<ButtonIcon
onClick={() => selectMethodFunc('keplr')}
active={selectMethod === 'keplr'}
onClick={() => selectMethodFunc(KEY_TYPE.keplr)}
active={selectMethod === KEY_TYPE.keplr}
img={imgKeplr}
text="keplr"
/>
Expand All @@ -439,11 +442,17 @@ export function ConnectAddress({
)}

<ButtonIcon
onClick={() => selectMethodFunc('read-only')}
active={selectMethod === 'read-only'}
onClick={() => selectMethodFunc(KEY_TYPE.readOnly)}
active={selectMethod === KEY_TYPE.readOnly}
img={imgRead}
text="read-only"
/>
<ButtonIcon
onClick={() => selectMethodFunc(KEY_TYPE.secrets)}
active={selectMethod === KEY_TYPE.secrets}
img={imgSecrets}
text="secrets"
/>
</Pane>
<span style={{ fontSize: '18px' }}>in</span>
<Pane display="flex" alignItems="center" justifyContent="center" flex={1}>
Expand Down
34 changes: 18 additions & 16 deletions src/containers/ipfs/components/SoulCompanion/SoulCompanion.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function SoulCompanion({
if (details.type && details.type !== 'text' && details.text) {
setStatus('done');
setMetaItems([
{ type: 'text', text: `Skip companion for '${details.content}'.` },
[{ type: 'text', text: `Skip companion for '${details.content}'.` }],
]);
return;
}
Expand Down Expand Up @@ -65,21 +65,23 @@ function SoulCompanion({
);
}
return (
<div>
<ul className={styles.itemLinks}>
{metaItems.map((item, index) => (
<li key={`soul_comp_${index}`}>
{item.type === 'text' && (
<p className={styles.itemText}>{item.text}</p>
)}
{item.type === 'link' && (
<Link className={styles.itemLink} to={item.url}>
{shortenString(item.title, 64)}
</Link>
)}
</li>
))}
</ul>
<div className={styles.soulCompanion}>
{metaItems.map((row, index) => (
<ul className={styles.itemLinks} key={`soul_comp_row_${index}`}>
{row.map((item, index) => (
<li key={`soul_comp_col_${index}`}>
{item.type === 'text' && (
<p className={styles.itemText}>{item.text}</p>
)}
{item.type === 'link' && (
<Link className={styles.itemLink} to={item.url}>
{shortenString(item.title, 64)}
</Link>
)}
</li>
))}
</ul>
))}
</div>
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
.itemLinks {
display: flex;
margin: -10px 0;

list-style-type: none;
font-size: 14px;
}

.soulCompanion {
margin: -10px 0;
}

.itemText {
font-size: 14px;
display: block;
Expand Down
42 changes: 27 additions & 15 deletions src/contexts/scripting/scripting.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,17 @@ function ScriptingProvider({ children }: { children: React.ReactNode }) {
const dispatch = useAppDispatch();

useEffect(() => {
runeBackend.pushContext('secrets', secrets);

const setupObservervable = async () => {
const { isSoulInitialized$ } = runeBackend;

const soulSubscription = (await isSoulInitialized$).subscribe((v) => {
setIsSoulInitialized(!!v);
if (v) {
runeRef.current = runeBackend;
console.log('👻 soul initalized');
}
setIsSoulInitialized(!!v);
});

const embeddingApiSubscription = (await embeddingApi$).subscribe(
Expand All @@ -72,28 +74,38 @@ function ScriptingProvider({ children }: { children: React.ReactNode }) {
};

setupObservervable();
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

const runeEntryPoints = useAppSelector(selectRuneEntypoints);

const citizenship = useAppSelector(selectCurrentPassport);
const secrets = useAppSelector((state) => state.scripting.context.secrets);

useEffect(() => {
(async () => {
if (citizenship) {
const particleCid = citizenship.extension.particle;
if (!isSoulInitialized || !runeRef.current) {
return;
}

if (citizenship) {
const particleCid = citizenship.extension.particle;

runeRef.current.pushContext('user', {
address: citizenship.owner,
nickname: citizenship.extension.nickname,
citizenship,
particle: particleCid,
} as UserContext);
} else {
runeRef.current.popContext(['user']);
}
}, [citizenship, isSoulInitialized]);

await runeBackend.pushContext('user', {
address: citizenship.owner,
nickname: citizenship.extension.nickname,
citizenship,
particle: particleCid,
} as UserContext);
} else {
await runeBackend.popContext(['user', 'secrets']);
}
})();
}, [citizenship, runeBackend]);
useEffect(() => {
if (isSoulInitialized && runeRef.current) {
runeRef.current.pushContext('secrets', secrets);
}
}, [secrets, isSoulInitialized]);

useEffect(() => {
(async () => {
Expand Down
2 changes: 1 addition & 1 deletion src/features/ipfs/Drive/BackendStatus.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { downloadJson } from 'src/utils/json';
import { useBackend } from 'src/contexts/backend/backend';
import { EmbeddinsDbEntity } from 'src/services/CozoDb/types/entities';
import { isObject } from 'lodash';
import { promptToOpenAI } from 'src/services/scripting/services/llmRequests/openai';
import { openAICompletion } from 'src/services/scripting/services/llmRequests/openai';

const getProgressTrackingInfo = (progress?: ProgressTracking) => {
if (!progress) {
Expand Down
1 change: 1 addition & 0 deletions src/image/secrets.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 4 additions & 3 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ import HubProvider from './contexts/hub';

import { INDEX_HTTPS, INDEX_WEBSOCKET } from './constants/config';
import ScriptingProvider from './contexts/scripting/scripting';
import ErrorBoundary from './components/ErrorBoundary/ErrorBoundary';

const httpLink = new HttpLink({
uri: INDEX_HTTPS,
Expand Down Expand Up @@ -100,7 +99,8 @@ if (container === null) {

const root = createRoot(container);

function Providers({ children }: { children: React.ReactNode }) {
// for Storybook, WIP
export function Providers({ children }: { children: React.ReactNode }) {
return (
<Provider store={store}>
<NetworksProvider>
Expand All @@ -116,7 +116,8 @@ function Providers({ children }: { children: React.ReactNode }) {
<ScriptingProvider>
<DeviceProvider>
<AdviserProvider>
<ErrorBoundary>{children}</ErrorBoundary>
{/* <ErrorBoundary>{children}</ErrorBoundary> */}
{children}
</AdviserProvider>
</DeviceProvider>
</ScriptingProvider>
Expand Down
Loading

0 comments on commit 342ca1c

Please sign in to comment.