Skip to content

Instantly share code, notes, and snippets.

View elijahbenizzy's full-sized avatar

Elijah ben Izzy elijahbenizzy

View GitHub Profile
results = dr.execute(
["trained_model_mlflow", "train_performance", "test_performance", "test_scatter_plot"],
inputs=dict(test_size_fraction=0.3)
)
from hamilton import driver
from hamilton.io.materialization import to
from hamilton.plugins.h_mlflow import MLFlowTracker
dr = (
driver.Builder()
.with_modules(model_training_2)
.with_adapters(
MLFlowTracker(
experiment_name="my_experiment",
from hamilton import driver
from hamilton.io.materialization import to
model_saver = to.mlflow(
id="trained_model_mlflow", # name given to the saver
dependencies=["trained_model"], # node returning the model
register_as="my_predictor", # name of the model in the MLFlow registry
)
dr = (
from hamilton import driver, base
from hamilton.io.materialization import to
json_saver = to.json(
id="saved_json_object", # name given to the saver
dependencies=["a", "b", "c"], # node returning the model
combine=base.DictResult() # put a, b, c together as a dict
)
dr = (
with mlflow.start_run():
lr = ElasticNet(alpha=alpha, l1_ratio=l1_ratio, random_state=42)
lr.fit(train_x, train_y)
predicted_qualities = lr.predict(test_x)
(rmse, mae, r2) = eval_metrics(test_y, predicted_qualities)
mlflow.log_param("alpha", alpha)
mlflow.log_param("l1_ratio", l1_ratio)
def run_cypher_query(graph, query):
try:
results = graph.ro_query(query).result_set
except:
results = {"error": "Query failed please try a different variation of this query"}
if len(results) == 0:
results = {
"error": "The query did not return any data, please make sure you're
"using the right edge directions and you're following the
def set_inital_chat_history(schema_prompt: str) -> list[dict]:
SYSTEM_MESSAGE = "You are a Cypher expert with access to a directed knowledge graph\n"
SYSTEM_MESSAGE += schema_prompt
SYSTEM_MESSAGE += ("Query the knowledge graph to extract relevant information to help you"
"answer the users questions, base your answer only on the
"context retrieved from the knowledge graph, do not use
"preexisting knowledge.")
SYSTEM_MESSAGE += ("For example to find out if two fighters had fought each other e.g."
"did Conor McGregor ever compete against Jose Aldo issue the
"following query: MATCH (a:Fighter)-[]->(f:Fight)<-[]-(b:Fighter)"
from hamilton import driver
import definitions # contains node definitions, e.g. A, B, C from above
dr = driver.Builder().with_modules(definitions).build()
# request node named "C"; returns a dictionary of results
results = dr.execute(["C"], inputs={"external_input": 7})
# request node named "B"; returns a dictionary of results
results = dr.execute(["B"], inputs={"external_input": 7})
from burr.core import ApplicationBuilder, default, expr
app = (
ApplicationBuilder()
.with_actions(
count=count,
done=done # implementation left out above
).with_transitions(
("counter", "counter", expr("count < 10")), # Keep counting if the counter is < 10
("counter", "done", default) # Otherwise, we're done
).with_state(count=0)
@action(reads=["count"], writes=["count"])
def counter(state: State) -> State:
return state.update(counter=state.get("count", 0) +1)