mirror of
https://github.com/codeflash-ai/codeflash-internal.git
synced 2026-05-04 18:25:18 +00:00
86 lines
2.2 KiB
Text
86 lines
2.2 KiB
Text
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "initial_id",
|
|
"metadata": {
|
|
"collapsed": true
|
|
},
|
|
"outputs": [],
|
|
"source": []
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 2,
|
|
"id": "43aad670ab761737",
|
|
"metadata": {
|
|
"ExecuteTime": {
|
|
"end_time": "2024-04-13T01:20:22.380492Z",
|
|
"start_time": "2024-04-13T01:20:17.939300Z"
|
|
}
|
|
},
|
|
"outputs": [],
|
|
"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",
|
|
" {\"role\": \"user\", \"content\": sentence},\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",
|
|
"\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)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "d929002a32073a23",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": []
|
|
}
|
|
],
|
|
"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
|
|
}
|