Skip to content

Commit

Permalink
Make sophon a feature in three body intepreter
Browse files Browse the repository at this point in the history
  • Loading branch information
meloalright committed Apr 8, 2024
1 parent a70e583 commit 4221f35
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/Sophon.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ on:
- main

jobs:
build:
reasoning:
runs-on: ubuntu-latest

steps:
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
10 changes: 7 additions & 3 deletions interpreter/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
6 changes: 6 additions & 0 deletions interpreter/src/evaluator/builtins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, Object> {
Expand All @@ -35,6 +39,7 @@ pub fn new_builtins() -> HashMap<String, Object> {
String::from("没关系的都一样"),
Object::Builtin(2, three_body_deep_equal),
);
#[cfg(feature="sophon")]
builtins.insert(
String::from("智子工程"),
Object::Builtin(1, three_body_sophon_engineering),
Expand Down Expand Up @@ -147,6 +152,7 @@ fn three_body_deep_equal(args: Vec<Object>) -> Object {
}
}

#[cfg(feature="sophon")]
fn three_body_sophon_engineering(args: Vec<Object>) -> Object {
match &args[0] {
Object::Hash(o) => {
Expand Down
2 changes: 2 additions & 0 deletions interpreter/src/evaluator/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -13,6 +14,7 @@ pub type BuiltinFunc = fn(Vec<Object>) -> Object;

#[derive(PartialEq, Clone, Debug)]
pub enum NativeObject {
#[cfg(feature="sophon")]
LLMModel(*mut dyn llm::Model),
}

Expand Down

0 comments on commit 4221f35

Please sign in to comment.