Add example wandb notebook

This commit is contained in:
afik.cohen 2024-05-02 17:51:43 -07:00
parent e6a137536c
commit 9a2b9ca2a5

90
experiments/wandb.ipynb Normal file
View file

@ -0,0 +1,90 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"id": "initial_id",
"metadata": {
"collapsed": true
},
"source": [
""
],
"outputs": []
},
{
"metadata": {
"ExecuteTime": {
"end_time": "2024-04-13T01:20:22.380492Z",
"start_time": "2024-04-13T01:20:17.939300Z"
}
},
"cell_type": "code",
"source": [
"import json\n",
"\n",
"import weave\n",
"from openai import OpenAI\n",
"\n",
"\n",
"@weave.op() # 🐝\n",
"def extract_fruit(sentence: str) -> dict:\n",
" client = OpenAI()\n",
"\n",
" response = client.chat.completions.create(\n",
" model=\"gpt-3.5-turbo-1106\",\n",
" messages=[\n",
" {\n",
" \"role\": \"system\",\n",
" \"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.\"\n",
" },\n",
" {\n",
" \"role\": \"user\",\n",
" \"content\": sentence\n",
" }\n",
" ],\n",
" temperature=0.7,\n",
" response_format={ \"type\": \"json_object\" }\n",
" )\n",
" extracted = response.choices[0].message.content\n",
" return json.loads(extracted)\n",
"\n",
"weave.init('intro-example') # 🐝\n",
"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.\"\n",
"extract_fruit(sentence)"
],
"id": "43aad670ab761737",
"execution_count": 2,
"outputs": []
},
{
"metadata": {},
"cell_type": "code",
"execution_count": null,
"source": "",
"id": "d929002a32073a23",
"outputs": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.6"
}
},
"nbformat": 4,
"nbformat_minor": 5
}