first commit

This commit is contained in:
stuart committed 2025-12-07 15:05:18 +01:00
1 parent 5037a09608
commit 94815b7918
10 files changed
+181

No files matched your search

View File
Whitespace-only changes.
+10
View File
@@ -0,0 +1,10 @@
from enum import Enum
class ModelType(Enum):
EMBEDDING = "embedding"
TRANSCRIPTION = "transcription"
RESPONSE = "response"
class PreprocessorType(Enum):
NORWEGIAN = "norwegian"
DEFAULT = "norwegian"
class SymbolProvider(Enum):
TOBII_DYNAVOX = "tobii_dynavox"
+20
View File
@@ -0,0 +1,20 @@
[project]
name = "shared-types"
version = "0.1.0"
description = "Shared typing models for all services"
authors = [
{ name = "Your Team", email = "team@example.com" }
]
requires-python = ">=3.10"
readme = "README.md"
keywords = ["types", "schemas", "shared"]
classifiers = [
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.10",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent"
]
[build-system]
requires = ["setuptools>=65.5.1", "wheel"]
build-backend = "setuptools.build_meta"
+52
View File
@@ -0,0 +1,52 @@
from pydantic import BaseModel as PydanticBaseModel
from typing import List, Any, Dict,Union
from structures import Embedding,Word, Symbol,Phrase
class EmbedRequest(PydanticBaseModel):
stemmed_words: List[str]
tokens: dict
class EmbeddingResponse(PydanticBaseModel):
embeddings: List[Embedding]
class ResponseRequest(PydanticBaseModel):
text: str
context: Dict[str, Any]
class PreprocessRequest(PydanticBaseModel):
text: str
class PreprocessResponse(PydanticBaseModel):
raw_words: List[str]
tokens: Dict[str, Any]
class GetSymbolRequest(PydanticBaseModel):
lexeme_id: int
class GetSymbolResponse(PydanticBaseModel):
symbol: Symbol
class GetWordRequest(PydanticBaseModel):
word_text: str
stemmed: bool = False
class GetWordResponse(PydanticBaseModel):
word:Union[Word,None]
class GetSimilarWordRequest(PydanticBaseModel):
embedding: Embedding
class GetAllPhrasesResponse(PydanticBaseModel):
phrases: List[Phrase]
View File
Whitespace-only changes.
+18
View File
@@ -0,0 +1,18 @@
from __future__ import annotations
from dataclasses import dataclass
import torch
@dataclass(frozen=True)
class Embedding:
data: torch.Tensor
def __post_init__(self):
if not isinstance(self.data, torch.Tensor):
raise TypeError(f"data must be a torch.Tensor, got {type(self.data)}")
def compare(self, other: Embedding) -> float:
"""
Compare this embedding with another embedding.
"""
raise NotImplementedError("compare method must be implemented")
+22
View File
@@ -0,0 +1,22 @@
from abc import ABC, abstractmethod
from typing import List, Union
from dataclasses import dataclass
from .embedding import Embedding
@dataclass
class Lexeme(ABC):
id: int
@property
@abstractmethod
def content(self) -> Union[str, List[str]]:
"""Text content of the lexeme."""
pass
@property
@abstractmethod
def embedding(self) -> Embedding:
"""Embedding(s) associated with the lexeme."""
pass
+26
View File
@@ -0,0 +1,26 @@
from typing import List
from .lexeme import Lexeme
from .embedding import Embedding
from .word import Word
class Phrase(Lexeme):
def __init__(self, id: int, content: str, embedding: Embedding):
self.id = id
self._content = content
self._embedding = embedding
@property
def content(self) -> List[str]:
return self._content
@property
def embedding(self) -> Embedding:
return self._embedding
def __str__(self):
return self.content
def __repr__(self):
return self.__str__()
+10
View File
@@ -0,0 +1,10 @@
from dataclasses import dataclass
from typing import Optional
from PIL import Image
@dataclass
class Symbol:
id: int
label: str
image: Optional[Image.Image]
+23
View File
@@ -0,0 +1,23 @@
from .lexeme import Lexeme
from .embedding import Embedding
class Word(Lexeme):
def __init__(self, word_id: int, content: str, embedding: Embedding):
self.id = word_id
self._content = content
self._embedding = embedding
@property
def content(self) -> str:
return self._content
@property
def embedding(self) -> Embedding:
return self._embedding
def __str__(self):
return self.content
def __repr__(self):
return self.__str__()