Skip to content

Commit

Permalink
chore: parameterized notebook
Browse files Browse the repository at this point in the history
  • Loading branch information
BroKun authored and zhanba committed Apr 28, 2024
1 parent d2235d7 commit 80df178
Show file tree
Hide file tree
Showing 5 changed files with 364 additions and 259 deletions.
95 changes: 95 additions & 0 deletions examples/execute.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 3,
"id": "1bff4672-0101-4fc1-ad2b-facf0cc7c4ae",
"metadata": {
"execution": {
"shell.execute_reply.end": "2024-04-16T09:32:16.079674Z",
"shell.execute_reply.started": "2024-04-16T09:32:14.912272Z",
"to_execute": "2024-04-16T09:32:14.975Z"
},
"libroFormatter": "formatter-string"
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"args {\"a\": 2, \"b\": \"test\"}\n",
"21634047-69023bf0a8b4809873435dc2_54253_10\n",
"{'header': {'msg_id': '5266cffb-7de1c83ab81f2f4a34668d24_54387_46', 'msg_type': 'execute_reply', 'username': 'brokun', 'session': '5266cffb-7de1c83ab81f2f4a34668d24', 'date': datetime.datetime(2024, 4, 16, 9, 32, 15, 963417, tzinfo=tzutc()), 'version': '5.3'}, 'msg_id': '5266cffb-7de1c83ab81f2f4a34668d24_54387_46', 'msg_type': 'execute_reply', 'parent_header': {'msg_id': '21634047-69023bf0a8b4809873435dc2_54253_10', 'msg_type': 'execute_request', 'username': 'brokun', 'session': '21634047-69023bf0a8b4809873435dc2', 'date': datetime.datetime(2024, 4, 16, 9, 32, 15, 961221, tzinfo=tzutc()), 'version': '5.3'}, 'metadata': {'started': '2024-04-16T09:32:15.961744Z', 'dependencies_met': True, 'engine': '0b105a88-3026-4e91-9ea0-f5d1f24f8266', 'status': 'ok'}, 'content': {'status': 'ok', 'execution_count': 6, 'user_expressions': {}, 'payload': []}, 'buffers': []}\n"
]
},
{
"data": {
"text/plain": [
"None"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"from libro_flow import execute_notebook\n",
"execute_notebook(\"test.ipynb\", args={ \"a\":2, \"b\":\"test\"}, execute_record_path='record.ipynb')"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "d96e9c32-0496-42ee-8524-a4c0034ddb12",
"metadata": {
"execution": {},
"libroFormatter": "formatter-string"
},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "4c662fdd-69e9-4db7-a8c8-060464b51f88",
"metadata": {
"execution": {},
"libroFormatter": "formatter-string"
},
"outputs": [],
"source": []
}
],
"metadata": {
"args": {
"properties": {
"a": {
"default": 1,
"title": "A",
"type": "integer"
},
"b": {
"default": "test1",
"title": "B",
"type": "string"
}
},
"title": "Parameters",
"type": "object"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
80 changes: 71 additions & 9 deletions examples/llm.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@
"cells": [
{
"cell_type": "code",
"execution_count": null,
"execution_count": 1,
"id": "e9ab7308-7da1-4620-80ca-8f1c23a18a76",
"metadata": {
"execution": {},
"execution": {
"shell.execute_reply.end": "2024-04-16T08:17:19.694214Z",
"shell.execute_reply.started": "2024-04-16T08:17:19.362097Z",
"to_execute": "2024-04-16T08:17:19.442Z"
},
"libroFormatter": "formatter-string"
},
"outputs": [],
Expand All @@ -15,10 +19,14 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 2,
"id": "0800424d-9c6c-437f-b500-0a31576d2ead",
"metadata": {
"execution": {},
"execution": {
"shell.execute_reply.end": "2024-04-16T08:17:19.888964Z",
"shell.execute_reply.started": "2024-04-16T08:17:19.867468Z",
"to_execute": "2024-04-16T08:17:19.901Z"
},
"libroFormatter": "formatter-string"
},
"outputs": [],
Expand All @@ -28,30 +36,84 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 4,
"id": "565fcbdd-f0a4-40c7-8663-222a0f30fad6",
"metadata": {
"execution": {
"shell.execute_reply.end": "2024-04-16T08:17:27.135082Z",
"shell.execute_reply.started": "2024-04-16T08:17:25.064105Z",
"to_execute": "2024-04-16T08:17:25.061Z"
},
"libroCellType": "prompt"
},
"outputs": [],
"outputs": [
{
"data": {
"application/vnd.libro.prompt+json": "Absolutely, I can assist with that. Please provide the Chinese text you want to be translated into English."
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"%%prompt \n",
"{\"model_name\":\"LLM:chatgpt\",\"chat_key\":\"LLM:chatgpt\",\"prompt\":\"You are a helpful assistant that translates Chinese to {output_language}.\",\"cell_id\":\"565fcbdd-f0a4-40c7-8663-222a0f30fad6\",\"record\":\"chat1\"}"
"{\"model_name\":\"LLM:gpt4\",\"chat_key\":\"LLM:gpt4\",\"prompt\":\"You are a helpful assistant that translates Chinese to {output_language}.\",\"cell_id\":\"565fcbdd-f0a4-40c7-8663-222a0f30fad6\",\"record\":\"chat1\"}"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 5,
"id": "d86071ba-e90f-4a4d-a775-099e08dae8df",
"metadata": {
"execution": {
"shell.execute_reply.end": "2024-04-16T08:17:30.405063Z",
"shell.execute_reply.started": "2024-04-16T08:17:29.292647Z",
"to_execute": "2024-04-16T08:17:29.288Z"
},
"libroCellType": "prompt"
},
"outputs": [],
"outputs": [
{
"data": {
"application/vnd.libro.prompt+json": "The weather is nice, let's go for a walk together."
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"%%prompt \n",
"{\"model_name\":\"LLM:chatgpt\",\"chat_key\":\"LLM:chatgpt\",\"prompt\":\"天气不错,一起去散步吧\",\"variable_name\":\"res\",\"cell_id\":\"d86071ba-e90f-4a4d-a775-099e08dae8df\",\"record\":\"chat1\"}"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "c33ae5d1-41b7-4e8d-b2b9-a78f24533744",
"metadata": {
"execution": {
"shell.execute_reply.end": "2024-04-16T08:17:35.695315Z",
"shell.execute_reply.started": "2024-04-16T08:17:35.691054Z",
"to_execute": "2024-04-16T08:17:35.745Z"
},
"libroFormatter": "formatter-string"
},
"outputs": [
{
"data": {
"text/plain": [
"AIMessage(content=\"The weather is nice, let's go for a walk together.\", response_metadata={'token_usage': {'completion_tokens': 13, 'prompt_tokens': 61, 'total_tokens': 74}, 'model_name': 'gpt-3.5-turbo', 'system_fingerprint': 'fp_c2295e73ad', 'finish_reason': 'stop', 'logprobs': None}, id='run-8d261356-50a6-4fb2-b69a-9ca6af1c0534-0')"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"res"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand Down
Loading

0 comments on commit 80df178

Please sign in to comment.