pymetadataeditor 0.3.1__tar.gz → 0.3.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pymetadataeditor
3
- Version: 0.3.1
3
+ Version: 0.3.2
4
4
  Summary: Metadata Editor client for python
5
5
  License: MIT
6
6
  Author: Gordon Blackadder
@@ -12,7 +12,7 @@ Classifier: Programming Language :: Python :: 3.11
12
12
  Classifier: Programming Language :: Python :: 3.12
13
13
  Requires-Dist: markitdown (>=0.0.1a3,<0.0.2)
14
14
  Requires-Dist: metadataschemas (>=0.1.3,<0.2.0)
15
- Requires-Dist: openai (>=1.59.4,<2.0.0)
15
+ Requires-Dist: openai (>=2.8.0,<3.0.0)
16
16
  Requires-Dist: pandas (>=2.2.2,<3.0.0)
17
17
  Requires-Dist: pydantic (>=2.7.4,<3.0.0)
18
18
  Requires-Dist: requests (>=2.32.3,<3.0.0)
@@ -702,7 +702,7 @@ class MetadataEditor:
702
702
  tokenizer_model="o200k_base",
703
703
  max_tokens=128_000,
704
704
  llm_base_url: Optional[str] = None,
705
- azure_llm_base_url: Optional[str] = None,
705
+ azure_deployment_name: Optional[str] = None,
706
706
  ) -> Union[BaseModel, Dict, str]:
707
707
  """Automatically generate *draft* metadata for a project based on local files or web pages.
708
708
 
@@ -739,11 +739,13 @@ class MetadataEditor:
739
739
  max_tokens (int): The maximum number of tokens to use when sending the content to OpenAI.
740
740
  Defaults to 128_000, which has been the typical maximum for the 4o model.
741
741
  llm_base_url (Optional[str]): The base URL for the LLM API. If None, the default URL is used which
742
- sends the request to OpenAI. This argument is ignored if an azure_llm_base_url is provided.
743
- azure_llm_base_url (Optional[str]): The base URL for the Azure LLM API. Typically used when an organization
744
- has its own deployment of an LLM model, possibly for privacy reasons. The Azure endpoint will be used
745
- even if a llm_base_url is provided. If None, then the llm_base_url endpoint is used. If
746
- that's also None, then OpenAI is used.
742
+ sends the request to OpenAI. Alternatively, this can be the base URL for a local LLM instance such as
743
+ Ollama or a private deployment of an LLM model. If using Azure OpenAI, this should be the Azure
744
+ endpoint URL (eg "https://my-azure-openai-resource.openai.azure.com/") and the azure_deployment_name
745
+ parameter should also be set.
746
+ azure_deployment_name (Optional[str]): Used when an organization has its own deployment of an LLM model in
747
+ Azure, possibly for privacy reasons. Be sure to provide the llm_base_url parameter as well which should
748
+ be the Azure endpoint URL.
747
749
 
748
750
  Returns:
749
751
  (Union[BaseModel, Dict, str]): If mode == 'dict', a dictionary is returned. If mode == 'pydantic', a
@@ -785,7 +787,8 @@ class MetadataEditor:
785
787
  metadata_producer_organization="My Organization",
786
788
  filename="output.xlsx",
787
789
  title="My Metadata",
788
- azure_llm_base_url="https://my-azure-openai-resource.openai.azure.com/",
790
+ llm_base_url="https://my-azure-openai-resource.openai.azure.com/",
791
+ azure_deployment_name="my-llm-deployment"
789
792
  )
790
793
  ```
791
794
  """
@@ -795,10 +798,15 @@ class MetadataEditor:
795
798
  metadata_type_or_template_uid, apply_template_rules=False
796
799
  )
797
800
  enc = tiktoken.get_encoding(tokenizer_model)
798
- if azure_llm_base_url is None:
801
+ if azure_deployment_name is None:
799
802
  client = OpenAI(api_key=llm_api_key, base_url=llm_base_url)
800
803
  else:
801
- client = AzureOpenAI(api_key=llm_api_key, base_url=azure_llm_base_url, api_version="2024-10-01")
804
+ client = AzureOpenAI(
805
+ api_key=llm_api_key,
806
+ azure_endpoint=llm_base_url,
807
+ azure_deployment=azure_deployment_name,
808
+ api_version="2024-10-01",
809
+ )
802
810
 
