From aff50a7e3963a995c20d52f6cda75acd717adb7e Mon Sep 17 00:00:00 2001 From: Shicheng Liu Date: Sat, 6 Apr 2024 00:15:10 +0000 Subject: [PATCH] move `OpenAI()` inside function --- src/suql/prompt_continuation.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/suql/prompt_continuation.py b/src/suql/prompt_continuation.py index f82e2d1..6e204e1 100644 --- a/src/suql/prompt_continuation.py +++ b/src/suql/prompt_continuation.py @@ -10,7 +10,6 @@ import openai from openai import OpenAI -client = OpenAI() import os import time import traceback @@ -35,14 +34,8 @@ lstrip_blocks=True, line_comment_prefix="#", ) -# # uncomment if using Azure OpenAI -openai.api_type == "open_ai" -# openai.api_type = "azure" -# openai.api_base = "https://ovalopenairesource.openai.azure.com/" -# openai.api_version = "2023-05-15" ENABLE_CACHING = False - if ENABLE_CACHING: import pymongo mongo_client = pymongo.MongoClient("localhost", 27017) @@ -82,6 +75,12 @@ def _model_name_to_cost(model_name: str) -> float: def openai_chat_completion_with_backoff(**kwargs): + client = OpenAI() + # # uncomment if using Azure OpenAI + openai.api_type == "open_ai" + # openai.api_type = "azure" + # openai.api_base = "https://ovalopenairesource.openai.azure.com/" + # openai.api_version = "2023-05-15" global total_cost ret = client.chat.completions.create(**kwargs) num_prompt_tokens = ret.usage.prompt_tokens