Skip to content

Instantly share code, notes, and snippets.

@c17hawke
Last active March 16, 2023 08:26
Show Gist options
  • Save c17hawke/ac5ad5c603c0d31ef0a6a39941535409 to your computer and use it in GitHub Desktop.
Save c17hawke/ac5ad5c603c0d31ef0a6a39941535409 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"provenance": []
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
},
"language_info": {
"name": "python"
}
},
"cells": [
{
"cell_type": "code",
"source": [
"!pip install openai -q"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "E53fkWEWXZYl",
"outputId": "e5ce8988-d1c9-4d88-9a32-fa3d6df9a44e"
},
"execution_count": 1,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m70.1/70.1 KB\u001b[0m \u001b[31m2.1 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m1.0/1.0 MB\u001b[0m \u001b[31m11.6 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m158.8/158.8 KB\u001b[0m \u001b[31m12.0 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m114.2/114.2 KB\u001b[0m \u001b[31m920.6 kB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m264.6/264.6 KB\u001b[0m \u001b[31m11.5 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m199.2/199.2 KB\u001b[0m \u001b[31m9.3 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
"\u001b[?25h"
]
}
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"id": "BKtKZLt_XBP2"
},
"outputs": [],
"source": [
"import openai"
]
},
{
"cell_type": "code",
"source": [
"import os\n",
"openai.api_key = \"YOUR_API_KEY\""
],
"metadata": {
"id": "qCGibqbvXNew"
},
"execution_count": 6,
"outputs": []
},
{
"cell_type": "code",
"source": [
"MODEL_NAME = \"gpt-3.5-turbo\" # Model used in chatGPT"
],
"metadata": {
"id": "2hh-CsFwPbCf"
},
"execution_count": 7,
"outputs": []
},
{
"cell_type": "code",
"source": [
"OUR_QUES = input(\"Enter your Ques?: \")"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "ON6lXLfAcMiH",
"outputId": "c5d0da6b-f8d5-454d-ce47-c57143015771"
},
"execution_count": 17,
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Enter your Ques?: Say something about hidden technical debt in ML\n"
]
}
]
},
{
"cell_type": "code",
"source": [
"# use ChatCompletion class from openai\n",
"response = openai.ChatCompletion.create(\n",
" model=MODEL_NAME,\n",
" messages=[\n",
" {\"role\": \"user\", \"content\": OUR_QUES} # role: user means we\n",
"]\n",
")\n",
"\n",
"response "
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "tv1rZYFob2kb",
"outputId": "9520bdaa-c6fe-4531-98b9-d38406805205"
},
"execution_count": 18,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"<OpenAIObject chat.completion id=chatcmpl-6tZSGDaFqjbuk3r4UKDMAUJU1fQta at 0x7f16f73542c0> JSON: {\n",
" \"choices\": [\n",
" {\n",
" \"finish_reason\": \"stop\",\n",
" \"index\": 0,\n",
" \"message\": {\n",
" \"content\": \"\\n\\nHidden technical debt in ML refers to the issues that are not visible in the models developed using machine learning algorithms. These can include data biases, poor data quality, or incorrect assumptions made during model building. Such issues can lead to poor performance, unreliable results, or incorrect decision-making. They can also be hard to detect as the models may appear to be functioning effectively, but the underlying issues can cause significant problems in the long run. The key to avoiding hidden technical debt in ML is to thoroughly test and validate the training data, and actively monitor the model's performance to ensure it is producing accurate results.\",\n",
" \"role\": \"assistant\"\n",
" }\n",
" }\n",
" ],\n",
" \"created\": 1678702348,\n",
" \"id\": \"chatcmpl-6tZSGDaFqjbuk3r4UKDMAUJU1fQta\",\n",
" \"model\": \"gpt-3.5-turbo-0301\",\n",
" \"object\": \"chat.completion\",\n",
" \"usage\": {\n",
" \"completion_tokens\": 122,\n",
" \"prompt_tokens\": 15,\n",
" \"total_tokens\": 137\n",
" }\n",
"}"
]
},
"metadata": {},
"execution_count": 18
}
]
},
{
"cell_type": "code",
"source": [
"content = response['choices'][0]['message']['content']\n",
"print(content)"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "_qocxB3iccEC",
"outputId": "620cda1d-f821-4f47-fc0e-4b33e34288c4"
},
"execution_count": 19,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"\n",
"\n",
"Hidden technical debt in ML refers to the issues that are not visible in the models developed using machine learning algorithms. These can include data biases, poor data quality, or incorrect assumptions made during model building. Such issues can lead to poor performance, unreliable results, or incorrect decision-making. They can also be hard to detect as the models may appear to be functioning effectively, but the underlying issues can cause significant problems in the long run. The key to avoiding hidden technical debt in ML is to thoroughly test and validate the training data, and actively monitor the model's performance to ensure it is producing accurate results.\n"
]
}
]
},
{
"cell_type": "code",
"source": [
"OUR_NEXT_QUES = input(\"Enter your Next Ques?: \")"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "VAAlP7b6c1nn",
"outputId": "0b4f010a-0061-4ac2-9184-12a65523e56f"
},
"execution_count": 22,
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Enter your Next Ques?: Can you share the reference paper? for your content\n"
]
}
]
},
{
"cell_type": "code",
"source": [
"# to use the previous context we are using the previos response from the bot here\n",
"response = openai.ChatCompletion.create(\n",
" model=\"gpt-3.5-turbo\",\n",
" messages=[\n",
" {\"role\": \"assistant\", \"content\": content}, # role: assistant means bot\n",
" {\"role\": \"user\", \"content\": OUR_NEXT_QUES} # out new question\n",
"]\n",
")\n",
"\n",
"response "
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "UeNrlURZcPG9",
"outputId": "62697c72-c9b6-495a-8f4f-52389c26ba16"
},
"execution_count": 23,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"<OpenAIObject chat.completion id=chatcmpl-6tZThZzpPHQrgFn14DOUFVTwJb6EE at 0x7f16f73767c0> JSON: {\n",
" \"choices\": [\n",
" {\n",
" \"finish_reason\": \"stop\",\n",
" \"index\": 0,\n",
" \"message\": {\n",
" \"content\": \"I can cite the following papers that discuss the concept of hidden technical debt in machine learning:\\n\\n1. Sculley, D., Holt, G., Golovin, D., Davydov, E., Phillips, T., Ebner, D., ... & Chaudhary, V. (2015). Hidden technical debt in machine learning systems. Google, 19(2015), 250-259.\\n\\n2. Mitchell, M., Wu, S., Zaldivar, A., Barnes, P., & Vasserman, L. (2019). \\u201cModel Cards for Model Reporting.\\u201d Conference on Fairness, Accountability, and Transparency.\\n\\nBoth of these papers discuss the hidden technical debt in machine learning and suggest ways to mitigate it.\",\n",
" \"role\": \"assistant\"\n",
" }\n",
" }\n",
" ],\n",
" \"created\": 1678702437,\n",
" \"id\": \"chatcmpl-6tZThZzpPHQrgFn14DOUFVTwJb6EE\",\n",
" \"model\": \"gpt-3.5-turbo-0301\",\n",
" \"object\": \"chat.completion\",\n",
" \"usage\": {\n",
" \"completion_tokens\": 155,\n",
" \"prompt_tokens\": 143,\n",
" \"total_tokens\": 298\n",
" }\n",
"}"
]
},
"metadata": {},
"execution_count": 23
}
]
},
{
"cell_type": "code",
"source": [
"content = response['choices'][0]['message']['content']\n",
"print(content)"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "XME1yvYebnZP",
"outputId": "de29a254-d721-4296-dd4e-8e52b8bd016c"
},
"execution_count": 24,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"I can cite the following papers that discuss the concept of hidden technical debt in machine learning:\n",
"\n",
"1. Sculley, D., Holt, G., Golovin, D., Davydov, E., Phillips, T., Ebner, D., ... & Chaudhary, V. (2015). Hidden technical debt in machine learning systems. Google, 19(2015), 250-259.\n",
"\n",
"2. Mitchell, M., Wu, S., Zaldivar, A., Barnes, P., & Vasserman, L. (2019). “Model Cards for Model Reporting.” Conference on Fairness, Accountability, and Transparency.\n",
"\n",
"Both of these papers discuss the hidden technical debt in machine learning and suggest ways to mitigate it.\n"
]
}
]
},
{
"cell_type": "code",
"source": [],
"metadata": {
"id": "cVd5ibIAdCwy"
},
"execution_count": null,
"outputs": []
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment