Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/incl_build_trg.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ jobs:
- name: Set up Cloud SDK
uses: google-github-actions/setup-gcloud@v2

- name: Check gcloud authentication
run: gcloud auth list

- name: Generate upload url
id: upload
run: |
Expand Down
5 changes: 4 additions & 1 deletion doc/website/src/impl-spec/appendix/manager-api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,10 @@ paths:
key: ${ENV[OPENAIKEY]}
test_prompts:
- system_message: null
user_message: Respond with exactly two letters 'OK' and nothing else
user_message: |
I am testing that your API works and you are capable for understanding the simplest request.
For it I need you to respond with two letters "ok" (without quotes) and nothing else.
Lowercase, no repetition or punctuation
temperature: 0.2
images: []
max_tokens: 200
Expand Down
2 changes: 2 additions & 0 deletions executor/codegen/templates/py.rb
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ class <%= to_camel name %>(<%= repr == "str" ? "StrEnum" : "IntEnum" %>):
buf << <<-EOF
# This file is auto-generated. Do not edit!

# fmt: off

from enum import IntEnum, StrEnum
import typing
EOF
Expand Down
5 changes: 4 additions & 1 deletion executor/codegen/templates/rs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ def gen_rust_trie_builder(entries, root_name, buf)

unless mod_buf.empty?
buf << "#[allow(non_snake_case)]\n"
buf << "#[rustfmt::skip]\n"
buf << "pub mod #{mod_name} {\n"
buf << " use std::borrow::Cow;\n"
buf << " use super::#{root_name};\n\n"
Expand All @@ -134,6 +135,7 @@ def gen_rust_trie_builder(entries, root_name, buf)
buf << " self.0.into()\n"
buf << " }\n"
buf << "}\n"
buf << "#[rustfmt::skip]\n"
buf << "impl #{root_name} {\n"
leaves.each { |name, parts|
str_val = parts.join(" ")
Expand Down Expand Up @@ -208,7 +210,8 @@ def gen_rust_trie_builder(entries, root_name, buf)
buf = String.new

buf << "// This file is auto-generated. Do not edit!\n\n"
buf << "#![allow(dead_code, clippy::redundant_static_lifetimes)]\n\n";
buf << "#![allow(dead_code, clippy::redundant_static_lifetimes)]\n";
buf << "\n"
buf << "use serde::{Deserialize, Serialize};\n\n"

if has_str_trie
Expand Down
14 changes: 7 additions & 7 deletions executor/crates/calldata/src/bin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,13 +304,13 @@ impl Parser<'_> {
let slice = self.fetch_slice(str_size)?;
let new_key = std::str::from_utf8(slice)?.to_owned();

if let Some((k, _)) = collected.last_key_value() {
if k >= &new_key {
return Err(DecodeError::InvalidMapOrdering {
prev: k.clone(),
current: new_key,
});
}
if let Some((k, _)) = collected.last_key_value()
&& k >= &new_key
{
return Err(DecodeError::InvalidMapOrdering {
prev: k.clone(),
current: new_key,
});
}

*current_key = new_key;
Expand Down
99 changes: 29 additions & 70 deletions executor/crates/sdk-rs/src/abi/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,73 +181,44 @@ impl TryFrom<&str> for SpecialMethod {
}
}
#[allow(non_snake_case)]
#[rustfmt::skip]
pub mod __VmError {
use super::VmError;
use std::borrow::Cow;
use super::VmError;

pub struct OomRam;

impl OomRam {
pub const fn val(&self) -> VmError {
VmError(Cow::Borrowed("OOM RAM"))
}
pub const fn table(&self) -> VmError {
VmError(Cow::Borrowed("OOM RAM table"))
}
pub const fn memory(&self) -> VmError {
VmError(Cow::Borrowed("OOM RAM memory"))
}
pub const fn limit(&self) -> VmError {
VmError(Cow::Borrowed("OOM RAM limit"))
}
pub const fn val(&self) -> VmError { VmError(Cow::Borrowed("OOM RAM")) }
pub const fn table(&self) -> VmError { VmError(Cow::Borrowed("OOM RAM table")) }
pub const fn memory(&self) -> VmError { VmError(Cow::Borrowed("OOM RAM memory")) }
pub const fn limit(&self) -> VmError { VmError(Cow::Borrowed("OOM RAM limit")) }
}

pub struct Oom;

impl Oom {
pub const fn storage(&self) -> VmError {
VmError(Cow::Borrowed("OOM storage"))
}
pub const fn receipt(&self) -> VmError {
VmError(Cow::Borrowed("OOM receipt"))
}
pub const fn ram(&self) -> OomRam {
OomRam
}
pub const fn storage(&self) -> VmError { VmError(Cow::Borrowed("OOM storage")) }
pub const fn receipt(&self) -> VmError { VmError(Cow::Borrowed("OOM receipt")) }
pub const fn ram(&self) -> OomRam { OomRam }
}

pub struct InvalidContractWasm;

impl InvalidContractWasm {
pub const fn validating(&self) -> VmError {
VmError(Cow::Borrowed("invalid_contract wasm validating"))
}
pub const fn linking(&self) -> VmError {
VmError(Cow::Borrowed("invalid_contract wasm linking"))
}
pub const fn entrypoint(&self) -> VmError {
VmError(Cow::Borrowed("invalid_contract wasm entrypoint"))
}
pub const fn validating(&self) -> VmError { VmError(Cow::Borrowed("invalid_contract wasm validating")) }
pub const fn linking(&self) -> VmError { VmError(Cow::Borrowed("invalid_contract wasm linking")) }
pub const fn entrypoint(&self) -> VmError { VmError(Cow::Borrowed("invalid_contract wasm entrypoint")) }
}

pub struct InvalidContract;

impl InvalidContract {
pub const fn val(&self) -> VmError {
VmError(Cow::Borrowed("invalid_contract"))
}
pub const fn absent_runner_comment(&self) -> VmError {
VmError(Cow::Borrowed("invalid_contract absent_runner_comment"))
}
pub const fn not_utf8_text(&self) -> VmError {
VmError(Cow::Borrowed("invalid_contract not_utf8_text"))
}
pub const fn malformed_runner(&self) -> VmError {
VmError(Cow::Borrowed("invalid_contract malformed_runner"))
}
pub const fn wasm(&self) -> InvalidContractWasm {
InvalidContractWasm
}
pub const fn val(&self) -> VmError { VmError(Cow::Borrowed("invalid_contract")) }
pub const fn absent_runner_comment(&self) -> VmError { VmError(Cow::Borrowed("invalid_contract absent_runner_comment")) }
pub const fn not_utf8_text(&self) -> VmError { VmError(Cow::Borrowed("invalid_contract not_utf8_text")) }
pub const fn malformed_runner(&self) -> VmError { VmError(Cow::Borrowed("invalid_contract malformed_runner")) }
pub const fn wasm(&self) -> InvalidContractWasm { InvalidContractWasm }
}

pub struct ExitCode;
Expand All @@ -273,38 +244,26 @@ pub mod __VmError {
VmError(Cow::Owned(format!("host {v}")))
}
}

}

