From 4221f35c9bf2385d40926016df5421aef4b5c4f2 Mon Sep 17 00:00:00 2001 From: meloalright Date: Mon, 8 Apr 2024 23:57:05 +0800 Subject: [PATCH] Make sophon a feature in three body intepreter --- .github/workflows/Sophon.yml | 2 +- Cargo.toml | 2 +- interpreter/Cargo.toml | 10 +++++++--- interpreter/src/evaluator/builtins.rs | 6 ++++++ interpreter/src/evaluator/object.rs | 2 ++ 5 files changed, 17 insertions(+), 5 deletions(-) diff --git a/.github/workflows/Sophon.yml b/.github/workflows/Sophon.yml index 8db08e5..303bc23 100644 --- a/.github/workflows/Sophon.yml +++ b/.github/workflows/Sophon.yml @@ -9,7 +9,7 @@ on: - main jobs: - build: + reasoning: runs-on: ubuntu-latest steps: diff --git a/Cargo.toml b/Cargo.toml index 3ad4813..c7b61ab 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,7 +12,7 @@ members = ["interpreter"] [dependencies] rustyline = { version = "12.0.0", optional = true } rustyline-derive = { version = "0.4.0", optional = true } -three_body_interpreter = { version = "0.4.5", path = "./interpreter" } +three_body_interpreter = { version = "0.4.5", path = "./interpreter", features = ["sophon"] } [[bin]] name = "3body" diff --git a/interpreter/Cargo.toml b/interpreter/Cargo.toml index 4cde771..eaf9344 100644 --- a/interpreter/Cargo.toml +++ b/interpreter/Cargo.toml @@ -14,6 +14,10 @@ unicode-xid = { version = "0.2.1" } [target.'cfg(not(target_arch = "wasm32"))'.dependencies] rand = { version = "0.8.5" } -llm = { version = "0.1.1" } -llm-base = { version = "0.1.1" } -spinoff = { version = "0.7.0", default-features = false, features = ["dots", "arc", "line"] } +llm = { version = "0.1.1", optional = true } +llm-base = { version = "0.1.1", optional = true } +spinoff = { version = "0.7.0", default-features = false, features = ["dots", "arc", "line"], optional = true } + +[features] +default = [] +sophon = ["llm", "llm-base", "spinoff"] \ No newline at end of file diff --git a/interpreter/src/evaluator/builtins.rs b/interpreter/src/evaluator/builtins.rs index 5a737a4..98f3cfd 100644 --- a/interpreter/src/evaluator/builtins.rs +++ b/interpreter/src/evaluator/builtins.rs @@ -8,9 +8,13 @@ use crate::evaluator::object::NativeObject; use rand::distributions::Uniform; use rand::{thread_rng, Rng}; +#[cfg(feature="sophon")] use llm::{load_progress_callback_stdout as load_callback, InferenceParameters, Model}; +#[cfg(feature="sophon")] use llm_base::InferenceRequest; +#[cfg(feature="sophon")] use std::{convert::Infallible, io::Write, path::Path}; +#[cfg(feature="sophon")] use spinoff; pub fn new_builtins() -> HashMap { @@ -35,6 +39,7 @@ pub fn new_builtins() -> HashMap { String::from("没关系的都一样"), Object::Builtin(2, three_body_deep_equal), ); + #[cfg(feature="sophon")] builtins.insert( String::from("智子工程"), Object::Builtin(1, three_body_sophon_engineering), @@ -147,6 +152,7 @@ fn three_body_deep_equal(args: Vec) -> Object { } } +#[cfg(feature="sophon")] fn three_body_sophon_engineering(args: Vec) -> Object { match &args[0] { Object::Hash(o) => { diff --git a/interpreter/src/evaluator/object.rs b/interpreter/src/evaluator/object.rs index 1f4131d..026abda 100644 --- a/interpreter/src/evaluator/object.rs +++ b/interpreter/src/evaluator/object.rs @@ -3,6 +3,7 @@ use std::rc::Rc; use std::cell::RefCell; use std::collections::HashMap; use std::hash::{Hash, Hasher}; +#[cfg(feature="sophon")] use llm; use crate::evaluator::env; @@ -13,6 +14,7 @@ pub type BuiltinFunc = fn(Vec) -> Object; #[derive(PartialEq, Clone, Debug)] pub enum NativeObject { + #[cfg(feature="sophon")] LLMModel(*mut dyn llm::Model), }