codeflash-internal/experiments/wandb.ipynb

87 lines
2.2 KiB
Text
Raw Permalink Normal View History

2024-05-03 00:51:43 +00:00
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"id": "initial_id",
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
2024-05-03 00:51:43 +00:00
},
{
"cell_type": "code",
"execution_count": 2,
"id": "43aad670ab761737",
2024-05-03 00:51:43 +00:00
"metadata": {
"ExecuteTime": {
"end_time": "2024-04-13T01:20:22.380492Z",
"start_time": "2024-04-13T01:20:17.939300Z"
}
},
"outputs": [],
2024-05-03 00:51:43 +00:00
"source": [
"import json\n",
"\n",
"import weave\n",
"from openai import OpenAI\n",
"\n",
"\n",
"@weave.op() # 🐝\n",
2024-05-03 00:51:43 +00:00
"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",
" {\"role\": \"user\", \"content\": sentence},\n",
2024-05-03 00:51:43 +00:00
" ],\n",
" temperature=0.7,\n",
" response_format={\"type\": \"json_object\"},\n",
2024-05-03 00:51:43 +00:00
" )\n",
" extracted = response.choices[0].message.content\n",
" return json.loads(extracted)\n",
"\n",
"\n",
"weave.init(\"intro-example\") # 🐝\n",
2024-05-03 00:51:43 +00:00
"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)"
]
2024-05-03 00:51:43 +00:00
},
{
"cell_type": "code",
"execution_count": null,
"id": "d929002a32073a23",
"metadata": {},
"outputs": [],
"source": []
2024-05-03 00:51:43 +00:00
}
],
"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
}