Skip to content

Commit

Permalink
Updated knowledge and llm.py docs
Browse files Browse the repository at this point in the history
  • Loading branch information
antoninoLorenzo committed Jun 19, 2024
1 parent 5b396c3 commit d62f1ed
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 4 deletions.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
7 changes: 6 additions & 1 deletion src/agent/knowledge/chunker.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
"""
Retrieval Augmented Generation chunking used to put documents into Qdrant.
"""
import spacy

from src.agent.knowledge.collections import Document
Expand All @@ -7,7 +10,9 @@


def chunk_str(document: str):
"""Chunks a text string"""
"""Chunks a text string.
The chunking strategy is NLP sentence extraction -> sentence grouping by similarity.
"""
doc = nlp(document)
sentences = [sent for sent in list(doc.sents) if str(sent).strip() not in ['*']]

Expand Down
1 change: 1 addition & 0 deletions src/agent/knowledge/collections.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"""RAG related data"""
from dataclasses import dataclass
from enum import StrEnum
from typing import List, Optional
Expand Down
4 changes: 3 additions & 1 deletion src/agent/knowledge/store.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"""RAG Vector Database interface"""
from typing import Dict

import ollama
Expand All @@ -8,7 +9,8 @@


class Store:
"""Act as interface for Qdrant database"""
"""Act as interface for Qdrant database.
Manages Collections and implements the Upload/Retrieve operations."""

def __init__(self):
self._connection = QdrantClient(":memory:")
Expand Down
14 changes: 12 additions & 2 deletions src/agent/llm.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,27 @@
"""
Interfaces the AI Agent to the LLM Provider, model availability depends on
implemented prompts, to use a new model the relative prompts should be written.
LLM providers are:
- [x] Ollama
- [ ] HuggingFace
"""
from ollama import Client
from dataclasses import dataclass

AVAILABLE_MODELS = ['phi3', 'gemma:2b']
AVAILABLE_MODELS = ['phi3', 'gemma:2b', 'gemma:7b']


@dataclass
class LLM:
"""Ollama model interface"""
model: str
client: Client = Client(host='http://localhost:11434')
client_url: str = 'http://localhost:11434'

def __post_init__(self):
if self.model not in AVAILABLE_MODELS:
raise ValueError(f'Model {self.model} is not available')
self.client = Client(self.client_url)

def query(self, messages: list, stream=True):
"""Generator that returns response chunks from Phi3-mini-k4 model"""
Expand Down

0 comments on commit d62f1ed

Please sign in to comment.