{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": { "id": "59qmZbsRTd-i" }, "outputs": [], "source": [ "!pip install --upgrade openai wandb\n", "import openai\n", "import os\n", "import time\n", "import pandas as pd\n", "import numpy as np\n", "import os\n", "import openai\n", "import wandb" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "id": "HTci6Mx3TWOi" }, "outputs": [], "source": [ "key = ## OpenAI Key##\n", "openai.api_key = key" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "id": "quD6tdjtUMh2" }, "outputs": [], "source": [ "diag_q = pd.read_excel('file1.xlsx',sheet_name= \"Sheet1\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "id": "pArfpDmJUXqW" }, "outputs": [], "source": [ "diag_q['CoT_response'] = np.nan\n", "diag_q['DR_response'] = np.nan" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "id": "5mDOCN-TWLWy" }, "outputs": [], "source": [ "for i in range(310):\n", " print(i)\n", " message=[{\"role\": \"user\", \"content\": diag_q['CoT'][i]}]\n", " response = openai.ChatCompletion.create(\n", " model=\"gpt-4\",\n", " messages = message,\n", " temperature=0,\n", " max_tokens=1000,\n", " frequency_penalty=0.0\n", " )\n", " diag_q['CoT_response'][i] = response\n", " time.sleep(15)\n", "\n", " message=[{\"role\": \"user\", \"content\": diag_q['DR'][i]}]\n", " response = openai.ChatCompletion.create(\n", " model=\"gpt-4\",\n", " messages = message,\n", " temperature=0,\n", " max_tokens=1000,\n", " frequency_penalty=0.0\n", " )\n", " diag_q['DR_response'][i] = response\n", "\n", " time.sleep(15)\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "id": "DFKtvlUuFV_X" }, "outputs": [], "source": [ "diag_q.to_csv('results.csv', index=False)" ] } ], "metadata": { "colab": { "provenance": [] }, "kernelspec": { "display_name": "Python 3", "name": "python3" }, "language_info": { "name": "python" } }, "nbformat": 4, "nbformat_minor": 0 }