- Sponsor
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Added example of how to run Hugging Face models through Ollama using TC #8771
Added example of how to run Hugging Face models through Ollama using TC #8771
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For adding reuse support, see suggestions (try if they compile like this 😅 ).
} | ||
|
||
@Override | ||
protected void containerIsStarted(InspectContainerResponse containerInfo) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
protected void containerIsStarted(InspectContainerResponse containerInfo) { | |
protected void containerIsStarted(InspectContainerResponse containerInfo, boolean reused) { |
Support re-use.
|
||
@Override | ||
protected void containerIsStarted(InspectContainerResponse containerInfo) { | ||
super.containerIsStarted(containerInfo); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @ilopezluna! Left some comments to improve the example.
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(); | ||
}) | ||
); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can move those commands to containerIsStarted
and use execInContainer
directly.
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(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
Thanks @ilopezluna ! |
Added example of how to use
OllamaContainer
to run Hugging Face modelsCo-authored-by: @kiview