803
811
  system_prompt = f"You are an expert on producing {metadata_type} documentation. "
804
812
  system_prompt += (
@@ -838,9 +846,7 @@ class MetadataEditor:
838
846
  print(f"Reading {doc}, running token count is {num_tokens}")
839
847
  messages += user_message
840
848
 
841
- endpoint_name = (
842
- azure_llm_base_url if azure_llm_base_url is not None else "OpenAI" if llm_base_url is None else llm_base_url
843
- )
849
+ endpoint_name = llm_base_url if llm_base_url is not None else "OpenAI"
844
850
  print(f"Sending to {endpoint_name}, this may take a few minutes...")
845
851
  try:
846
852
  completion = client.beta.chat.completions.parse(
@@ -885,7 +891,7 @@ class MetadataEditor:
885
891
  tokenizer_model="o200k_base",
886
892
  max_tokens=128_000,
887
893
  llm_base_url: Optional[str] = None,
888
- azure_llm_base_url: Optional[str] = None,
894
+ azure_deployment_name: Optional[str] = None,
889
895
  ) -> Union[BaseModel, Dict, str]:
890
896
  """Augment existing metadata with information from files or web pages.
891
897
 
@@ -914,11 +920,13 @@ class MetadataEditor:
914
920
  max_tokens (int): The maximum number of tokens to use when sending the content to OpenAI.
915
921
  Defaults to 128_000, which has been the typical maximum for the 4o model.
916
922
  llm_base_url (Optional[str]): The base URL for the LLM API. If None, the default URL is used which
917
- sends the request to OpenAI.
918
- azure_llm_base_url (Optional[str]): The base URL for the Azure LLM API. Typically used when an organization
919
- has its own deployment of an LLM model, possibly for privacy reasons. The Azure endpoint will be used
920
- even if a llm_base_url is provided. If None, then the llm_base_url endpoint is used. If
921
- that's also None, then OpenAI is used.
923
+ sends the request to OpenAI. Alternatively, this can be the base URL for a local LLM instance such as
924
+ Ollama or a private deployment of an LLM model. If using Azure OpenAI, this should be the Azure
925
+ endpoint URL (eg "https://my-azure-openai-resource.openai.azure.com/") and the azure_deployment_name
926
+ parameter should also be set.
927
+ azure_deployment_name (Optional[str]): Used when an organization has its own deployment of an LLM model in
928
+ Azure, possibly for privacy reasons. Be sure to provide the llm_base_url parameter as well which should
929
+ be the Azure endpoint URL.
922
930
 
923
931
  Returns:
924
932
  Union[BaseModel, Dict, str]: The augmented metadata.
@@ -945,7 +953,8 @@ class MetadataEditor:
945
953
  output_mode="pydantic",
946
954
  metadata_producer_organization="My Organization",
947
955
  prefix="<AI>",
948
- azure_llm_base_url="https://my-azure-openai-resource.openai.azure.com/",
956
+ llm_base_url="https://my-azure-openai-resource.openai.azure.com/",
957
+ azure_deployment_name="my-llm-deployment"
949
958
  )
950
959
  ```
951
960
  """
@@ -1017,7 +1026,7 @@ class MetadataEditor:
1017
1026
  tokenizer_model=tokenizer_model,
1018
1027
  max_tokens=max_tokens,
1019
1028
  llm_base_url=llm_base_url,
1020
- azure_llm_base_url=azure_llm_base_url,
1029
+ azure_deployment_name=azure_deployment_name,
1021
1030
  )
1022
1031
 
1023
1032
  if new_metadata is None or len(new_metadata) == 0:
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "pymetadataeditor"
3
- version = "0.3.1"
3
+ version = "0.3.2"
4
4
  description = "Metadata Editor client for python"
5
5
  authors = ["Gordon Blackadder <gblackadder@worldbank.org>"]
6
6
  readme = "README.md"
@@ -12,7 +12,7 @@ requests = "^2.32.3"
12
12
  urllib3 = "^2.2.2" # earlier versions have known security issues
13
13
  pandas = "^2.2.2"
14
14
  pydantic = "^2.7.4"
15
- openai = "^1.59.4"
15
+ openai = "^2.8.0"
16
16
  tiktoken = "^0.8.0"
17
17
  markitdown = "^0.0.1a3"
18
18
  metadataschemas = "^0.1.3"