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

Mccloskey/llama2 hf #17

Merged
merged 18 commits into from
Nov 6, 2023
Merged

Mccloskey/llama2 hf #17

merged 18 commits into from
Nov 6, 2023

Conversation

colinmccloskey
Copy link
Contributor

No description provided.

@hunterjackson hunterjackson self-requested a review October 25, 2023 16:54
public T handle(ThreadState<T> messageStack) throws IOException {
T fromUser = messageStack.tail();
@Override
public T handle(ThreadState<T> threadState) throws IOException {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

HuggingFaceLlamaPromptBuilder<T> promptBuilder = new HuggingFaceLlamaPromptBuilder<>();

String prompt = promptBuilder.createPrompt(threadState, config);
if (prompt.equals("I'm sorry but that request was too long for me.")) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just have createPrompt return an Optional instead of doing string check like this


body.put("inputs", prompt);

String bodyString;
try {
bodyString = MAPPER.writeValueAsString(body);
} catch (JsonProcessingException e) {
throw new RuntimeException(e); // this should be impossible
throw new RuntimeException(e);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just add a comment saying this should be impossible

try {
resource = Objects.requireNonNull(HuggingFaceLlamaPromptBuilder.class.getClassLoader().getResource("llamaTokenizer.json")).toURI();
} catch (URISyntaxException e) {
LOGGER.error("Failed to find local llama tokenizer.json file", e);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a fatal error, lets throw an exception. Continuing on after a fatal error is a great way to get unexpected input downstream

Suggested change
LOGGER.error("Failed to find local llama tokenizer.json file", e);
LOGGER.error("Failed to find local llama tokenizer.json file", e);
throw new RuntimeException(e);

}

try {
assert resource != null;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

assert in java only runs in unit test (I know it's weird), that's why we have Objects.requiresNonNull()

Identifier.random(),
Identifier.random(),
Message.Role.SYSTEM);
ArrayList<Message> output = new ArrayList<>();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there a way we can avoid creating a intermediary list object here? If not lets at least initiate the size of the array list because we know that.

@hunterjackson hunterjackson merged commit 65d1246 into main Nov 6, 2023
2 checks passed
@hunterjackson hunterjackson deleted the mccloskey/llama2-hf branch November 6, 2023 22:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants