phyloforfun commited on
Commit
cac5f9c
1 Parent(s): 5bd4a83
vouchervision/utils_VoucherVision.py CHANGED
@@ -98,18 +98,39 @@ class VoucherVision():
98
  self.logger.info(f' Model name passed to API --> {self.model_name}')
99
  self.logger.info(f' API access token is found in PRIVATE_DATA.yaml --> {self.has_key}')
100
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
101
  def map_API_options(self):
102
- self.chat_version = self.cfg['leafmachine']['LLM_version']
 
 
 
 
 
 
103
  version_mapping = {
104
- 'GPT 4': ('OpenAI GPT 4', False, 'GPT_4', self.has_key_openai),
105
- 'GPT 3.5': ('OpenAI GPT 3.5', False, 'GPT_3_5', self.has_key_openai),
106
- 'Azure GPT 3.5': ('(Azure) OpenAI GPT 3.5', True, 'Azure_GPT_3_5', self.has_key_azure_openai),
107
- 'Azure GPT 4': ('(Azure) OpenAI GPT 4', True, 'Azure_GPT_4', self.has_key_azure_openai),
108
- 'PaLM 2': ('Google PaLM 2', None, None, self.has_key_palm2)
109
  }
 
110
  if self.chat_version not in version_mapping:
111
- supported_LLMs = ", ".join(version_mapping.keys())
112
- raise Exception(f"Unsupported LLM: {self.chat_version}. Requires one of: {supported_LLMs}")
113
 
114
  self.version_name, self.is_azure, self.model_name, self.has_key = version_mapping[self.chat_version]
115
 
@@ -367,6 +388,27 @@ class VoucherVision():
367
  # save the workbook
368
  wb.save(path_transcription)
369
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
370
 
371
  def set_API_keys(self):
372
  # Access secrets directly from the environment
@@ -391,6 +433,9 @@ class VoucherVision():
391
  from google.cloud import vision
392
  self.client = vision.ImageAnnotatorClient(credentials=google_credentials)
393
 
 
 
 
394
  if self.has_key_palm2:
395
  os.environ['PALM'] = palm_api_key
396
  palm.configure(api_key=palm_api_key)
 
98
  self.logger.info(f' Model name passed to API --> {self.model_name}')
99
  self.logger.info(f' API access token is found in PRIVATE_DATA.yaml --> {self.has_key}')
100
 
101
+ # def map_API_options(self):
102
+ # self.chat_version = self.cfg['leafmachine']['LLM_version']
103
+ # version_mapping = {
104
+ # 'GPT 4': ('OpenAI GPT 4', False, 'GPT_4', self.has_key_openai),
105
+ # 'GPT 3.5': ('OpenAI GPT 3.5', False, 'GPT_3_5', self.has_key_openai),
106
+ # 'Azure GPT 3.5': ('(Azure) OpenAI GPT 3.5', True, 'Azure_GPT_3_5', self.has_key_azure_openai),
107
+ # 'Azure GPT 4': ('(Azure) OpenAI GPT 4', True, 'Azure_GPT_4', self.has_key_azure_openai),
108
+ # 'PaLM 2': ('Google PaLM 2', None, None, self.has_key_palm2)
109
+ # }
110
+ # if self.chat_version not in version_mapping:
111
+ # supported_LLMs = ", ".join(version_mapping.keys())
112
+ # raise Exception(f"Unsupported LLM: {self.chat_version}. Requires one of: {supported_LLMs}")
113
+
114
+ # self.version_name, self.is_azure, self.model_name, self.has_key = version_mapping[self.chat_version]
115
  def map_API_options(self):
116
+ self.chat_version = self.cfg['leafmachine']['LLM_version'] # Replace with your env variable for LLM version if needed
117
+
118
+ # Assuming you have set your environment variables for each key like 'OPENAI_API_KEY', 'AZURE_API_KEY', 'PALM_API_KEY'
119
+ openai_api_key = os.getenv('OPENAI_API_KEY')
120
+ azure_api_key = os.getenv('AZURE_API_KEY')
121
+ palm_api_key = os.getenv('PALM_API_KEY')
122
+
123
  version_mapping = {
124
+ 'GPT 4': ('OpenAI GPT 4', False, 'GPT_4', bool(openai_api_key)),
125
+ 'GPT 3.5': ('OpenAI GPT 3.5', False, 'GPT_3_5', bool(openai_api_key)),
126
+ 'Azure GPT 3.5': ('(Azure) OpenAI GPT 3.5', True, 'Azure_GPT_3_5', bool(azure_api_key)),
127
+ 'Azure GPT 4': ('(Azure) OpenAI GPT 4', True, 'Azure_GPT_4', bool(azure_api_key)),
128
+ 'PaLM 2': ('Google PaLM 2', None, None, bool(palm_api_key))
129
  }
130
+
131
  if self.chat_version not in version_mapping:
132
+ supported_llms = ", ".join(version_mapping.keys())
133
+ raise Exception(f"Unsupported LLM: {self.chat_version}. Requires one of: {supported_llms}")
134
 
135
  self.version_name, self.is_azure, self.model_name, self.has_key = version_mapping[self.chat_version]
136
 
 
388
  # save the workbook
389
  wb.save(path_transcription)
390
 
391
+ def configure_azure_llm(self):
392
+ # Access the secrets from the environment
393
+ azure_api_version = os.getenv('AZURE_API_VERSION')
394
+ azure_api_key = os.getenv('AZURE_API_KEY')
395
+ azure_api_base = os.getenv('AZURE_API_BASE')
396
+ azure_organization = os.getenv('AZURE_ORGANIZATION')
397
+ azure_api_type = os.getenv('AZURE_API_TYPE')
398
+ azure_deployment_name = os.getenv('AZURE_DEPLOYMENT_NAME')
399
+
400
+ # Check if all required Azure configurations are present
401
+ if azure_api_version and azure_api_key and azure_api_base and azure_organization and azure_api_type and azure_deployment_name:
402
+ self.llm = AzureChatOpenAI(
403
+ deployment_name=azure_deployment_name,
404
+ openai_api_version=azure_api_version,
405
+ openai_api_key=azure_api_key,
406
+ openai_api_base=azure_api_base,
407
+ openai_organization=azure_organization,
408
+ openai_api_type=azure_api_type
409
+ )
410
+ else:
411
+ raise ValueError("Missing Azure configuration in environment variables.")
412
 
413
  def set_API_keys(self):
414
  # Access secrets directly from the environment
 
433
  from google.cloud import vision
434
  self.client = vision.ImageAnnotatorClient(credentials=google_credentials)
435
 
436
+ if os.getenv('AZURE_API_KEY') is not None:
437
+ self.configure_azure_llm()
438
+
439
  if self.has_key_palm2:
440
  os.environ['PALM'] = palm_api_key
441
  palm.configure(api_key=palm_api_key)