Added example of how to run Hugging Face models through Ollama using TC#8771
Merged
eddumelendez merged 8 commits intotestcontainers:mainfrom Jun 30, 2024
Merged
Conversation
kiview
requested changes
Jun 12, 2024
| } | ||
|
|
||
| @Override | ||
| protected void containerIsStarted(InspectContainerResponse containerInfo) { |
Member
There was a problem hiding this comment.
Suggested change
| protected void containerIsStarted(InspectContainerResponse containerInfo) { | |
| protected void containerIsStarted(InspectContainerResponse containerInfo, boolean reused) { |
Support re-use.
|
|
||
| @Override | ||
| protected void containerIsStarted(InspectContainerResponse containerInfo) { | ||
| super.containerIsStarted(containerInfo); |
Member
There was a problem hiding this comment.
Suggested change
| super.containerIsStarted(containerInfo); | |
| super.containerIsStarted(containerInfo, reused); | |
| if (reused) { | |
| return; | |
| } |
Don't download the model on re-use.
… not fail on compile with java 1.8
Closed
eddumelendez
requested changes
Jun 27, 2024
Member
eddumelendez
left a comment
There was a problem hiding this comment.
Thanks @ilopezluna! Left some comments to improve the example.
Comment on lines
+27
to
+38
| if (huggingFaceModel != null) { | ||
| this.setImage( | ||
| new ImageFromDockerfile() | ||
| .withDockerfileFromBuilder(builder -> { | ||
| builder | ||
| .from(this.getDockerImageName()) | ||
| .run("apt-get update && apt-get upgrade -y && apt-get install -y python3-pip") | ||
| .run("pip install huggingface-hub") | ||
| .build(); | ||
| }) | ||
| ); | ||
| } |
Member
There was a problem hiding this comment.
I think we can move those commands to containerIsStarted and use execInContainer directly.
Comment on lines
+21
to
+40
| try ( | ||
| OllamaContainer ollama = new OllamaContainer( | ||
| DockerImageName.parse(imageName).asCompatibleSubstituteFor("ollama/ollama:0.1.42") | ||
| ) | ||
| ) { | ||
| try { | ||
| ollama.start(); | ||
| } catch (ContainerFetchException ex) { | ||
| // Create the image | ||
| try ( | ||
| OllamaHuggingFaceContainer huggingFaceContainer = new OllamaHuggingFaceContainer( | ||
| imageName, | ||
| new OllamaHuggingFaceContainer.HuggingFaceModel(repository, model) | ||
| ) | ||
| ) { | ||
| huggingFaceContainer.start(); | ||
| huggingFaceContainer.stop(); | ||
| } | ||
| ollama.start(); | ||
| } |
Member
There was a problem hiding this comment.
let's use the docker client API to check if the image exists, the code will be more readable.
- use docker client to check if image already exist - remove the gguf file after creating the ollama model
eddumelendez
approved these changes
Jun 30, 2024
Member
|
Thanks @ilopezluna ! |
lizhou1111
pushed a commit
to lizhou1111/testcontainers-java
that referenced
this pull request
Jul 13, 2024
fokion
pushed a commit
to fokion/testcontainers-java
that referenced
this pull request
Jan 18, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Added example of how to use
OllamaContainerto run Hugging Face modelsCo-authored-by: @kiview