Skip to content

Commit

Permalink
chore(weave): Fix notebook docs: OpenAI and model_output #3274
Browse files Browse the repository at this point in the history
  • Loading branch information
tssweeney authored Dec 17, 2024
1 parent efc4068 commit 588012f
Show file tree
Hide file tree
Showing 11 changed files with 92 additions and 17 deletions.
19 changes: 16 additions & 3 deletions docs/intro_notebook.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
"---\n",
"docusaurus_head_meta::end -->\n",
"\n",

"<!--- @wandbcode{intro-colab} -->"
]
},
Expand Down Expand Up @@ -54,6 +53,20 @@
"!pip install weave openai set-env-colab-kaggle-dotenv"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "5e188ab8",
"metadata": {},
"outputs": [],
"source": [
"%%capture\n",
"# Temporary workaround to fix bug in openai:\n",
"# TypeError: Client.__init__() got an unexpected keyword argument 'proxies'\n",
"# See https://community.openai.com/t/error-with-openai-1-56-0-client-init-got-an-unexpected-keyword-argument-proxies/1040332/15\n",
"!pip install \"httpx<0.28\""
]
},
{
"cell_type": "code",
"execution_count": null,
Expand Down Expand Up @@ -586,9 +599,9 @@
"\n",
"# Define any custom scoring function\n",
"@weave.op()\n",
"def exact_match(expected: str, model_output: dict) -> dict:\n",
"def exact_match(expected: str, output: dict) -> dict:\n",
" # Here is where you'd define the logic to score the model output\n",
" return {\"match\": expected == model_output}\n",
" return {\"match\": expected == output}\n",
"\n",
"\n",
"# Score your examples using scoring functions\n",
Expand Down
13 changes: 13 additions & 0 deletions docs/notebooks/audio_with_weave.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,19 @@
"!pip install set-env-colab-kaggle-dotenv -q # for env var"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%%capture\n",
"# Temporary workaround to fix bug in openai:\n",
"# TypeError: Client.__init__() got an unexpected keyword argument 'proxies'\n",
"# See https://community.openai.com/t/error-with-openai-1-56-0-client-init-got-an-unexpected-keyword-argument-proxies/1040332/15\n",
"!pip install \"httpx<0.28\""
]
},
{
"cell_type": "markdown",
"metadata": {
Expand Down
5 changes: 2 additions & 3 deletions docs/notebooks/chain_of_density.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
"---\n",
"docusaurus_head_meta::end -->\n",
"\n",

"<!--- @wandbcode{cod-notebook} -->"
]
},
Expand Down Expand Up @@ -502,8 +501,8 @@
"source": [
"# Define the scorer function\n",
"@weave.op()\n",
"def quality_scorer(instruction: str, model_output: dict) -> dict:\n",
" result = evaluate_summary(model_output[\"final_summary\"], instruction)\n",
"def quality_scorer(instruction: str, output: dict) -> dict:\n",
" result = evaluate_summary(output[\"final_summary\"], instruction)\n",
" return result"
]
},
Expand Down
17 changes: 15 additions & 2 deletions docs/notebooks/codegen.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,19 @@
"!pip install -qU autopep8 autoflake weave isort openai set-env-colab-kaggle-dotenv datasets"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%%capture\n",
"# Temporary workaround to fix bug in openai:\n",
"# TypeError: Client.__init__() got an unexpected keyword argument 'proxies'\n",
"# See https://community.openai.com/t/error-with-openai-1-56-0-client-init-got-an-unexpected-keyword-argument-proxies/1040332/15\n",
"!pip install \"httpx<0.28\""
]
},
{
"cell_type": "code",
"execution_count": null,
Expand Down Expand Up @@ -383,8 +396,8 @@
"outputs": [],
"source": [
"@weave.op()\n",
"async def score_humaneval_test(test: str, entry_point: str, model_output: str):\n",
" generated_code = model_output\n",
"async def score_humaneval_test(test: str, entry_point: str, output: str):\n",
" generated_code = output\n",
"\n",
" # Extract test cases from the test string\n",
" test_cases = re.findall(r\"assert.*\", test)\n",
Expand Down
5 changes: 2 additions & 3 deletions docs/notebooks/dspy_prompt_optimization.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
"---\n",
"docusaurus_head_meta::end -->\n",
"\n",

"<!--- @wandbcode{prompt-optim-notebook} -->"
]
},
Expand Down Expand Up @@ -300,8 +299,8 @@
"outputs": [],
"source": [
"@weave.op()\n",
"def weave_evaluation_scorer(answer: str, model_output: Output) -> dict:\n",
" return {\"match\": int(answer.lower() == model_output[\"answer\"].lower())}"
"def weave_evaluation_scorer(answer: str, output: Output) -> dict:\n",
" return {\"match\": int(answer.lower() == output[\"answer\"].lower())}"
]
},
{
Expand Down
14 changes: 13 additions & 1 deletion docs/notebooks/feedback_prod.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
"---\n",
"docusaurus_head_meta::end -->\n",
"\n",

"<!--- @wandbcode{feedback-colab} -->"
]
},
Expand Down Expand Up @@ -49,6 +48,19 @@
"!pip install weave openai streamlit"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%%capture\n",
"# Temporary workaround to fix bug in openai:\n",
"# TypeError: Client.__init__() got an unexpected keyword argument 'proxies'\n",
"# See https://community.openai.com/t/error-with-openai-1-56-0-client-init-got-an-unexpected-keyword-argument-proxies/1040332/15\n",
"!pip install \"httpx<0.28\""
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down
13 changes: 13 additions & 0 deletions docs/notebooks/multi-agent-structured-output.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,19 @@
"!pip install -qU openai weave wandb"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%%capture\n",
"# Temporary workaround to fix bug in openai:\n",
"# TypeError: Client.__init__() got an unexpected keyword argument 'proxies'\n",
"# See https://community.openai.com/t/error-with-openai-1-56-0-client-init-got-an-unexpected-keyword-argument-proxies/1040332/15\n",
"!pip install \"httpx<0.28\""
]
},
{
"cell_type": "markdown",
"metadata": {
Expand Down
2 changes: 1 addition & 1 deletion docs/notebooks/notdiamond_custom_routing.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@
"outputs": [],
"source": [
"@weave.op()\n",
"def is_correct(score: int, model_output: dict) -> dict:\n",
"def is_correct(score: int, output: dict) -> dict:\n",
" # We hack score, since we already have model responses\n",
" return {\"correct\": score}\n",
"\n",
Expand Down
4 changes: 2 additions & 2 deletions examples/tutorial_scripts/05_eval_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ async def predict(self, sentence: str) -> dict:


@weave.op()
def fruit_name_score(target: dict, model_output: dict) -> dict:
return {"correct": target["fruit"] == model_output["fruit"]}
def fruit_name_score(target: dict, output: dict) -> dict:
return {"correct": target["fruit"] == output["fruit"]}


evaluation = weave.Evaluation(
Expand Down
4 changes: 2 additions & 2 deletions examples/tutorial_scripts/06_eval_pipeline_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ async def predict(self, sentence: str) -> dict:

# We define a scoring functions to compare our model predictions with a ground truth label.
@weave.op()
def fruit_name_score(target: dict, model_output: dict) -> dict:
return {"correct": target["fruit"] == model_output["fruit"]}
def fruit_name_score(target: dict, output: dict) -> dict:
return {"correct": target["fruit"] == output["fruit"]}


# Finally, we run an evaluation of this model.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,19 @@
"!pip install -qqq openai"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%%capture\n",
"# Temporary workaround to fix bug in openai:\n",
"# TypeError: Client.__init__() got an unexpected keyword argument 'proxies'\n",
"# See https://community.openai.com/t/error-with-openai-1-56-0-client-init-got-an-unexpected-keyword-argument-proxies/1040332/15\n",
"!pip install \"httpx<0.28\""
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down

0 comments on commit 588012f

Please sign in to comment.