class_docstr: Test Class for OpenAI Integration Testing
class_docstr_tok: ["Test","Class","for","OpenAI","Integration","Testing"]
docstr: Tests normal completions (e.g. text-davinci-003) with bulk joins that are larger than the max batch_size
docstr_tok: ["Tests","normal","completions","(","e.g",".","text-davinci-003",")","with","bulk","joins","that","are","larger","than","the","max","batch_size"]
code: def test_bulk_normal_completion(self, mock_handler):
      """Tests normal completions (e.g. text-davinci-003) with bulk joins that are larger than the max batch_size"""
  
      class MockHandlerStorage:
          def json_get(self, key):
              return {"ft-suffix": {"ft-suffix": "$"}}[
                  key
              ]  # finetuning suffix, irrelevant for this test but needed for init  # noqa
  
          def get_connection_args(self):
              return {"api_key": OPENAI_API_KEY}  # noqa
  
      # create project
      handler = OpenAIHandler(
          model_storage=None,  # the storage does not matter for this test
          engine_storage=MockHandlerStorage(),  # nor does this, but we do need to pass some object due to the init procedure  # noqa
      )
      N = (
          1 + handler.max_batch_size
      )  # get N larger than default batch size
      df = pd.DataFrame.from_dict({"input": ["I feel happy!"] * N})
      self.set_handler(mock_handler, name="pg", tables={"df": df})
      self.run_sql(
          f"""
             create model proj.test_openai_bulk_normal_completion
             predict completion
             using
               engine='openai',
               prompt_template='What is the sentiment of the following phrase? Answer either "positive" or "negative": {{{{input}}}}',
               api_key='{self.get_api_key()}';
          """  # noqa
      )
      self.wait_predictor("proj", "test_openai_bulk_normal_completion")
  
      result_df = self.run_sql(
          """
              SELECT p.completion
              FROM pg.df as t
              JOIN proj.test_openai_bulk_normal_completion as p;
          """
      )
  
      for i in range(N):
          assert "positive" in result_df["completion"].iloc[i].lower()
  
imports: import os
  import time
  import pytest
  import pandas
  from unittest.mock import patch
  from mindsdb_sql import parse_sql
  from mindsdb.integrations.handlers.openai_handler.openai_handler import OpenAIHandler
  from ..executor_test_base import BaseExecutorTest
label_desc: Use image node_id 11 for calling the TestOpenAI obj's underlying member method code with example usage: obj.test_bulk_normal_completion(mock_handler) and returns: dict, dict