Skip to content

Commit

Permalink
clean up examples and README
Browse files Browse the repository at this point in the history
  • Loading branch information
Forrest Bao authored and Yazawazi committed Feb 28, 2024
1 parent 9d7dad2 commit a9f7007
Show file tree
Hide file tree
Showing 12 changed files with 214 additions and 141 deletions.
260 changes: 167 additions & 93 deletions README.md

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions examples/advanced_usage/sessions_simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
title="Session/state: set",
description="Set the global variable `y` to a new value. ",
)
def set_y(x: str="123") -> str:
def set_y(new_y: str="123") -> str:
global y
y = x
y = new_y
return "Y has been changed. Now check it in the `Session/State: get` page."


Expand Down
5 changes: 3 additions & 2 deletions examples/class.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

@funix_class()
class A:
@funix_method(title="Initialize A", print_to_web=True)
# @funix_method(title="Initialize A", print_to_web=True)
def __init__(self, a: int):
self.a = a
print(f"`self.a` has been initialized to {self.a}")
Expand All @@ -16,10 +16,11 @@ def print_a(self) -> str:
return f"The value of `self.a` is {self.a}"

@staticmethod
@funix_method(disable=True)
def add(a: int, b: int) -> int:
return a + b

@staticmethod
@funix_method(title="Returns 1")
@funix_method(title="Returns 1", disable=True)
def return_1() -> int:
return 1
2 changes: 0 additions & 2 deletions examples/hello_world.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
import funix # This line can be commented out in the lazy mode of funix.
@funix.funix() # This line can be commented out in the lazy mode of funix.
def hello_world(name: str="Funix") -> str:
return f"Hello {name}!"
29 changes: 0 additions & 29 deletions examples/new_openai_with_session.py

This file was deleted.

9 changes: 9 additions & 0 deletions examples/print_to_web.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from funix import funix
@funix(
print_to_web=True
)
def my_main(x: str="123", debug:bool=True) -> None:
if debug:
print("### This is a debug message.")

return x
10 changes: 0 additions & 10 deletions examples/reactive.py

This file was deleted.

14 changes: 14 additions & 0 deletions examples/sine.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import funix
import matplotlib.pyplot, matplotlib.figure
import numpy

@funix.funix(
autorun=True
)
def sine(omega: numpy.arange(0, 1, 0.01)) -> matplotlib.figure.Figure:
fig = matplotlib.pyplot.figure()
ax = fig.add_subplot(1, 1, 1)
x = numpy.linspace(0, 12, 100)
y = numpy.sin(x*omega)
ax.plot(x, y)
return fig
File renamed without changes.
File renamed without changes.
16 changes: 16 additions & 0 deletions examples/tax_calculator_reactive.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from funix import funix

def compute_tax(salary: float, income_tax_rate: float) -> int:
return salary * income_tax_rate


@funix(
reactive={"tax": compute_tax}
)
def after_tax_income_calculator(
salary: float,
income_tax_rate: float,
tax: float) -> str:
return f"Your take home money is {salary - tax} dollars,\
for a salary of {salary} dollars, \
after a {income_tax_rate*100}% income tax."
6 changes: 3 additions & 3 deletions examples/widgets/input_widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
)
def input_widgets_basic(
prompt: str,
advanced_features: bool = False,
model: typing.Literal['GPT-3.5', 'GPT-4.0', 'Llama-2', 'Falcon-7B']= 'GPT-4.0',
max_token: funix.hint.IntSlider(100, 200, 20)=140,
advanced_features: bool = True,
model: typing.Literal['GPT-3.5', 'GPT-4.0', 'Falcon-7B']= 'GPT-4.0',
max_token: range(100, 200, 20)=140,
openai_key: ipywidgets.Password = "1234556",
) -> str:
return "This is a dummy function. It returns nothing. "

0 comments on commit a9f7007

Please sign in to comment.