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
# NODES | |
@dataclass | |
class UserPromptNode(BaseNode[...]): | |
"""Get the system & user prompt parts for initial message, or user prompt message if there is chat history""" | |
user_prompt: str | |
system_prompts: tuple[str, ...] | |
... | |
def run(tx: GraphRunContext[...]) -> _messages.ModelRequest: | |
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
from collections.abc import Container | |
from pydantic import BaseModel, ConfigDict, create_model | |
orm_config = ConfigDict(from_attributes=True) | |
def sqlalchemy_to_pydantic( | |
db_model: type, | |
*, |
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
class VectorArray(ExtensionScalarOpsMixin, ExtensionArray): | |
""" | |
Custom Extension Array type for an array of Vectors | |
Needs to define: | |
- Associated Dtype it is used with | |
- How to construct array from sequence of scalars | |
- How data is stored and accessed | |
- Any custom array methods | |
""" |
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
import numpy as np | |
import pandas as pd | |
from pandas.core.dtypes.dtypes import PandasExtensionDtype | |
from pandas.api.extensions import ExtensionArray, ExtensionScalarOpsMixin, register_extension_dtype | |
@register_extension_dtype | |
class VectorDtype(PandasExtensionDtype): | |
""" | |
Class to describe the custom Vector data type | |
""" |
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
from functools import total_ordering | |
from math import sqrt | |
@total_ordering | |
class Vector(object): | |
""" | |
Simple class to represent a 2D vector with X and Y components. | |
Could extend with more useful methods etc | |
""" | |
def __init__(self, x, y): |