-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ollama generation integration (#103)
* Added support for Ollama chat completions --------- Co-authored-by: Akshat Jaimini <[email protected]>
- Loading branch information
1 parent
3ac2430
commit b9fa75b
Showing
18 changed files
with
263 additions
and
20 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
name: Build and deploy ollama server | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
- ollama-integration | ||
paths: | ||
- ".github/workflows/build-ollama-serve.yml" | ||
- "ollama-serve/**" | ||
|
||
pull_request: | ||
branches: | ||
- main | ||
paths: | ||
- ".github/workflows/build-ollama-serve.yml" | ||
- "ollama-serve/**" | ||
|
||
permissions: | ||
id-token: write | ||
contents: read | ||
|
||
defaults: | ||
run: | ||
shell: bash | ||
working-directory: ./ollama-serve/ | ||
|
||
jobs: | ||
build_and_push: | ||
name: Build and push images | ||
runs-on: | ||
- self-hosted | ||
- dind | ||
- large-8x8 | ||
outputs: | ||
short_sha: ${{ steps.versions.outputs.SHORT_SHA }} | ||
steps: | ||
- name: Check out the repo | ||
uses: actions/checkout@v3 | ||
- name: Set version strings | ||
id: versions | ||
run: | | ||
echo "SHORT_SHA=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT | ||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v3 | ||
|
||
- name: Set up QEMU | ||
uses: docker/setup-qemu-action@v3 | ||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v3 | ||
|
||
- name: Login to Quay | ||
uses: docker/login-action@v2 | ||
with: | ||
registry: quay.io/tembo | ||
username: ${{ secrets.QUAY_USER_TEMBO }} | ||
password: ${{ secrets.QUAY_PASSWORD_TEMBO }} | ||
|
||
- name: Build and push -- Commit | ||
# push a build for every commit | ||
uses: docker/build-push-action@v5 | ||
with: | ||
file: ./ollama-serve/Dockerfile | ||
context: . | ||
platforms: linux/amd64, linux/arm64 | ||
push: true | ||
tags: | | ||
quay.io/tembo/ollama-serve:${{ steps.versions.outputs.SHORT_SHA }} | ||
- name: Build and push -- Latest | ||
# only push latest off main | ||
if: github.ref == 'refs/heads/main' | ||
uses: docker/build-push-action@v5 | ||
with: | ||
file: ./ollama-serve/Dockerfile | ||
context: . | ||
platforms: linux/amd64, linux/arm64 | ||
push: true | ||
tags: | | ||
quay.io/tembo/ollama-serve:latest |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
name: Build and deploy server | ||
name: Build and deploy embedding server | ||
|
||
on: | ||
push: | ||
|
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
pub mod generic; | ||
pub mod http_handler; | ||
pub mod ollama; | ||
pub mod openai; | ||
pub mod types; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
use anyhow::Result; | ||
use ollama_rs::{generation::completion::request::GenerationRequest, Ollama}; | ||
use url::Url; | ||
|
||
pub struct OllamaInstance { | ||
pub model_name: String, | ||
pub instance: Ollama, | ||
} | ||
|
||
pub trait LLMFunctions { | ||
fn new(model_name: String, url: String) -> Self; | ||
#[allow(async_fn_in_trait)] | ||
async fn generate_reponse(&self, prompt_text: String) -> Result<String, String>; | ||
} | ||
|
||
impl LLMFunctions for OllamaInstance { | ||
fn new(model_name: String, url: String) -> Self { | ||
let parsed_url = Url::parse(&url).unwrap_or_else(|_| panic!("invalid url: {}", url)); | ||
let instance = Ollama::new( | ||
format!( | ||
"{}://{}", | ||
parsed_url.scheme(), | ||
parsed_url.host_str().expect("parsed url missing") | ||
), | ||
parsed_url.port().expect("parsed port missing"), | ||
); | ||
OllamaInstance { | ||
model_name, | ||
instance, | ||
} | ||
} | ||
async fn generate_reponse(&self, prompt_text: String) -> Result<String, String> { | ||
let req = GenerationRequest::new(self.model_name.clone(), prompt_text); | ||
println!("ollama instance: {:?}", self.instance); | ||
let res = self.instance.generate(req).await; | ||
match res { | ||
Ok(res) => Ok(res.response), | ||
Err(e) => Err(e.to_string()), | ||
} | ||
} | ||
} | ||
|
||
pub fn ollama_embedding_dim(model_name: &str) -> i32 { | ||
match model_name { | ||
"llama2" => 5192, | ||
_ => 1536, | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.