Skip to content

Commit

Permalink
Merge branch 'main' into primitive-conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
vsbogd authored Nov 15, 2024
2 parents 7a6b1f0 + 988b716 commit 7cb77e1
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 32 deletions.
35 changes: 26 additions & 9 deletions lib/src/space/grounding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,16 +179,17 @@ impl GroundingSpace {

fn remove_internal(&mut self, atom: &Atom) -> bool {
let index_key = atom_to_trie_key(atom);
let indexes: Vec<usize> = self.index.get(&index_key).map(|i| *i).collect();
let mut indexes: Vec<usize> = indexes.into_iter()
.filter(|i| self.content[*i] == *atom).collect();
indexes.sort_by(|a, b| b.partial_cmp(a).unwrap());
let is_removed = indexes.len() > 0;
for i in indexes {
self.index.remove(&index_key, &i);
self.free.insert(i);
let index = self.index.get(&index_key)
.filter(|&&i| self.content[i] == *atom)
.next();
match index {
Some(&i) => {
self.index.remove(&index_key, &i);
self.free.insert(i);
true
},
None => false,
}
is_removed
}

/// Replaces `from` atom to `to` atom inside space. Doesn't add `to` when
Expand Down Expand Up @@ -431,6 +432,22 @@ mod test {
SpaceEvent::Remove(sym!("b"))]);
}

#[test]
fn remove_duplicated_atom() {
let mut space = GroundingSpace::new();
let observer = space.common.register_observer(SpaceEventCollector::new());

space.add(expr!("a"));
space.add(expr!("a"));
space.add(expr!("a"));
assert_eq!(space.remove(&expr!("a")), true);

assert_eq_no_order!(space, vec![expr!("a"), expr!("a")]);
assert_eq!(observer.borrow().events, vec![SpaceEvent::Add(sym!("a")),
SpaceEvent::Add(sym!("a")), SpaceEvent::Add(sym!("a")),
SpaceEvent::Remove(sym!("a"))]);
}

#[test]
fn remove_atom_not_found() {
let mut space = GroundingSpace::new();
Expand Down
28 changes: 11 additions & 17 deletions python/hyperon/exts/snet_io/snet_gate.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,13 @@ def init_sdk(self,
private_key=os.getenv("SNET_PRIVATE_KEY", '0' * 32),
eth_rpc_endpoint=os.getenv("ETH_RPC_ENDPOINT"),
email=os.getenv("SNET_EMAIL"),
identity_name="hyperon",
network="mainnet",
identity_type="key",
concurrency=False,
force_update=False):
config = {
"private_key": private_key,
"eth_rpc_endpoint": eth_rpc_endpoint,
"email": email,
"concurrency": concurrency,
"identity_name": identity_name,
"network": network,
"identity_type": identity_type,
"force_update": force_update
}
self.email = email
config = sdk.config.Config(private_key=private_key,
eth_rpc_endpoint=eth_rpc_endpoint,
concurrency=concurrency,
force_update=force_update)
self.snet_sdk = sdk.SnetSDK(config)

def organization_list(self):
Expand All @@ -45,6 +37,7 @@ def create_service_client(self, org_id, service_id,
service_client = self.snet_sdk.create_service_client(
org_id=org_id, service_id=service_id,
# group_name="default_group",
email=self.email,
free_call_auth_token_bin=free_call_auth_token_bin,
free_call_token_expiry_block=free_call_token_expiry_block)
return ServiceCall(service_client)
Expand Down Expand Up @@ -191,13 +184,14 @@ def get_service_messages(self):
def get_operation_atom(self):
return OperationAtom(self.service_details[1], self)

def generate_callers_text(self):
return pretty_print_atoms(self.generate_callers())

def open_channel_and_deposit(self, amount, expiration):
self.service_client.deposit_and_open_channel(amount, expiration)
return [E()]

def generate_callers_text(self):
# TODO: pretty print
return "\n".join([repr(e) for e in self.generate_callers()])

def _map_type(self, t):
type_map = {'bool': 'Bool',
'string': 'String',
Expand Down Expand Up @@ -241,4 +235,4 @@ def snet_atoms():
# TODO: new-sdk-atom
return {
'snet-sdk': defaultSDKAtom,
}
}
5 changes: 1 addition & 4 deletions python/hyperon/exts/snet_io/test_snet_call.metta
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,4 @@
(gen_gpt_2 "What was the largest dinosaur?" "universal" 0.5 2 100)

; possible usage of open_channel_and_deposit function. 100 is the amount of AGIX and 10000 is a payment channel's TTL in blocks
(snet-sdk open_channel_and_deposit &generative-lms 100 10000)

; usage of generate_callers_text method
((py-dot &generative-lms generate_callers_text))
(snet-sdk open_channel_and_deposit &generative-lms 100 10000)
3 changes: 1 addition & 2 deletions python/hyperon/exts/snet_io/test_snet_meta.metta
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,4 @@
; (naint punctuation-restoration) returns a service caller now
!((py-dot (naint punctuation-restoration) get_service_messages))
; we can also get a list of all service methods as typed metta functions
!(naint punctuation-restoration methods)

!(naint punctuation-restoration methods)

0 comments on commit 7cb77e1

Please sign in to comment.