-
Notifications
You must be signed in to change notification settings - Fork 0
2 introduce llm model abstraction #5
Changes from all commits
fd8e7b5
b07cb67
9e7cb7d
5796a88
a4d7574
b31d3ce
33024f9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
name: spellcheck | ||
on: | ||
push: | ||
branches: [ "main" ] | ||
pull_request: | ||
branches: [ "main" ] | ||
jobs: | ||
check-spelling: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
- name: Check Spelling | ||
uses: rojopolis/spellcheck-github-actions@0.33.1 | ||
with: | ||
config_path: .spellcheck.yml | ||
task_name: Markdown |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
name: Run tests | ||
|
||
on: | ||
push: | ||
pull_request: | ||
|
||
jobs: | ||
test: | ||
permissions: | ||
contents: "read" | ||
id-token: "write" | ||
runs-on: ubuntu-latest | ||
services: | ||
falkordb: | ||
image: falkordb/falkordb:latest | ||
ports: | ||
- 6379:6379 | ||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- name: Set up Python | ||
uses: actions/setup-python@v5 | ||
with: | ||
python-version: 3.x # Update with desired Python version | ||
|
||
- name: Cache Poetry virtualenv | ||
id: cache | ||
uses: actions/cache@v4 | ||
with: | ||
path: ~/.poetry/virtualenvs | ||
key: ${{ runner.os }}-poetry-${{ hashFiles('poetry.lock') }} | ||
restore-keys: | | ||
${{ runner.os }}-poetry- | ||
|
||
- id: "auth" | ||
uses: "google-github-actions/auth@v2" | ||
with: | ||
credentials_json: ${{ secrets.GCP_SA_KEY }} | ||
|
||
- name: "Set up Cloud SDK" | ||
uses: "google-github-actions/setup-gcloud@v2" | ||
with: | ||
version: ">= 363.0.0" | ||
|
||
- name: Install Poetry | ||
if: steps.cache.outputs.cache-hit != true | ||
run: | | ||
curl -sSL https://install.python-poetry.org | python3 - | ||
|
||
- name: Install dependencies | ||
run: poetry install | ||
|
||
- name: Run tests | ||
env: | ||
PROJECT_ID: ${{ secrets.PROJECT_ID }} | ||
REGION: ${{ vars.REGION }} | ||
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} | ||
run: poetry run pytest |
This file was deleted.
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
@@ -1,7 +1,7 @@ | ||||
from .classes.source import Source | ||||
from .classes.ontology import Ontology | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove unused import The - from .classes.ontology import Ontology Committable suggestion
Suggested change
ToolsRuff
|
||||
from .kg import KnowledgeGraph | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove unused import The - from .kg import KnowledgeGraph Committable suggestion
Suggested change
ToolsRuff
|
||||
from .classes.model_config import KnowledgeGraphModelConfig, StepModelConfig | ||||
from .classes.model_config import KnowledgeGraphModelConfig | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove unused import The - from .classes.model_config import KnowledgeGraphModelConfig Committable suggestion
Suggested change
ToolsRuff
|
||||
from .steps.create_ontology_step import CreateOntologyStep | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove unused import The - from .steps.create_ontology_step import CreateOntologyStep Committable suggestion
Suggested change
ToolsRuff
|
||||
|
||||
# Setup Null handler | ||||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -2,8 +2,10 @@ | |||||
from .source import Source | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove unused import The - from .source import Source Committable suggestion
Suggested change
ToolsRuff
|
||||||
from .node import Node | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove unused import The - from .node import Node Committable suggestion
Suggested change
ToolsRuff
|
||||||
from .edge import Edge | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove unused import The - from .edge import Edge Committable suggestion
Suggested change
ToolsRuff
|
||||||
from .attribute import Attribute, AttributeType | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove unused import The - from .attribute import AttributeType
ToolsRuff
Remove unused import The - from .attribute import Attribute, AttributeType
+ from .attribute import AttributeType Committable suggestion
Suggested change
ToolsRuff
|
||||||
|
||||||
# Setup Null handler | ||||||
import logging | ||||||
|
||||||
logger = logging.getLogger(__name__) | ||||||
logger.addHandler(logging.NullHandler()) |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -1,7 +1,7 @@ | ||||||
import json | ||||||
import re | ||||||
import logging | ||||||
from .attribute import Attribute, _AttributeType | ||||||
from .attribute import Attribute, AttributeType | ||||||
from falkordb import Node as GraphNode, Edge as GraphEdge | ||||||
from falkordb_gemini_kg.fixtures.regex import * | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Avoid using star imports. The star import ( - from falkordb_gemini_kg.fixtures.regex import *
+ from falkordb_gemini_kg.fixtures.regex import EDGE_LABEL_REGEX, NODE_LABEL_REGEX, EDGE_REGEX Committable suggestion
Suggested change
ToolsRuff
|
||||||
|
||||||
|
@@ -58,7 +58,7 @@ def from_graph(edge: GraphEdge, nodes: list[GraphNode]): | |||||
[ | ||||||
Attribute( | ||||||
attr, | ||||||
_AttributeType.fromString(edge.properties), | ||||||
AttributeType.fromString(edge.properties), | ||||||
"!" in edge.properties[attr], | ||||||
"*" in edge.properties[attr], | ||||||
) | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,66 +1,22 @@ | ||
from vertexai.generative_models import GenerationConfig | ||
|
||
|
||
class StepModelGenerationConfig: | ||
def __init__( | ||
self, | ||
temperature: float, | ||
top_p: float, | ||
top_k: int, | ||
candidate_count: int, | ||
max_output_tokens: int, | ||
stop_sequences: list[str], | ||
): | ||
self.temperature = temperature | ||
self.top_p = top_p | ||
self.top_k = top_k | ||
self.candidate_count = candidate_count | ||
self.max_output_tokens = max_output_tokens | ||
self.stop_sequences = stop_sequences | ||
|
||
def to_generation_config(self) -> GenerationConfig: | ||
return GenerationConfig( | ||
temperature=self.temperature, | ||
top_p=self.top_p, | ||
top_k=self.top_k, | ||
candidate_count=self.candidate_count, | ||
max_output_tokens=self.max_output_tokens, | ||
stop_sequences=self.stop_sequences, | ||
) | ||
|
||
|
||
class StepModelConfig: | ||
|
||
def __init__( | ||
self, model: str, generation_config: StepModelGenerationConfig | None = None | ||
): | ||
self.model = model | ||
self.generation_config = generation_config | ||
from falkordb_gemini_kg.models import GenerativeModel | ||
|
||
|
||
class KnowledgeGraphModelConfig: | ||
|
||
def __init__( | ||
self, | ||
extract_data: StepModelConfig | None = None, | ||
cypher_generation: StepModelConfig | None = None, | ||
qa: StepModelConfig | None = None, | ||
extract_data: GenerativeModel, | ||
cypher_generation: GenerativeModel, | ||
qa: GenerativeModel, | ||
): | ||
self.extract_data = extract_data | ||
self.cypher_generation = cypher_generation | ||
self.qa = qa | ||
|
||
@staticmethod | ||
def from_dict(d: dict): | ||
model = d.get("model") | ||
generation_config = d.get("generation_config") | ||
extract_data = StepModelConfig(model=model, generation_config=generation_config) | ||
cypher_generation = StepModelConfig( | ||
model=model, generation_config=generation_config | ||
) | ||
qa = StepModelConfig(model=model, generation_config=generation_config) | ||
def with_model(model: GenerativeModel): | ||
return KnowledgeGraphModelConfig( | ||
extract_data=extract_data, | ||
cypher_generation=cypher_generation, | ||
qa=qa, | ||
extract_data=model, | ||
cypher_generation=model, | ||
qa=model, | ||
) |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1 @@ | ||||||
from .model import * | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Avoid using wildcard imports. Using - from .model import *
+ from .model import GenerativeModel, GenerativeModelConfig, GenerativeModelChatSession, FinishReason, GenerationResponse Committable suggestion
Suggested change
ToolsRuff
|
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.
Remove unused import
Source
.The
Source
class is imported but not used in this file. Consider removing it.- from .classes.source import Source
Committable suggestion
Tools
Ruff