-
Notifications
You must be signed in to change notification settings - Fork 222
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
234 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,230 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"id": "8a157fb8", | ||
"metadata": {}, | ||
"source": [ | ||
"# Grammar" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 1, | ||
"id": "e08cdbd6", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import datetime\n", | ||
"import os\n", | ||
"import openai\n", | ||
"import sys\n", | ||
"\n", | ||
"from dotenv import load_dotenv" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 2, | ||
"id": "55d27ebf", | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"Open AI version: 0.28.1\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"load_dotenv(\"azure.env\")\n", | ||
"\n", | ||
"# Azure Open AI\n", | ||
"openai.api_type: str = \"azure\"\n", | ||
"openai.api_key = os.getenv(\"OPENAI_API_KEY\")\n", | ||
"openai.api_base = os.getenv(\"OPENAI_API_BASE\")\n", | ||
"openai.api_version = os.getenv(\"OPENAI_API_VERSION\")\n", | ||
"\n", | ||
"print(\"Open AI version:\", openai.__version__)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 3, | ||
"id": "4889c5af", | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"Today is: 12-Oct-2023 14:55:06\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"print(\"Today is:\", datetime.datetime.today().strftime(\"%d-%b-%Y %H:%M:%S\"))" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 4, | ||
"id": "20f2f778", | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"text/plain": [ | ||
"'3.10.10 (main, Mar 21 2023, 18:45:11) [GCC 11.2.0]'" | ||
] | ||
}, | ||
"execution_count": 4, | ||
"metadata": {}, | ||
"output_type": "execute_result" | ||
} | ||
], | ||
"source": [ | ||
"sys.version" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 5, | ||
"id": "ed7bc8a5", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"def grammar(text):\n", | ||
" \"\"\"\n", | ||
" grammar analysis with Azure Open AI\n", | ||
" \"\"\"\n", | ||
" prompt = (\n", | ||
" \"You are a spoken language expert. \\\n", | ||
" You must correct any mispelling or grammar error. Do not add any additional term. This is text to verify: \"\n", | ||
" + text\n", | ||
" )\n", | ||
"\n", | ||
" response = openai.Completion.create(\n", | ||
" engine=\"text-davinci-003\",\n", | ||
" prompt=prompt,\n", | ||
" max_tokens=100,\n", | ||
" temperature=0,\n", | ||
" )\n", | ||
"\n", | ||
" result = response[\"choices\"][0][\"text\"]\n", | ||
"\n", | ||
" return result" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 6, | ||
"id": "201fa2ea", | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"\n", | ||
"\n", | ||
"She didn't go to the market.\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"print(grammar(\"She no went to the market.\"))" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 7, | ||
"id": "b54d1e49", | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"\n", | ||
"\n", | ||
"I want to be an expert.\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"print(grammar(\"I want be a expert\"))" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 8, | ||
"id": "5d90d29a", | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"\n", | ||
"\n", | ||
"Je vais faire les courses.\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"print(grammar(\"Je vais faire les course\"))" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 9, | ||
"id": "1de88976", | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"\n", | ||
"\n", | ||
"Ils sont tous partis.\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"print(grammar(\"Ils sont tous parti\"))" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "7a71338d", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3.10 - SDK v2", | ||
"language": "python", | ||
"name": "python310-sdkv2" | ||
}, | ||
"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.10.10" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 5 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# Azure Open AI | ||
OPENAI_API_BASE = "tobereplaced" | ||
OPENAI_API_KEY = "tobereplaced" | ||
OPENAI_API_VERSION = "2023-05-15" |