-
Notifications
You must be signed in to change notification settings - Fork 0
Mvr/#17/launch docker #21
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
Open
MatthiasvonRakowski
wants to merge
19
commits into
dev
Choose a base branch
from
mvr/#17/launch_docker
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
81826b7
wip(rag): V1 of a rag working with an ollama llm working with the cur…
MatthiasvonRakowski 87588fb
wip(rag): set the filter at None to be able to restrieve collections …
MatthiasvonRakowski fe78725
Merge remote-tracking branch 'origin/dev' into mvr/#38/setupRAG
MatthiasvonRakowski 9b7dade
feat(id): add ids to make it work with the rag system + an ingestion …
MatthiasvonRakowski 52b2cc5
clean(id): clean code
MatthiasvonRakowski 209969e
feat(ingestion): ingestion done with the possibility of semantic and …
MatthiasvonRakowski b5f810f
wip(todo): Add some todos to not forget the work I have to do
MatthiasvonRakowski a0418a9
refacto(user_ids): user_id -> user_id
MatthiasvonRakowski 529297a
wip(pr): add a module with ids and generate a rag class with module w…
MatthiasvonRakowski 9cc6083
Merge remote-tracking branch 'origin/mvr/#14/ids_managment' into mvr/…
MatthiasvonRakowski 04073a0
wip(docker): add a docker that launch with one commande. Only work wi…
MatthiasvonRakowski eebb216
wip(config): move qdrant, ollama into a config file.
MatthiasvonRakowski 52c03bb
wip(config): config file client updated
MatthiasvonRakowski 7bdcc71
feat(huri): update config file
MatthiasvonRakowski 452fc4d
fix(ingestion): update for the wrong branch now fixed
MatthiasvonRakowski 2f691fa
merge: dev -> launch docker
MatthiasvonRakowski 96d1da7
merge: dev -> launch docker
MatthiasvonRakowski eb4f98c
fix(config): huri.yaml fix
MatthiasvonRakowski 450f21d
remove(main): remove unnecessary function
MatthiasvonRakowski File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| huri_url: ws://localhost:8000/session | ||
|
|
||
| topic_list: ["transcript", "question", "rag_response"] | ||
| sample_rate: 16000 | ||
| frame_duration: 0.030 | ||
| modules: | ||
| mic: | ||
| name: mic | ||
| args: | ||
| vad_agressiveness: 3 | ||
| silence_duration: 1.5 | ||
| block_duration: ${frame_duration} | ||
| stt: | ||
| name: stt | ||
| args: | ||
| language: "en" | ||
| block_duration: ${frame_duration} | ||
| logging: INFO | ||
| tag: | ||
| name: tag | ||
| logging: INFO | ||
| rag: | ||
| name: rag | ||
| args: | ||
| language: "en" | ||
| tone: "formal" |
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,220 @@ | ||
| import time | ||
| import socket | ||
| import subprocess | ||
|
|
||
| import httpx | ||
| from ray import serve | ||
|
|
||
|
|
||
| def find_free_port() -> int: | ||
| """ | ||
| Ask the OS for a random free port. | ||
| We need this because if we run multiple Ollama containers, | ||
| they can't all use port 11434 — each needs its own. | ||
| """ | ||
| with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s: | ||
| s.bind(("", 0)) | ||
| return s.getsockname()[1] | ||
|
|
||
|
|
||
| def wait_for_service(url: str, timeout: int = 120) -> bool: | ||
| """ | ||
| Returns True if ready, False if timeout. | ||
| """ | ||
| start = time.time() | ||
| while time.time() - start < timeout: | ||
| try: | ||
| resp = httpx.get(url, timeout=5) | ||
| if resp.status_code == 200: | ||
| return True | ||
| except Exception: | ||
| pass | ||
| time.sleep(2) | ||
| return False | ||
|
|
||
|
|
||
| def is_container_running(name: str) -> bool: | ||
| """Check if a Docker container with this name is already running.""" | ||
| result = subprocess.run( | ||
| ["docker", "ps", "-q", "-f", f"name=^{name}$"], | ||
| capture_output=True, text=True, | ||
| ) | ||
| return bool(result.stdout.strip()) | ||
|
|
||
|
|
||
| def remove_container(name: str): | ||
| """Force remove a container by name (ignores errors if it doesn't exist).""" | ||
| subprocess.run(["docker", "rm", "-f", name], capture_output=True) | ||
|
|
||
|
|
||
| @serve.deployment | ||
| class OllamaService: | ||
| """ | ||
| Manages one Ollama Docker container. | ||
|
|
||
| LIFECYCLE: | ||
| __init__: starts container -> waits for it -> pulls model | ||
| generate: sends a prompt to the container, returns the answer | ||
| __del__: stops and removes the container | ||
| """ | ||
|
|
||
| def __init__( | ||
| self, | ||
| model: str = "mistral:7b", | ||
| image: str = "ollama/ollama:latest", | ||
| gpu_devices: bool = False, | ||
| ): | ||
| self.model = model | ||
| self.port = find_free_port() | ||
| self.container_name = f"ollama-ray-{self.port}" | ||
| self.base_url = f"http://localhost:{self.port}" | ||
|
|
||
| remove_container(self.container_name) | ||
|
|
||
| cmd = [ | ||
| "docker", "run", "-d", | ||
| "--name", self.container_name, | ||
| "-p", f"{self.port}:11434", | ||
| "-v", "ollama_shared:/root/.ollama", | ||
| ] | ||
|
|
||
| if gpu_devices: | ||
| cmd.extend([ | ||
| "--device=/dev/kfd", | ||
| "--device=/dev/dri", | ||
| "--group-add=video", | ||
| ]) | ||
|
|
||
| cmd.append(image) | ||
|
|
||
| print(f"[OllamaService] Starting container '{self.container_name}' on port {self.port}...") | ||
| result = subprocess.run(cmd, capture_output=True, text=True) | ||
| if result.returncode != 0: | ||
| raise RuntimeError(f"Docker failed: {result.stderr}") | ||
|
|
||
| print(f"[OllamaService] Waiting for Ollama to be ready...") | ||
| if not wait_for_service(f"{self.base_url}/api/tags"): | ||
| raise RuntimeError(f"Ollama didn't start within timeout on port {self.port}") | ||
|
|
||
| print(f"[OllamaService] Pulling model '{model}'...") | ||
| pull_result = subprocess.run( | ||
| ["docker", "exec", self.container_name, "ollama", "pull", model], | ||
| capture_output=True, text=True, | ||
| ) | ||
| if pull_result.returncode != 0: | ||
| raise RuntimeError(f"Failed to pull model: {pull_result.stderr}") | ||
|
|
||
| print(f"[OllamaService] Ready! container='{self.container_name}', port={self.port}, model='{model}'") | ||
|
|
||
|
|
||
| async def generate( | ||
| self, | ||
| messages: list, | ||
| max_tokens: int = 1024, | ||
| temperature: float = 0.1, | ||
| ) -> str: | ||
| """ | ||
| Send messages to Ollama and return the response. | ||
| This is what RAGHandle calls to get LLM answers. | ||
| """ | ||
| async with httpx.AsyncClient(timeout=60.0) as client: | ||
| resp = await client.post( | ||
| f"{self.base_url}/api/chat", | ||
| json={ | ||
| "model": self.model, | ||
| "messages": messages, | ||
| "stream": False, | ||
| "options": { | ||
| "num_predict": max_tokens, | ||
| "temperature": temperature, | ||
| }, | ||
| }, | ||
| ) | ||
| resp.raise_for_status() | ||
| return resp.json()["message"]["content"] | ||
|
|
||
| async def health(self) -> dict: | ||
| """Check if this Ollama instance is alive.""" | ||
| try: | ||
| async with httpx.AsyncClient(timeout=5.0) as client: | ||
| resp = await client.get(f"{self.base_url}/api/tags") | ||
| return {"status": "ok", "port": self.port, "container": self.container_name} | ||
| except Exception as e: | ||
| return {"status": "error", "error": str(e)} | ||
|
|
||
| def __del__(self): | ||
| """Cleanup when Ray destroys this replica.""" | ||
| print(f"[OllamaService] Removing container '{self.container_name}'") | ||
| remove_container(self.container_name) | ||
|
|
||
|
|
||
| @serve.deployment(num_replicas=1) | ||
| class QdrantService: | ||
| """ | ||
| Manages a Qdrant Docker container. | ||
|
|
||
| LIFECYCLE: | ||
| __init__: starts container (or reuses if already running) | ||
| get_url: returns the URL other services should connect to | ||
| __del__: leaves the container running (it has data!) | ||
| """ | ||
|
|
||
| def __init__( | ||
| self, | ||
| port: int = 6333, | ||
| image: str = "qdrant/qdrant:latest", | ||
| storage_volume: str = "qdrant_data", | ||
| ): | ||
| self.port = port | ||
| self.container_name = "qdrant-ray" | ||
| self.url = f"http://localhost:{self.port}" | ||
|
|
||
| if self._is_healthy(): | ||
| print(f"[QdrantService] Qdrant already running on port {self.port}") | ||
| return | ||
|
|
||
| remove_container(self.container_name) | ||
|
|
||
| cmd = [ | ||
| "docker", "run", "-d", | ||
| "--name", self.container_name, | ||
| "-p", f"{self.port}:6333", | ||
| "-v", f"{storage_volume}:/qdrant/storage", | ||
| image, | ||
| ] | ||
|
|
||
| print(f"[QdrantService] Starting Qdrant on port {self.port}...") | ||
| result = subprocess.run(cmd, capture_output=True, text=True) | ||
| if result.returncode != 0: | ||
| raise RuntimeError(f"Docker failed: {result.stderr}") | ||
|
|
||
| if not wait_for_service(f"{self.url}/healthz"): | ||
| raise RuntimeError(f"Qdrant didn't start within timeout on port {self.port}") | ||
|
|
||
| print(f"[QdrantService] Ready on port {self.port}") | ||
|
|
||
|
|
||
| def _is_healthy(self) -> bool: | ||
| try: | ||
| resp = httpx.get(f"{self.url}/healthz", timeout=3) | ||
| return resp.status_code == 200 | ||
| except Exception: | ||
| return False | ||
|
|
||
|
|
||
| async def get_url(self) -> str: | ||
| """Return the URL. Called by RAGHandle to know where Qdrant is.""" | ||
| return self.url | ||
|
|
||
|
|
||
| async def health(self) -> dict: | ||
| try: | ||
| async with httpx.AsyncClient(timeout=5.0) as client: | ||
| resp = await client.get(f"{self.url}/healthz") | ||
| return {"status": "ok", "port": self.port, "url": self.url} | ||
| except Exception as e: | ||
| return {"status": "error", "error": str(e)} | ||
|
|
||
|
|
||
| def __del__(self): | ||
| print(f"[QdrantService] Actor destroyed. Container '{self.container_name}' left running.") |
Oops, something went wrong.
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.
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.
Tu pourrais possiblement faire la config de qdrant et OllamaService danss le config file huri.yaml je pense, ce srait plus clean
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.
T as raison je vais regarder pour le faire
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.
Bizarement fait