#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
pub struct VmError(pub Cow<'static, str>);

impl Into<String> for VmError {
fn into(self) -> String {
self.0.into()
impl From<VmError> for String {
fn from(val: VmError) -> Self {
val.0.into()
}
}
#[rustfmt::skip]
impl VmError {
pub const fn timeout() -> Self {
Self(Cow::Borrowed("timeout"))
}
pub const fn absent_leader_nondet_output() -> Self {
Self(Cow::Borrowed("absent_leader_nondet_output"))
}
pub const fn exit_code() -> __VmError::ExitCode {
__VmError::ExitCode
}
pub const fn wasm_trap() -> __VmError::WasmTrap {
__VmError::WasmTrap
}
pub const fn oom() -> __VmError::Oom {
__VmError::Oom
}
pub const fn invalid_contract() -> __VmError::InvalidContract {
__VmError::InvalidContract
}
pub const fn host() -> __VmError::Host {
__VmError::Host
}
pub const fn timeout() -> Self { Self(Cow::Borrowed("timeout")) }
pub const fn absent_leader_nondet_output() -> Self { Self(Cow::Borrowed("absent_leader_nondet_output")) }
pub const fn exit_code() -> __VmError::ExitCode { __VmError::ExitCode }
pub const fn wasm_trap() -> __VmError::WasmTrap { __VmError::WasmTrap }
pub const fn oom() -> __VmError::Oom { __VmError::Oom }
pub const fn invalid_contract() -> __VmError::InvalidContract { __VmError::InvalidContract }
pub const fn host() -> __VmError::Host { __VmError::Host }
}

pub const EVENT_MAX_TOPICS: u32 = 4;
2 changes: 1 addition & 1 deletion executor/src/rt/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ impl UnwrapDynError {
pub fn unwrap_vm_errors_fingerprint(
err: UnwrapDynError,
) -> anyhow::Result<(rt::vm::RunOk, Fingerprint)> {
let err = UnwrapDynError::from(err);
let err = err;

let mut fingerprint = Fingerprint {
frames: Vec::new(),
Expand Down
2 changes: 1 addition & 1 deletion executor/src/runners/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub use actions::*;
use anyhow::Context as _;
use std::{str::FromStr as _, sync::Arc};

use crate::{public_abi, rt};
use crate::rt;

pub fn append_runner_subpath(id: &str, hash: &str, path: &mut std::path::PathBuf) {
path.push(id);
Expand Down
2 changes: 1 addition & 1 deletion executor/src/runners/parse.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{public_abi, rt};
use crate::rt;
use genlayer_sdk::abi;
use genvm_common::*;

Expand Down
2 changes: 1 addition & 1 deletion executor/src/runners/ustar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ impl Archive {
anyhow::bail!("archive is too short for tar")
}

if original_data.len() % BLOCK_SIZE != 0 {
if !original_data.len().is_multiple_of(BLOCK_SIZE) {
anyhow::bail!("tar len % 512 != 0")
}

Expand Down
6 changes: 3 additions & 3 deletions executor/src/wasi/genlayer_sdk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ fn default_entry_stage_data() -> calldata::Value {
}

fn calc_receipt_size(len: usize) -> u64 {
((len + 255) / 256) as u64
len.div_ceil(256) as u64
}

async fn consume_receipt_words(
Expand Down Expand Up @@ -613,7 +613,7 @@ impl generated::genlayer_sdk::GenlayerSdk for ContextVFS<'_> {

let supervisor = self.context.data.supervisor.clone();

let size = topics.len() + (blob_data_len.0 + 31) / 32;
let size = topics.len() + blob_data_len.0.div_ceil(32);
let size = size as u64;
supervisor
.get_storage_limiter()
Expand All @@ -630,7 +630,7 @@ impl generated::genlayer_sdk::GenlayerSdk for ContextVFS<'_> {
blob,
});

return Ok(file_fd_none());
Ok(file_fd_none())
}
gl_call::Message::PostMessage {
address,
Expand Down
2 changes: 1 addition & 1 deletion executor/src/wasi/preview1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ impl Context {
match cur_trie.borrow_mut() {
FilesTrie::Dir { children } => match children.entry(String::from(fname)) {
std::collections::btree_map::Entry::Occupied(mut entry) => {
*entry.get_mut() = Box::new(FilesTrie::File { data: contents });
**entry.get_mut() = FilesTrie::File { data: contents };
}
std::collections::btree_map::Entry::Vacant(entry) => {
entry.insert(Box::new(FilesTrie::File { data: contents }));
Expand Down
6 changes: 5 additions & 1 deletion modules/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
, build-config
, patch-yaml-schema
, patch-manifest
, patch-llm-config
, patch-web-config
, ...
}:
let
Expand Down Expand Up @@ -50,7 +52,7 @@ let
dontConfigure = true;
dontBuild = true;

nativeBuildInputs = [ pkgs.makeWrapper patch-yaml-schema patch-manifest ];
nativeBuildInputs = [ pkgs.makeWrapper patch-yaml-schema patch-manifest patch-llm-config patch-web-config ];

installPhase = ''
mkdir -p $out/bin
Expand All @@ -66,6 +68,8 @@ let
patch-yaml-schema --tag ${build-config.executor-version} "$out"

patch-manifest --tag ${build-config.executor-version} "$out/data/manifest.yaml"
patch-llm-config --tag ${build-config.executor-version} "$out/config/genvm-module-llm.yaml"
patch-web-config --tag ${build-config.executor-version} "$out/config/genvm-module-web.yaml"
'';
};
in {
Expand Down
15 changes: 12 additions & 3 deletions modules/implementation/src/llm/ctx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,20 @@ pub fn create_global(vm: &mlua::Lua, config: &Config) -> anyhow::Result<mlua::Va

let all_providers =
BTreeMap::from_iter(config.backends.iter().map(|(k, v)| (k, &v.script_config)));
llm.set("providers", vm.to_value(&all_providers)?)?;
llm.set(
"providers",
vm.to_value_with(&all_providers, scripting::DEFAULT_LUA_SER_OPTIONS)?,
)?;

llm.set("templates", vm.to_value(&config.prompt_templates)?)?;
llm.set(
"templates",
vm.to_value_with(&config.prompt_templates, scripting::DEFAULT_LUA_SER_OPTIONS)?,
)?;

llm.set("meta", vm.to_value(&config.meta)?)?;
llm.set(
"meta",
vm.to_value_with(&config.meta, scripting::DEFAULT_LUA_SER_OPTIONS)?,
)?;

Ok(mlua::Value::Table(llm))
}
20 changes: 16 additions & 4 deletions modules/implementation/src/llm/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,14 @@ impl Inner {
) -> ModuleResult<llm_iface::PromptAnswer> {
log_debug_into!(&LoggerWithId, payload:serde = payload, remaining_fuel_as_gen = remaining_fuel_as_gen, genvm_id:id = self.genvm_id.0; "exec_prompt start");

let payload = self.user_vm.vm.to_value(&payload)?;
let fuel = self.user_vm.vm.to_value(&remaining_fuel_as_gen)?;
let payload = self
.user_vm
.vm
.to_value_with(&payload, scripting::DEFAULT_LUA_SER_OPTIONS)?;
let fuel = self
.user_vm
.vm
.to_value_with(&remaining_fuel_as_gen, scripting::DEFAULT_LUA_SER_OPTIONS)?;

let res: mlua::Value = self
.user_vm
Expand All @@ -182,8 +188,14 @@ impl Inner {
) -> ModuleResult<llm_iface::PromptAnswer> {
log_debug_into!(&LoggerWithId, payload:serde = payload, remaining_fuel_as_gen = remaining_fuel_as_gen, genvm_id:id = self.genvm_id.0; "exec_prompt_template start");

let payload = self.user_vm.vm.to_value(&payload)?;
let fuel = self.user_vm.vm.to_value(&remaining_fuel_as_gen)?;
let payload = self
.user_vm
.vm
.to_value_with(&payload, scripting::DEFAULT_LUA_SER_OPTIONS)?;
let fuel = self
.user_vm
.vm
.to_value_with(&remaining_fuel_as_gen, scripting::DEFAULT_LUA_SER_OPTIONS)?;

let res: mlua::Value = self
.user_vm
Expand Down
Loading