-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(weave): Pre-release doc script audit (#1476)
* init * subtle fixes * minor style * give all example projects the same name * fix for model_output * a few more inits * a few more inits * added tuts * linted * fixed name
- Loading branch information
Showing
20 changed files
with
432 additions
and
25 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import weave | ||
import json | ||
from openai import OpenAI | ||
|
||
|
||
@weave.op() | ||
def extract_fruit(sentence: str) -> dict: | ||
client = OpenAI() | ||
|
||
response = client.chat.completions.create( | ||
model="gpt-3.5-turbo-1106", | ||
messages=[ | ||
{ | ||
"role": "system", | ||
"content": "You will be provided with unstructured data, and your task is to parse it one JSON dictionary with fruit, color and flavor as keys.", | ||
}, | ||
{"role": "user", "content": sentence}, | ||
], | ||
temperature=0.7, | ||
response_format={"type": "json_object"}, | ||
) | ||
extracted = response.choices[0].message.content | ||
return json.loads(extracted) | ||
|
||
|
||
weave.init("intro-example") | ||
sentence = "There are many fruits that were found on the recently discovered planet Goocrux. There are neoskizzles that grow there, which are purple and taste like candy." | ||
extract_fruit(sentence) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import weave | ||
import json | ||
from openai import OpenAI | ||
|
||
|
||
@weave.op() # 🐝 | ||
def extract_fruit(sentence: str) -> dict: | ||
client = OpenAI() | ||
|
||
response = client.chat.completions.create( | ||
model="gpt-3.5-turbo-1106", | ||
messages=[ | ||
{ | ||
"role": "system", | ||
"content": "You will be provided with unstructured data, and your task is to parse it one JSON dictionary with fruit, color and flavor as keys.", | ||
}, | ||
{"role": "user", "content": sentence}, | ||
], | ||
temperature=0.7, | ||
response_format={"type": "json_object"}, | ||
) | ||
extracted = response.choices[0].message.content | ||
return json.loads(extracted) | ||
|
||
|
||
weave.init("intro-example") # 🐝 | ||
sentence = "There are many fruits that were found on the recently discovered planet Goocrux. There are neoskizzles that grow there, which are purple and taste like candy." | ||
extract_fruit(sentence) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
from weave import Model | ||
import weave | ||
|
||
|
||
class YourModel(Model): | ||
attribute1: str | ||
attribute2: int | ||
|
||
@weave.op() | ||
def predict(self, input_data: str) -> dict: | ||
# Model logic goes here | ||
prediction = self.attribute1 + " " + input_data | ||
return {"pred": prediction} | ||
|
||
|
||
import weave | ||
|
||
weave.init("intro-example") | ||
|
||
model = YourModel(attribute1="hello", attribute2=5) | ||
model.predict("world") | ||
|
||
import weave | ||
|
||
weave.init("intro-example") | ||
|
||
model = YourModel(attribute1="howdy", attribute2=10) | ||
model.predict("world") | ||
|
||
|
||
with weave.attributes({"env": "production"}): | ||
model.predict("world") |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import weave | ||
from weave import Dataset | ||
|
||
# Initialize Weave | ||
weave.init("intro-example") | ||
|
||
# Create a dataset | ||
dataset = Dataset( | ||
name="grammar", | ||
rows=[ | ||
{ | ||
"id": "0", | ||
"sentence": "He no likes ice cream.", | ||
"correction": "He doesn't like ice cream.", | ||
}, | ||
{ | ||
"id": "1", | ||
"sentence": "She goed to the store.", | ||
"correction": "She went to the store.", | ||
}, | ||
{ | ||
"id": "2", | ||
"sentence": "They plays video games all day.", | ||
"correction": "They play video games all day.", | ||
}, | ||
], | ||
) | ||
|
||
# Publish the dataset | ||
weave.publish(dataset) | ||
|
||
# Retrieve the dataset | ||
dataset_ref = weave.ref("grammar").get() | ||
|
||
# Access a specific example | ||
example_label = dataset_ref.rows[2]["sentence"] |
Oops, something went wrong.