Skip to content

Commit

Permalink
set up sampler resource to use new sampler api
Browse files Browse the repository at this point in the history
  • Loading branch information
AsbjornOlling committed Nov 28, 2024
1 parent dd25561 commit 51ea101
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 13 deletions.
44 changes: 41 additions & 3 deletions nobodywho/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,61 @@ unsafe impl ExtensionLibrary for NobodyWhoExtension {}
struct NobodyWhoSampler {
base: Base<Resource>,

#[export]
seed: u32,
#[export]
temperature: f32,
#[export]
penalty_last_n: i32,
#[export]
penalty_repeat: f32,
#[export]
penalty_freq: f32,
#[export]
penalty_present: f32,
#[export]
penalize_nl: bool,
#[export]
ignore_eos: bool,
#[export]
mirostat_tau: f32,
#[export]
mirostat_eta: f32,
}

#[godot_api]
impl IResource for NobodyWhoSampler {
fn init(base: Base<Resource>) -> Self {
Self {
base,
temperature: 0.5,
seed: llm::DEFAULT_SAMPLER_CONFIG.seed,
temperature: llm::DEFAULT_SAMPLER_CONFIG.temperature,
penalty_last_n: llm::DEFAULT_SAMPLER_CONFIG.penalty_last_n,
penalty_repeat: llm::DEFAULT_SAMPLER_CONFIG.penalty_repeat,
penalty_freq: llm::DEFAULT_SAMPLER_CONFIG.penalty_freq,
penalty_present: llm::DEFAULT_SAMPLER_CONFIG.penalty_present,
penalize_nl: llm::DEFAULT_SAMPLER_CONFIG.penalize_nl,
ignore_eos: llm::DEFAULT_SAMPLER_CONFIG.ignore_eos,
mirostat_tau: llm::DEFAULT_SAMPLER_CONFIG.mirostat_tau,
mirostat_eta: llm::DEFAULT_SAMPLER_CONFIG.mirostat_eta,
}
}
}

impl<'a> NobodyWhoSampler {
impl NobodyWhoSampler {
pub fn get_sampler_config(&self) -> llm::SamplerConfig {
llm::DEFAULT_SAMPLER_CONFIG
llm::SamplerConfig {
seed: self.seed,
temperature: self.temperature,
penalty_last_n: self.penalty_last_n,
penalty_repeat: self.penalty_repeat,
penalty_freq: self.penalty_freq,
penalty_present: self.penalty_present,
penalize_nl: self.penalize_nl,
ignore_eos: self.ignore_eos,
mirostat_tau: self.mirostat_tau,
mirostat_eta: self.mirostat_eta,
}
}
}

Expand Down
20 changes: 10 additions & 10 deletions nobodywho/src/llm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,16 @@ pub fn apply_chat_template(model: Model, chat: Vec<(String, String)>) -> Result<
}

pub struct SamplerConfig {
seed: u32,
temperature: f32,
penalty_last_n: i32,
penalty_repeat: f32,
penalty_freq: f32,
penalty_present: f32,
penalize_nl: bool,
ignore_eos: bool,
mirostat_tau: f32,
mirostat_eta: f32,
pub seed: u32,
pub temperature: f32,
pub penalty_last_n: i32,
pub penalty_repeat: f32,
pub penalty_freq: f32,
pub penalty_present: f32,
pub penalize_nl: bool,
pub ignore_eos: bool,
pub mirostat_tau: f32,
pub mirostat_eta: f32,
}

// defaults here match the defaults read from `llama-cli --help`
Expand Down

0 comments on commit 51ea101

Please sign in to comment.