Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

base_url not included when request to gpt in SingleTableGPTModel #205

Merged
merged 2 commits into from
Jul 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions sdgx/models/LLM/single_table/gpt.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,12 @@ def _get_openai_setting_from_env(self):
self.openai_API_url = os.getenv("OPENAI_URL")
logger.debug("Get OPENAI_URL from ENV.")

def openai_client(self):
"""
Generate a openai request client.
"""
return openai.OpenAI(api_key=self.openai_API_key, base_url=self.openai_API_url)

def ask_gpt(self, question, model=None):
"""
Sends a question to the GPT model.
Expand All @@ -156,13 +162,11 @@ def ask_gpt(self, question, model=None):
SynthesizerInitError: If the check method fails.
"""
self.check()
api_key = self.openai_API_key
if model:
model = model
else:
model = self.gpt_model
openai.api_key = api_key
client = openai.OpenAI(api_key=api_key)
client = self.openai_client()
logger.info(f"Ask GPT with temperature = {self.temperature}.")
response = client.chat.completions.create(
model=model,
Expand Down
12 changes: 12 additions & 0 deletions tests/models/test_singletable_gpt.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,18 @@ def single_table_gpt_model():
gpt_response_sample_count = [20, 15, 20, 5, 5]


def test_singletable_gpt_model_openapi_setting(single_table_gpt_model: SingleTableGPTModel):
open_ai_key = "sk-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
open_ai_base = "https://api.mock.openai.base.com"
open_ai_model = "gpt-4o-mini"
single_table_gpt_model.set_openAI_settings(open_ai_base, open_ai_key)
single_table_gpt_model.gpt_model = open_ai_model
client = single_table_gpt_model.openai_client()
assert client.base_url == open_ai_base
assert client.api_key == open_ai_key
assert single_table_gpt_model.gpt_model == open_ai_model


def test_singletable_gpt_model(
single_table_gpt_model: SingleTableGPTModel,
raw_data: pd.DataFrame,
Expand Down
Loading