Skip to content

Commit

Permalink
feat!: rename start_with to complete_with
Browse files Browse the repository at this point in the history
inference only returns one of these string, whereas the naming suggested it would
return a completion starting with one of the string
  • Loading branch information
moldhouse committed Dec 10, 2024
1 parent 5f18f38 commit edd5590
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 13 deletions.
11 changes: 5 additions & 6 deletions src/completion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,13 @@ pub struct Sampling<'a> {
/// the smallest possible set of tokens whose cumulative probability exceeds the probability
/// top_p. Set to 0 to get the same behaviour as `None`.
pub top_p: Option<f64>,
/// Only start the completion with one of the following strings. The model will sample
/// between these options, and ignore anything else. Once one of the options is generated,
/// then the model will continue sampling until one of the stop reasons is reached.
/// Only complete with one of the following strings. The model will sample
/// between these options, and ignore anything else.
///
/// For example, if trying to get the model to answer "Yes" or "No", and your prompt was
/// "Can this question be answered?" this could be set to `[" Yes", " No"]`. Note the
/// space in front of each option, since the model would start with a space character.
pub start_with_one_of: &'a [&'a str],
pub complete_with_one_of: &'a [&'a str],
}

impl Sampling<'_> {
Expand All @@ -65,7 +64,7 @@ impl Sampling<'_> {
temperature: None,
top_k: None,
top_p: None,
start_with_one_of: &[],
complete_with_one_of: &[],
};
}

Expand Down Expand Up @@ -157,7 +156,7 @@ impl<'a> BodyCompletion<'a> {
temperature: task.sampling.temperature,
top_k: task.sampling.top_k,
top_p: task.sampling.top_p,
completion_bias_inclusion: task.sampling.start_with_one_of,
completion_bias_inclusion: task.sampling.complete_with_one_of,
stream: false,
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ impl Client {
self.output_of(&task.with_model(model), how).await
}

/// Execute any task with the aleph alpha API and fetch its result. This is most usefull in
/// Execute any task with the aleph alpha API and fetch its result. This is most useful in
/// generic code then you want to execute arbitrary task types. Otherwise prefer methods taking
/// concrete tasks like [`Self::completion`] for improved readability.
pub async fn output_of<T: Job>(&self, task: &T, how: &How) -> Result<T::Output, Error> {
Expand Down
9 changes: 3 additions & 6 deletions tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ async fn only_answer_with_specific_animal() {
prompt,
stopping: Stopping::from_maximum_tokens(1),
sampling: Sampling {
start_with_one_of: &[" dog"],
complete_with_one_of: &[" dog"],
..Default::default()
},
};
Expand All @@ -431,7 +431,6 @@ async fn only_answer_with_specific_animal() {
assert_eq!(response.completion, " dog");
}

#[should_panic]
#[tokio::test]
async fn answer_should_continue() {
// Given
Expand All @@ -442,7 +441,7 @@ async fn answer_should_continue() {
prompt,
stopping: Stopping::from_maximum_tokens(20),
sampling: Sampling {
start_with_one_of: &[" Says.", " Art.", " Weekend."],
complete_with_one_of: &[" Says.", " Art.", " Weekend."],
..Default::default()
},
};
Expand All @@ -454,9 +453,7 @@ async fn answer_should_continue() {
.unwrap();

// Then
eprintln!("{}", response.completion);
assert!(response.completion.starts_with(" Says."));
assert!(response.completion.len() > " Says.".len());
assert_eq!(response.completion, " Says.");
}

#[tokio::test]
Expand Down

0 comments on commit edd5590

Please sign in to comment.