0xdc28…f289

All memos sent from and to 0xdc28…f289.

;# { # "Seq": [ # { "Depends": "py-lib-genlayermodelwrappers:test" }, # { "Depends": "py-genlayer:test" } # ] # } import numpy as np from genlayer import * import genlayermodelwrappers from dataclasses import dataclass import typing @allow_storage @dataclass class StoreValue: log_id: u256 text: str # contract class class LogIndexer(gl.Contract): vector_store: VecDB[np.float32, typing.Literal[384], StoreValue] def __init__(self): pass def get_embedding_generator(self): return genlayermodelwrappers.SentenceTransformer("all-MiniLM-L6-v2") def get_embedding( self, txt: str ) -> np.ndarray[tuple[typing.Literal[384]], np.dtypes.Float32DType]: return self.get_embedding_generator()(txt) @gl.public.view def get_closest_vector(self, text: str) -> dict | None: emb = self.get_embedding(text) result = list(self.vector_store.knn(emb, 1)) if len(result) == 0: return None result = result[0] return { "vector": list(str(x) for x in result.key), "similarity": str(1 - result.distance), "id": result.value.log_id, "text": result.value.text, } @gl.public.write def add_log(self, log: str, log_id: int) -> None: emb = self.get_embedding(log) self.vector_store.insert(emb, StoreValue(text=log, log_id=u256(log_id))) @gl.public.write def update_log(self, log_id: int, log: str) -> None: emb = self.get_embedding(log) for elem in self.vector_store.knn(emb, 2): if elem.value.text == log: elem.value.log_id = u256(log_id) @gl.public.write def remove_log(self, id: int) -> None: for el in self.vector_store: if el.value.log_id == id: el.remove()
# { "Depends": "py-genlayer:test" } from genlayer import * import json import typing class PredictionMarket(gl.Contract): has_resolved: bool team1: str team2: str resolution_url: str winner: u256 score: str def __init__(self, game_date: str, team1: str, team2: str): """ Initializes a new instance of the prediction market with the specified game date and teams. Args: game_date (str): The date of the game in the format 'YYYY-MM-DD'. team1 (str): The name of the first team. team2 (str): The name of the second team. Attributes: has_resolved (bool): Indicates whether the game's resolution has been processed. Default is False. game_date (str): The date of the game. resolution_url (str): The URL to the game's resolution on BBC Sport. team1 (str): The name of the first team. team2 (str): The name of the second team. """ self.has_resolved = False self.resolution_url = ( "https://www.bbc.com/sport/football/scores-fixtures/" + game_date ) self.team1 = team1 self.team2 = team2 self.winner = 0 self.score = "" @gl.public.write def resolve(self) -> typing.Any: if self.has_resolved: return "Already resolved" market_resolution_url = self.resolution_url team1 = self.team1 team2 = self.team2 def get_match_result() -> str: web_data = gl.get_webpage(market_resolution_url, mode="text") print(web_data) task = f""" In the following web page, find the winning team in a matchup between the following teams: Team 1: {team1} Team 2: {team2} Web page content: {web_data} End of web page data. If it says "Kick off [time]" between the names of the two teams, it means the game hasn't started yet. If you fail to extract the score, assume the game is not resolved yet. Respond with the following JSON format: {{ "score": str, // The score with numbers only, e.g, "1:2", or "-" if the game is not resolved yet "winner": int, // The number of the winning team, 0 for draw, or -1 if the game is not yet finished }} It is mandatory that you respond only using the JSON format above, nothing else. Don't include any other words or characters, your output must be only JSON without any formatting prefix or suffix. This result should be perfectly parsable by a JSON parser without errors. """ result = gl.exec_prompt(task).replace("```json", "").replace("```", "") print(result) return json.dumps(json.loads(result), sort_keys=True) result_json = json.loads(gl.eq_principle_strict_eq(get_match_result)) if result_json["winner"] > -1: self.has_resolved = True self.winner = result_json["winner"] self.score = result_json["score"] return result_json @gl.public.view def get_resolution_data(self) -> dict[str, typing.Any]: return { "winner": self.winner, "score": self.score, "has_resolved": self.has_resolved, }
A# { "Depends": "py-genlayer:test" } # Always put above line as first in the contract file # Upon release it will be changed from `:test` to `:<hash>` and library will be frozen forever # this imports all types into globals and `genlayer.std` as `gl` (will be imported lazily on first access) from genlayer import * # extend `gl.Contract` to mark class as a contract. There can be only one class that extends `gl.Contract` class Storage(gl.Contract): # below you must declare all class fields that you are going to use # this fields persist between contract calls storage_str: str storage_int: u256 # NOTE: `int`s are intentionally not supported! in future `bigint` int alias will be introduced # all public methods must have type annotations to be user friendly # constructor, must not be public def __init__(self, initial_str_storage: str): self.storage_str = initial_str_storage # methods that don't modify anything must be annotated with view @gl.public.view def get_storage(self) -> str: return self.storage_str # keyword arguments are supported as well, however, they should not be mixed with positional, # in python terms it means that function has following signature (note `/`) # def debug(self, x: int, /, *, flag: bool) -> str: @gl.public.view def debug(self, x: int, *, flag: bool) -> None: # you can use prints for debugging (even in write methods and non deterministic blocks) # however, stdout doesn't go through consensus and is meant for debug use only # it also may be absent in the actual node print(f"debug: {self.storage_int}, {x}, {flag}") # methods that modify storage must be annotated with write @gl.public.write def update_storage(self, new_storage: str) -> None: self.storage_str = new_storage