Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: rename start_with to complete_with #44

Merged
merged 1 commit into from
Dec 10, 2024
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
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
Loading