Skip to content

Commit

Permalink
Merge pull request AI4Finance-Foundation#128 from pschofield2/patch-1
Browse files Browse the repository at this point in the history
Update prepare_data.ipynb to update openai client api usage
  • Loading branch information
Noir97 authored Nov 28, 2023
2 parents 42d3804 + 8c0a47d commit 6ebe88a
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions fingpt/FinGPT_Forecaster/prepare_data.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@
"import math\n",
"import time\n",
"import json\n",
"import openai\n",
"import random\n",
"import finnhub\n",
"import datasets\n",
"import pandas as pd\n",
"import yfinance as yf\n",
"from datetime import datetime\n",
"from collections import defaultdict\n",
"from datasets import Dataset"
"from datasets import Dataset\n",
"from openai import OpenAI"
]
},
{
Expand All @@ -39,7 +39,7 @@
"\n",
"finnhub_client = finnhub.Client(api_key=\"your finnhub key\")\n",
"\n",
"openai.api_key = 'your openai key'"
"client = OpenAI(api_key = 'your openai key')"
]
},
{
Expand Down Expand Up @@ -1073,7 +1073,7 @@
" cnt = 0\n",
" while cnt < 5:\n",
" try:\n",
" completion = openai.ChatCompletion.create(\n",
" completion = client.chat.completions.create(\n",
" model=\"gpt-4\",\n",
" messages=[\n",
" {\"role\": \"system\", \"content\": SYSTEM_PROMPT},\n",
Expand All @@ -1085,7 +1085,7 @@
" cnt += 1\n",
" print(f'retry cnt {cnt}')\n",
" \n",
" answer = completion['choices'][0]['message']['content'] if cnt < 5 else \"\"\n",
" answer = completion.choices[0].message.content if cnt < 5 else \"\"\n",
" append_to_csv(csv_file, prompt, answer)\n",
" "
]
Expand Down

0 comments on commit 6ebe88a

Please sign in to comment.