gllm-inference-binary 0.5.9b1__cp312-cp312-macosx_11_0_universal2.macosx_13_0_arm64.whl

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.

Potentially problematic release.


This version of gllm-inference-binary might be problematic. Click here for more details.

Files changed (105) hide show
  1. gllm_inference/__init__.pyi +0 -0
  2. gllm_inference/builder/__init__.pyi +6 -0
  3. gllm_inference/builder/build_em_invoker.pyi +137 -0
  4. gllm_inference/builder/build_lm_invoker.pyi +161 -0
  5. gllm_inference/builder/build_lm_request_processor.pyi +93 -0
  6. gllm_inference/builder/build_output_parser.pyi +29 -0
  7. gllm_inference/catalog/__init__.pyi +4 -0
  8. gllm_inference/catalog/catalog.pyi +121 -0
  9. gllm_inference/catalog/lm_request_processor_catalog.pyi +112 -0
  10. gllm_inference/catalog/prompt_builder_catalog.pyi +82 -0
  11. gllm_inference/constants.pyi +10 -0
  12. gllm_inference/em_invoker/__init__.pyi +10 -0
  13. gllm_inference/em_invoker/azure_openai_em_invoker.pyi +88 -0
  14. gllm_inference/em_invoker/bedrock_em_invoker.pyi +106 -0
  15. gllm_inference/em_invoker/em_invoker.pyi +90 -0
  16. gllm_inference/em_invoker/google_em_invoker.pyi +129 -0
  17. gllm_inference/em_invoker/langchain/__init__.pyi +3 -0
  18. gllm_inference/em_invoker/langchain/em_invoker_embeddings.pyi +84 -0
  19. gllm_inference/em_invoker/langchain_em_invoker.pyi +46 -0
  20. gllm_inference/em_invoker/openai_compatible_em_invoker.pyi +96 -0
  21. gllm_inference/em_invoker/openai_em_invoker.pyi +90 -0
  22. gllm_inference/em_invoker/schema/__init__.pyi +0 -0
  23. gllm_inference/em_invoker/schema/bedrock.pyi +22 -0
  24. gllm_inference/em_invoker/schema/google.pyi +9 -0
  25. gllm_inference/em_invoker/schema/langchain.pyi +5 -0
  26. gllm_inference/em_invoker/schema/openai.pyi +7 -0
  27. gllm_inference/em_invoker/schema/openai_compatible.pyi +7 -0
  28. gllm_inference/em_invoker/schema/twelvelabs.pyi +17 -0
  29. gllm_inference/em_invoker/schema/voyage.pyi +15 -0
  30. gllm_inference/em_invoker/twelevelabs_em_invoker.pyi +101 -0
  31. gllm_inference/em_invoker/voyage_em_invoker.pyi +104 -0
  32. gllm_inference/exceptions/__init__.pyi +4 -0
  33. gllm_inference/exceptions/error_parser.pyi +41 -0
  34. gllm_inference/exceptions/exceptions.pyi +132 -0
  35. gllm_inference/exceptions/provider_error_map.pyi +23 -0
  36. gllm_inference/lm_invoker/__init__.pyi +12 -0
  37. gllm_inference/lm_invoker/anthropic_lm_invoker.pyi +275 -0
  38. gllm_inference/lm_invoker/azure_openai_lm_invoker.pyi +252 -0
  39. gllm_inference/lm_invoker/bedrock_lm_invoker.pyi +234 -0
  40. gllm_inference/lm_invoker/datasaur_lm_invoker.pyi +166 -0
  41. gllm_inference/lm_invoker/google_lm_invoker.pyi +317 -0
  42. gllm_inference/lm_invoker/langchain_lm_invoker.pyi +260 -0
  43. gllm_inference/lm_invoker/litellm_lm_invoker.pyi +248 -0
  44. gllm_inference/lm_invoker/lm_invoker.pyi +152 -0
  45. gllm_inference/lm_invoker/openai_compatible_lm_invoker.pyi +265 -0
  46. gllm_inference/lm_invoker/openai_lm_invoker.pyi +362 -0
  47. gllm_inference/lm_invoker/schema/__init__.pyi +0 -0
  48. gllm_inference/lm_invoker/schema/anthropic.pyi +50 -0
  49. gllm_inference/lm_invoker/schema/bedrock.pyi +53 -0
  50. gllm_inference/lm_invoker/schema/datasaur.pyi +12 -0
  51. gllm_inference/lm_invoker/schema/google.pyi +24 -0
  52. gllm_inference/lm_invoker/schema/langchain.pyi +23 -0
  53. gllm_inference/lm_invoker/schema/openai.pyi +91 -0
  54. gllm_inference/lm_invoker/schema/openai_compatible.pyi +60 -0
  55. gllm_inference/lm_invoker/schema/xai.pyi +31 -0
  56. gllm_inference/lm_invoker/xai_lm_invoker.pyi +305 -0
  57. gllm_inference/model/__init__.pyi +9 -0
  58. gllm_inference/model/em/__init__.pyi +0 -0
  59. gllm_inference/model/em/google_em.pyi +16 -0
  60. gllm_inference/model/em/openai_em.pyi +15 -0
  61. gllm_inference/model/em/twelvelabs_em.pyi +13 -0
  62. gllm_inference/model/em/voyage_em.pyi +20 -0
  63. gllm_inference/model/lm/__init__.pyi +0 -0
  64. gllm_inference/model/lm/anthropic_lm.pyi +20 -0
  65. gllm_inference/model/lm/google_lm.pyi +17 -0
  66. gllm_inference/model/lm/openai_lm.pyi +27 -0
  67. gllm_inference/output_parser/__init__.pyi +3 -0
  68. gllm_inference/output_parser/json_output_parser.pyi +60 -0
  69. gllm_inference/output_parser/output_parser.pyi +27 -0
  70. gllm_inference/prompt_builder/__init__.pyi +3 -0
  71. gllm_inference/prompt_builder/prompt_builder.pyi +56 -0
  72. gllm_inference/prompt_formatter/__init__.pyi +7 -0
  73. gllm_inference/prompt_formatter/agnostic_prompt_formatter.pyi +49 -0
  74. gllm_inference/prompt_formatter/huggingface_prompt_formatter.pyi +55 -0
  75. gllm_inference/prompt_formatter/llama_prompt_formatter.pyi +59 -0
  76. gllm_inference/prompt_formatter/mistral_prompt_formatter.pyi +53 -0
  77. gllm_inference/prompt_formatter/openai_prompt_formatter.pyi +35 -0
  78. gllm_inference/prompt_formatter/prompt_formatter.pyi +30 -0
  79. gllm_inference/request_processor/__init__.pyi +4 -0
  80. gllm_inference/request_processor/lm_request_processor.pyi +101 -0
  81. gllm_inference/request_processor/uses_lm_mixin.pyi +130 -0
  82. gllm_inference/schema/__init__.pyi +14 -0
  83. gllm_inference/schema/attachment.pyi +88 -0
  84. gllm_inference/schema/code_exec_result.pyi +14 -0
  85. gllm_inference/schema/config.pyi +15 -0
  86. gllm_inference/schema/enums.pyi +29 -0
  87. gllm_inference/schema/lm_output.pyi +36 -0
  88. gllm_inference/schema/message.pyi +52 -0
  89. gllm_inference/schema/model_id.pyi +147 -0
  90. gllm_inference/schema/reasoning.pyi +15 -0
  91. gllm_inference/schema/token_usage.pyi +75 -0
  92. gllm_inference/schema/tool_call.pyi +14 -0
  93. gllm_inference/schema/tool_result.pyi +11 -0
  94. gllm_inference/schema/type_alias.pyi +11 -0
  95. gllm_inference/utils/__init__.pyi +5 -0
  96. gllm_inference/utils/io_utils.pyi +26 -0
  97. gllm_inference/utils/langchain.pyi +30 -0
  98. gllm_inference/utils/validation.pyi +12 -0
  99. gllm_inference.build/.gitignore +1 -0
  100. gllm_inference.cpython-312-darwin.so +0 -0
  101. gllm_inference.pyi +123 -0
  102. gllm_inference_binary-0.5.9b1.dist-info/METADATA +71 -0
  103. gllm_inference_binary-0.5.9b1.dist-info/RECORD +105 -0
  104. gllm_inference_binary-0.5.9b1.dist-info/WHEEL +6 -0
  105. gllm_inference_binary-0.5.9b1.dist-info/top_level.txt +1 -0
File without changes
@@ -0,0 +1,6 @@
1
+ from gllm_inference.builder.build_em_invoker import build_em_invoker as build_em_invoker
2
+ from gllm_inference.builder.build_lm_invoker import build_lm_invoker as build_lm_invoker
3
+ from gllm_inference.builder.build_lm_request_processor import build_lm_request_processor as build_lm_request_processor
4
+ from gllm_inference.builder.build_output_parser import build_output_parser as build_output_parser
5
+
6
+ __all__ = ['build_em_invoker', 'build_lm_invoker', 'build_lm_request_processor', 'build_output_parser']
@@ -0,0 +1,137 @@
1
+ from _typeshed import Incomplete
2
+ from gllm_inference.em_invoker import AzureOpenAIEMInvoker as AzureOpenAIEMInvoker, BedrockEMInvoker as BedrockEMInvoker, GoogleEMInvoker as GoogleEMInvoker, LangChainEMInvoker as LangChainEMInvoker, OpenAICompatibleEMInvoker as OpenAICompatibleEMInvoker, OpenAIEMInvoker as OpenAIEMInvoker, TwelveLabsEMInvoker as TwelveLabsEMInvoker, VoyageEMInvoker as VoyageEMInvoker
3
+ from gllm_inference.em_invoker.em_invoker import BaseEMInvoker as BaseEMInvoker
4
+ from gllm_inference.schema.model_id import ModelId as ModelId, ModelProvider as ModelProvider
5
+ from typing import Any
6
+
7
+ PROVIDER_TO_EM_INVOKER_MAP: dict[str, type[BaseEMInvoker]]
8
+ logger: Incomplete
9
+
10
+ class Key:
11
+ """Defines valid keys in the config."""
12
+ ACCESS_KEY_ID: str
13
+ API_KEY: str
14
+ AZURE_DEPLOYMENT: str
15
+ AZURE_ENDPOINT: str
16
+ BASE_URL: str
17
+ CREDENTIALS_PATH: str
18
+ MODEL_KWARGS: str
19
+ MODEL_NAME: str
20
+ MODEL_CLASS_PATH: str
21
+ SECRET_ACCESS_KEY: str
22
+
23
+ def build_em_invoker(model_id: str | ModelId, credentials: str | dict[str, Any] | None = None, config: dict[str, Any] | None = None) -> BaseEMInvoker:
24
+ '''Build an embedding model invoker based on the provided configurations.
25
+
26
+ Args:
27
+ model_id (str | ModelId): The model id, can either be a ModelId instance or a string in the following format:
28
+ 1. For `azure-openai` provider: `azure-openai/azure-endpoint:azure-deployment`.
29
+ 2. For `openai-compatible` provider: `openai-compatible/base-url:model-name`.
30
+ 3. For `langchain` provider: `langchain/<package>.<class>:model-name`.
31
+ 4. For other providers: `provider/model-name`.
32
+ credentials (str | dict[str, Any] | None, optional): The credentials for the language model. Can either be:
33
+ 1. An API key.
34
+ 2. A path to a credentials JSON file, currently only supported for Google Vertex AI.
35
+ 3. A dictionary of credentials, currently only supported for LangChain.
36
+ Defaults to None, in which case the credentials will be loaded from the appropriate environment variables.
37
+ config (dict[str, Any] | None, optional): Additional configuration for the embedding model. Defaults to None.
38
+
39
+ Returns:
40
+ BaseEMInvoker: The initialized embedding model invoker.
41
+
42
+ Raises:
43
+ ValueError: If the provider is invalid.
44
+
45
+ Usage examples:
46
+ # Using Bedrock
47
+ ```python
48
+ em_invoker = build_em_invoker(
49
+ model_id="bedrock/cohere.embed-english-v3",
50
+ credentials={
51
+ "access_key_id": "Abc123...",
52
+ "secret_access_key": "Xyz123...",
53
+ },
54
+ )
55
+ ```
56
+ The credentials can also be provided through the `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY`
57
+ environment variables.
58
+
59
+ # Using Google Gen AI (via API key)
60
+ ```python
61
+ em_invoker = build_em_invoker(
62
+ model_id="google/text-embedding-004",
63
+ credentials="AIzaSyD..."
64
+ )
65
+ ```
66
+ The credentials can also be provided through the `GOOGLE_API_KEY` environment variable.
67
+
68
+ # Using Google Vertex AI (via service account)
69
+ ```python
70
+ em_invoker = build_em_invoker(
71
+ model_id="google/text-embedding-004",
72
+ credentials="/path/to/google-credentials.json"
73
+ )
74
+ ```
75
+ Providing credentials through environment variable is not supported for Google Vertex AI.
76
+
77
+ # Using OpenAI
78
+ ```python
79
+ em_invoker = build_em_invoker(
80
+ model_id="openai/text-embedding-3-small",
81
+ credentials="sk-..."
82
+ )
83
+ ```
84
+ The credentials can also be provided through the `OPENAI_API_KEY` environment variable.
85
+
86
+ # Using Azure OpenAI
87
+ ```python
88
+ em_invoker = build_em_invoker(
89
+ model_id="azure-openai/https://my-resource.openai.azure.com/openai/v1:my-deployment",
90
+ credentials="azure-api-key"
91
+ )
92
+ ```
93
+ The credentials can also be provided through the `AZURE_OPENAI_API_KEY` environment variable.
94
+
95
+ # Using OpenAI Compatible endpoint (e.g. Text Embeddings Inference)
96
+ ```python
97
+ em_invoker = build_em_invoker(
98
+ model_id="openai-compatible/https://my-text-embeddings-inference-endpoint.com:model-name",
99
+ credentials="tei-api-key"
100
+ )
101
+ ```
102
+ The credentials can also be provided through the `OPENAI_API_KEY` environment variable.
103
+
104
+ # Using TwelveLabs
105
+ ```python
106
+ em_invoker = build_em_invoker(
107
+ model_id="twelvelabs/Marengo-retrieval-2.7",
108
+ credentials="tlk_..."
109
+ )
110
+ ```
111
+ The credentials can also be provided through the `TWELVELABS_API_KEY` environment variable.
112
+
113
+ # Using Voyage
114
+ ```python
115
+ em_invoker = build_em_invoker(
116
+ model_id="voyage/voyage-3.5-lite",
117
+ credentials="sk-..."
118
+ )
119
+ ```
120
+ The credentials can also be provided through the `VOYAGE_API_KEY` environment variable.
121
+
122
+ # Using LangChain
123
+ ```python
124
+ em_invoker = build_em_invoker(
125
+ model_id="langchain/langchain_openai.OpenAIEmbeddings:text-embedding-3-small",
126
+ credentials={"api_key": "sk-..."}
127
+ )
128
+ ```
129
+ The credentials can also be provided through various environment variables depending on the
130
+ LangChain module being used. For the list of supported providers and the supported environment
131
+ variables credentials, please refer to the following page:
132
+ https://python.langchain.com/docs/integrations/text_embedding/
133
+
134
+ Security warning:
135
+ Please provide the EM invoker credentials ONLY to the `credentials` parameter. Do not put any kind of
136
+ credentials in the `config` parameter as the content of the `config` parameter will be logged.
137
+ '''
@@ -0,0 +1,161 @@
1
+ from _typeshed import Incomplete
2
+ from gllm_inference.lm_invoker import AnthropicLMInvoker as AnthropicLMInvoker, AzureOpenAILMInvoker as AzureOpenAILMInvoker, BedrockLMInvoker as BedrockLMInvoker, DatasaurLMInvoker as DatasaurLMInvoker, GoogleLMInvoker as GoogleLMInvoker, LangChainLMInvoker as LangChainLMInvoker, LiteLLMLMInvoker as LiteLLMLMInvoker, OpenAICompatibleLMInvoker as OpenAICompatibleLMInvoker, OpenAILMInvoker as OpenAILMInvoker, XAILMInvoker as XAILMInvoker
3
+ from gllm_inference.lm_invoker.lm_invoker import BaseLMInvoker as BaseLMInvoker
4
+ from gllm_inference.schema.model_id import ModelId as ModelId, ModelProvider as ModelProvider
5
+ from typing import Any
6
+
7
+ PROVIDER_TO_LM_INVOKER_MAP: dict[str, type[BaseLMInvoker]]
8
+ logger: Incomplete
9
+
10
+ class Key:
11
+ """Defines valid keys in the config."""
12
+ ACCESS_KEY_ID: str
13
+ API_KEY: str
14
+ AZURE_DEPLOYMENT: str
15
+ AZURE_ENDPOINT: str
16
+ BASE_URL: str
17
+ CREDENTIALS_PATH: str
18
+ MODEL_ID: str
19
+ MODEL_KWARGS: str
20
+ MODEL_NAME: str
21
+ MODEL_CLASS_PATH: str
22
+ SECRET_ACCESS_KEY: str
23
+
24
+ def build_lm_invoker(model_id: str | ModelId, credentials: str | dict[str, Any] | None = None, config: dict[str, Any] | None = None) -> BaseLMInvoker:
25
+ '''Build a language model invoker based on the provided configurations.
26
+
27
+ Args:
28
+ model_id (str | ModelId): The model id, can either be a ModelId instance or a string in the following format:
29
+ 1. For `azure-openai` provider: `azure-openai/azure-endpoint:azure-deployment`.
30
+ 2. For `openai-compatible` provider: `openai-compatible/base-url:model-name`.
31
+ 3. For `langchain` provider: `langchain/<package>.<class>:model-name`.
32
+ 4. For `litellm` provider: `litellm/provider/model-name`.
33
+ 5. For `datasaur` provider: `datasaur/deployment-id:model-name`.
34
+ 6. For other providers: `provider/model-name`.
35
+ credentials (str | dict[str, Any] | None, optional): The credentials for the language model. Can either be:
36
+ 1. An API key.
37
+ 2. A path to a credentials JSON file, currently only supported for Google Vertex AI.
38
+ 3. A dictionary of credentials, currently supported for Bedrock and LangChain.
39
+ Defaults to None, in which case the credentials will be loaded from the appropriate environment variables.
40
+ config (dict[str, Any] | None, optional): Additional configuration for the language model. Defaults to None.
41
+
42
+ Returns:
43
+ BaseLMInvoker: The initialized language model invoker.
44
+
45
+ Raises:
46
+ ValueError: If the provider is invalid.
47
+
48
+ Usage examples:
49
+ # Using Anthropic
50
+ ```python
51
+ lm_invoker = build_lm_invoker(
52
+ model_id="anthropic/claude-3-5-sonnet-latest",
53
+ credentials="sk-ant-api03-..."
54
+ )
55
+ ```
56
+ The credentials can also be provided through the `ANTHROPIC_API_KEY` environment variable.
57
+
58
+ # Using Bedrock
59
+ ```python
60
+ lm_invoker = build_lm_invoker(
61
+ model_id="bedrock/us.anthropic.claude-sonnet-4-20250514-v1:0",
62
+ credentials={
63
+ "access_key_id": "Abc123...",
64
+ "secret_access_key": "Xyz123...",
65
+ },
66
+ )
67
+ ```
68
+ The credentials can also be provided through the `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY`
69
+ environment variables.
70
+
71
+ # Using Datasaur LLM Projects Deployment API
72
+ ```python
73
+ lm_invoker = build_lm_invoker(
74
+ model_id="datasaur/https://deployment.datasaur.ai/api/deployment/teamId/deploymentId/",
75
+ credentials="..."
76
+ )
77
+ ```
78
+ The credentials can also be provided through the `DATASAUR_API_KEY` environment variable.
79
+
80
+ # Using Google Gen AI (via API key)
81
+ ```python
82
+ lm_invoker = build_lm_invoker(
83
+ model_id="google/gemini-1.5-flash-latest",
84
+ credentials="AIzaSyD..."
85
+ )
86
+ ```
87
+ The credentials can also be provided through the `GOOGLE_API_KEY` environment variable.
88
+
89
+ # Using Google Vertex AI (via service account)
90
+ ```python
91
+ lm_invoker = build_lm_invoker(
92
+ model_id="google/gemini-1.5-flash",
93
+ credentials="/path/to/google-credentials.json"
94
+ )
95
+ ```
96
+ Providing credentials through environment variable is not supported for Google Vertex AI.
97
+
98
+ # Using OpenAI
99
+ ```python
100
+ lm_invoker = build_lm_invoker(
101
+ model_id="openai/gpt-4o-mini",
102
+ credentials="sk-..."
103
+ )
104
+ ```
105
+ The credentials can also be provided through the `OPENAI_API_KEY` environment variable.
106
+
107
+ # Using Azure OpenAI
108
+ ```python
109
+ lm_invoker = build_lm_invoker(
110
+ model_id="azure-openai/https://my-resource.openai.azure.com/openai/v1:my-deployment",
111
+ credentials="azure-api-key"
112
+ )
113
+ ```
114
+ The credentials can also be provided through the `AZURE_OPENAI_API_KEY` environment variable.
115
+
116
+ # Using OpenAI Compatible endpoint (e.g. Groq)
117
+ ```python
118
+ lm_invoker = build_lm_invoker(
119
+ model_id="openai-compatible/https://api.groq.com/openai/v1:llama3-8b-8192",
120
+ credentials="gsk_..."
121
+ )
122
+ ```
123
+ The credentials can also be provided through the `OPENAI_API_KEY` environment variable.
124
+
125
+ # Using LangChain
126
+ ```python
127
+ lm_invoker = build_lm_invoker(
128
+ model_id="langchain/langchain_openai.ChatOpenAI:gpt-4o-mini",
129
+ credentials={"api_key": "sk-..."}
130
+ )
131
+ ```
132
+ The credentials can also be provided through various environment variables depending on the
133
+ LangChain module being used. For the list of supported providers and the supported environment
134
+ variables credentials, please refer to the following table:
135
+ https://python.langchain.com/docs/integrations/chat/#featured-providers
136
+
137
+ # Using LiteLLM
138
+ ```python
139
+ os.environ["OPENAI_API_KEY"] = "sk-..."
140
+ lm_invoker = build_lm_invoker(
141
+ model_id="litellm/openai/gpt-4o-mini",
142
+ )
143
+ ```
144
+ For the list of supported providers, please refer to the following page:
145
+ https://docs.litellm.ai/docs/providers/
146
+
147
+ # Using xAI
148
+ ```python
149
+ lm_invoker = build_lm_invoker(
150
+ model_id="xai/grok-3",
151
+ credentials="xai-..."
152
+ )
153
+ ```
154
+ The credentials can also be provided through the `XAI_API_KEY` environment variable.
155
+ For the list of supported models, please refer to the following page:
156
+ https://docs.x.ai/docs/models
157
+
158
+ Security warning:
159
+ Please provide the LM invoker credentials ONLY to the `credentials` parameter. Do not put any kind of
160
+ credentials in the `config` parameter as the content of the `config` parameter will be logged.
161
+ '''
@@ -0,0 +1,93 @@
1
+ from _typeshed import Incomplete
2
+ from gllm_inference.builder.build_lm_invoker import build_lm_invoker as build_lm_invoker
3
+ from gllm_inference.builder.build_output_parser import build_output_parser as build_output_parser
4
+ from gllm_inference.prompt_builder import PromptBuilder as PromptBuilder
5
+ from gllm_inference.request_processor.lm_request_processor import LMRequestProcessor as LMRequestProcessor
6
+ from gllm_inference.schema.model_id import ModelId as ModelId
7
+ from typing import Any
8
+
9
+ logger: Incomplete
10
+
11
+ def build_lm_request_processor(model_id: str | ModelId, credentials: str | dict[str, Any] | None = None, config: dict[str, Any] | None = None, system_template: str = '', user_template: str = '', key_defaults: dict[str, Any] | None = None, output_parser_type: str = 'none') -> LMRequestProcessor:
12
+ '''Build a language model invoker based on the provided configurations.
13
+
14
+ Args:
15
+ model_id (str | ModelId): The model id, can either be a ModelId instance or a string in the following format:
16
+ 1. For `azure-openai` provider: `azure-openai/azure-endpoint:azure-deployment`.
17
+ 2. For `openai-compatible` provider: `openai-compatible/base-url:model-name`.
18
+ 3. For `langchain` provider: `langchain/<package>.<class>:model-name`.
19
+ 4. For `litellm` provider: `litellm/provider/model-name`.
20
+ 5. For `datasaur` provider: `datasaur/base-url`.
21
+ 6. For other providers: `provider/model-name`.
22
+ credentials (str | dict[str, Any] | None, optional): The credentials for the language model. Can either be:
23
+ 1. An API key.
24
+ 2. A path to a credentials JSON file, currently only supported for Google Vertex AI.
25
+ 3. A dictionary of credentials, currently supported for Bedrock and LangChain.
26
+ Defaults to None, in which case the credentials will be loaded from the appropriate environment variables.
27
+ config (dict[str, Any] | None, optional): Additional configuration for the language model. Defaults to None.
28
+ system_template (str): The system prompt template. May contain placeholders enclosed in curly braces `{}`.
29
+ Defaults to an empty string.
30
+ user_template (str): The user prompt template. May contain placeholders enclosed in curly braces `{}`.
31
+ Defaults to an empty string.
32
+ key_defaults (dict[str, str] | None, optional): Default values for the keys in the prompt templates.
33
+ Applied when the corresponding keys are not provided in the runtime input.
34
+ Defaults to None, in which case no default values will be assigned to the keys.
35
+ output_parser_type (str, optional): The type of output parser to use. Supports "json" and "none".
36
+ Defaults to "none".
37
+
38
+ Returns:
39
+ LMRequestProcessor: The initialized language model request processor.
40
+
41
+ Raises:
42
+ ValueError: If the provided configuration is invalid.
43
+
44
+ Usage examples:
45
+ ```python
46
+ # Basic usage
47
+ lm_request_processor = build_lm_request_processor(
48
+ model_id="openai/gpt-4o-mini",
49
+ credentials="sk-...",
50
+ user_template="{query}",
51
+ )
52
+ ```
53
+
54
+ # With custom LM invoker configuration
55
+ ```python
56
+ config = {
57
+ "default_hyperparameters": {"temperature": 0.5},
58
+ "tools": [tool_1, tool_2],
59
+ }
60
+
61
+ lm_request_processor = build_lm_request_processor(
62
+ model_id="openai/gpt-4o-mini",
63
+ credentials="sk-...",
64
+ config=config,
65
+ user_template="{query}",
66
+ )
67
+ ```
68
+
69
+ # With custom prompt builder configuration
70
+ ```python
71
+ lm_request_processor = build_lm_request_processor(
72
+ model_id="openai/gpt-4o-mini",
73
+ credentials="sk-...",
74
+ system_template="Talk like a {role}.",
75
+ user_template="{query}",
76
+ key_defaults={"role": "pirate"},
77
+ )
78
+ ```
79
+
80
+ # With output parser
81
+ ```python
82
+ lm_request_processor = build_lm_request_processor(
83
+ model_id="openai/gpt-4o-mini",
84
+ credentials="sk-...",
85
+ user_template="{query}",
86
+ output_parser_type="json",
87
+ )
88
+ ```
89
+
90
+ Security warning:
91
+ Please provide the LM invoker credentials ONLY to the `credentials` parameter. Do not put any kind of
92
+ credentials in the `config` parameter as the content of the `config` parameter will be logged.
93
+ '''
@@ -0,0 +1,29 @@
1
+ from _typeshed import Incomplete
2
+ from gllm_inference.output_parser import JSONOutputParser as JSONOutputParser
3
+ from gllm_inference.output_parser.output_parser import BaseOutputParser as BaseOutputParser
4
+
5
+ OUTPUT_PARSER_TYPE_MAP: Incomplete
6
+
7
+ def build_output_parser(output_parser_type: str) -> BaseOutputParser | None:
8
+ '''Build an output parser based on the provided configurations.
9
+
10
+ Args:
11
+ output_parser_type (str): The type of output parser to use. Supports "json" and "none".
12
+
13
+ Returns:
14
+ BaseOutputParser: The initialized output parser.
15
+
16
+ Raises:
17
+ ValueError: If the provided type is not supported.
18
+
19
+ Usage examples:
20
+ # Using JSON output parser
21
+ ```python
22
+ output_parser = build_output_parser(output_parser_type="json")
23
+ ```
24
+
25
+ # Not using output parser
26
+ ```python
27
+ output_parser = build_output_parser(output_parser_type="none")
28
+ ```
29
+ '''
@@ -0,0 +1,4 @@
1
+ from gllm_inference.catalog.lm_request_processor_catalog import LMRequestProcessorCatalog as LMRequestProcessorCatalog
2
+ from gllm_inference.catalog.prompt_builder_catalog import PromptBuilderCatalog as PromptBuilderCatalog
3
+
4
+ __all__ = ['LMRequestProcessorCatalog', 'PromptBuilderCatalog']
@@ -0,0 +1,121 @@
1
+ import abc
2
+ from _typeshed import Incomplete
3
+ from abc import ABC
4
+ from pydantic import BaseModel
5
+ from typing import Generic, TypeVar
6
+
7
+ T = TypeVar('T')
8
+ logger: Incomplete
9
+
10
+ class BaseCatalog(ABC, BaseModel, Generic[T], arbitrary_types_allowed=True, metaclass=abc.ABCMeta):
11
+ '''A base class for catalogs used for loading and managing various components in GLLM Inference.
12
+
13
+ Attributes:
14
+ components (dict[str, T]): A dictionary containing the components.
15
+
16
+ Initialization:
17
+ # Example 1: Load from Google Sheets using client email and private key
18
+ ```python
19
+ catalog = BaseCatalog.from_gsheets(
20
+ sheet_id="...",
21
+ worksheet_id="...",
22
+ client_email="...",
23
+ private_key="...",
24
+ )
25
+ component = catalog.name
26
+ ```
27
+
28
+ # Example 2: Load from Google Sheets using credential file
29
+ ```python
30
+ catalog = BaseCatalog.from_gsheets(
31
+ sheet_id="...",
32
+ worksheet_id="...",
33
+ credential_file_path="...",
34
+ )
35
+ component = catalog.name
36
+ ```
37
+
38
+ # Example 3: Load from CSV
39
+ ```python
40
+ catalog = BaseCatalog.from_csv(csv_path="...")
41
+ component = catalog.name
42
+ ```
43
+
44
+ # Example 4: Load from records
45
+ ```python
46
+ records = [
47
+ {"name": "...", "col_1": "...", "col_2": "..."},
48
+ {"name": "...", "col_1": "...", "col_2": "..."},
49
+ ]
50
+ catalog = BaseCatalog.from_records(records=records)
51
+ component = catalog.name
52
+ ```
53
+ '''
54
+ components: dict[str, T]
55
+ def __getattr__(self, name: str) -> T:
56
+ """Fetches a component by attribute name.
57
+
58
+ This method attempts to retrieve a component from the `components` dictionary using the provided
59
+ attribute name. If the attribute is not found, it raises an `AttributeError`.
60
+
61
+ Args:
62
+ name (str): The name of the attribute to fetch.
63
+
64
+ Returns:
65
+ T: The component associated with the given attribute name.
66
+
67
+ Raises:
68
+ AttributeError: If the attribute name does not exist in the `components` dictionary.
69
+ """
70
+ @classmethod
71
+ def from_gsheets(cls, sheet_id: str, worksheet_id: str = '0', credential_file_path: str = None, client_email: str = None, private_key: str = None) -> BaseCatalog[T]:
72
+ '''Creates a `BaseCatalog[T]` instance from Google Sheets data.
73
+
74
+ This class method reads component data from a Google Sheets worksheet and initializes components
75
+ based on the provided data. Authentication can be provided either by specifying the path to a `credential.json`
76
+ file or by directly supplying the `client_email` and `private_key`.
77
+
78
+ Args:
79
+ sheet_id (str): The ID of the Google Sheet.
80
+ worksheet_id (str): The ID of the worksheet within the Google Sheet. Defaults to "0"
81
+ credential_file_path (str): The file path to the `credential.json` file. If provided, `client_email` and
82
+ `private_key` are extracted from this file, effectively ignoring the `client_email` and `private_key`
83
+ arguments. Defaults to None.
84
+ client_email (str): The client email associated with the service account. This is ignored if
85
+ `credential_file_path` is provided. Defaults to None.
86
+ private_key (str): The private key used for authentication. This is ignored if `credential_file_path`
87
+ is provided. Defaults to None.
88
+
89
+ Returns:
90
+ BaseCatalog[T]: An instance of `BaseCatalog[T]` initialized with components based on the
91
+ Google Sheets data.
92
+
93
+ Raises:
94
+ ValueError: If authentication credentials are not provided or are invalid.
95
+ '''
96
+ @classmethod
97
+ def from_csv(cls, csv_path: str) -> BaseCatalog[T]:
98
+ """Creates a `BaseCatalog[T]` instance from CSV data.
99
+
100
+ This class method reads component data from a CSV file and initializes components based on the provided data.
101
+
102
+ Args:
103
+ csv_path (str): The file path to the CSV containing component data.
104
+
105
+ Returns:
106
+ BaseCatalog[T]: An instance of `BaseCatalog[T]` initialized with components based on the
107
+ CSV data.
108
+ """
109
+ @classmethod
110
+ def from_records(cls, records: list[dict[str, str]]) -> BaseCatalog[T]:
111
+ """Creates a `BaseCatalog[T]` instance from a list of records.
112
+
113
+ This class method builds a catalog from the provided records.
114
+
115
+ Args:
116
+ records (list[dict[str, str]]): A list of records containing component data.
117
+
118
+ Returns:
119
+ BaseCatalog[T]: An instance of `BaseCatalog[T]` initialized with components based on the
120
+ list of records.
121
+ """
@@ -0,0 +1,112 @@
1
+ from _typeshed import Incomplete
2
+ from gllm_inference.builder import build_lm_request_processor as build_lm_request_processor
3
+ from gllm_inference.catalog.catalog import BaseCatalog as BaseCatalog
4
+ from gllm_inference.request_processor import LMRequestProcessor as LMRequestProcessor
5
+
6
+ MODEL_ID_ENV_VAR_REGEX_PATTERN: str
7
+ LM_REQUEST_PROCESSOR_REQUIRED_COLUMNS: Incomplete
8
+ CONFIG_SCHEMA_MAP: Incomplete
9
+ logger: Incomplete
10
+
11
+ class LMRequestProcessorCatalog(BaseCatalog[LMRequestProcessor]):
12
+ '''Loads multiple LM request processors from certain sources.
13
+
14
+ Attributes:
15
+ components (dict[str, LMRequestProcessor]): Dictionary of the loaded LM request processors.
16
+
17
+ Initialization:
18
+ # Example 1: Load from Google Sheets using client email and private key
19
+ ```python
20
+ catalog = LMRequestProcessorCatalog.from_gsheets(
21
+ sheet_id="...",
22
+ worksheet_id="...",
23
+ client_email="...",
24
+ private_key="...",
25
+ )
26
+
27
+ lm_request_processor = catalog.name
28
+ ```
29
+
30
+ # Example 2: Load from Google Sheets using credential file
31
+ ```python
32
+ catalog = LMRequestProcessorCatalog.from_gsheets(
33
+ sheet_id="...",
34
+ worksheet_id="...",
35
+ credential_file_path="...",
36
+ )
37
+
38
+ lm_request_processor = catalog.name
39
+ ```
40
+
41
+ # Example 3: Load from CSV
42
+ ```python
43
+ catalog = LMRequestProcessorCatalog.from_csv(csv_path="...")
44
+
45
+ lm_request_processor = catalog.name
46
+ ```
47
+
48
+ # Example 4: Load from record
49
+ ```python
50
+ records=[
51
+ {
52
+ "name": "answer_question",
53
+ "system_template": (
54
+ "You are helpful assistant.\\n"
55
+ "Answer the following question based on the provided context.\\n"
56
+ "```{context}```"
57
+ ),
58
+ "user_template": "{query}",
59
+ "key_defaults": \'{"context": "<default context>"}\',
60
+ "model_id": "openai/gpt-4.1-nano",
61
+ "credentials": "OPENAI_API_KEY",
62
+ "config": "",
63
+ "output_parser_type": "none",
64
+ },
65
+ ]
66
+ catalog = LMRequestProcessorCatalog.from_records(records=records)
67
+ lm_request_processor = catalog.answer_question
68
+ ```
69
+
70
+ Template Format Example:
71
+ # Example 1: Google Sheets
72
+ For an example of how a Google Sheets file can be formatted to be loaded using LMRequestProcessorCatalog, see:
73
+ https://docs.google.com/spreadsheets/d/1CX9i45yEinv1UdB3s6uHNMj7mxr2-s1NFHfFDvMsq0E/edit?usp=drive_link
74
+
75
+ # Example 2: CSV
76
+ For an example of how a CSV file can be formatted to be loaded using LMRequestProcessorCatalog, see:
77
+ https://drive.google.com/file/d/1_2rSoxh3CR2KZxIyUmpowMrt0Lm0YqAb/view?usp=drive_link
78
+
79
+ Template Explanation:
80
+ The required columns are:
81
+ 1. name (str): The name of the LM request processor.
82
+ 2. system_template (str): The system template of the prompt builder.
83
+ 3. user_template (str): The user template of the prompt builder.
84
+ 4. key_defaults (json_str): The default values for the prompt template keys.
85
+ 5. model_id (str): The model ID of the LM invoker.
86
+ 6. credentials (str | json_str): The credentials of the LM invoker.
87
+ 7. config (json_str): The additional configuration of the LM invoker.
88
+ 8. output_parser_type (str): The type of the output parser.
89
+
90
+ Important Notes:
91
+ 1. At least one of `system_template` or `user_template` must be filled.
92
+ 2. `key_defaults` is optional. If filled, must be a dictionary containing the default values for the
93
+ prompt template keys. These default values will be applied when the corresponding keys are not provided
94
+ in the runtime input. If it is empty, the prompt template keys will not have default values.
95
+ 3. The `model_id`:
96
+ 3.1. Must be filled with the model ID of the LM invoker, e.g. "openai/gpt-4.1-nano".
97
+ 3.2. Can be partially loaded from the environment variable using the "${ENV_VAR_KEY}" syntax,
98
+ e.g. "azure-openai/${AZURE_ENDPOINT}/${AZURE_DEPLOYMENT}".
99
+ 3.3. For the available model ID formats, see: https://gdplabs.gitbook.io/sdk/resources/supported-models
100
+ 4. `credentials` is optional. If it is filled, it can either be:
101
+ 4.1. An environment variable name containing the API key (e.g. OPENAI_API_KEY).
102
+ 4.2. An environment variable name containing the path to a credentials JSON file
103
+ (e.g. GOOGLE_CREDENTIALS_FILE_PATH). Currently only supported for Google Vertex AI.
104
+ 4.3. A dictionary of credentials, with each value being an environment variable name corresponding to the
105
+ credential (e.g. {"api_key": "OPENAI_API_KEY"}). Currently supported for Bedrock and LangChain.
106
+ If it is empty, the LM invoker will use the default credentials loaded from the environment variables.
107
+ 5. `config` is optional. If filled, must be a dictionary containing the configuration for the LM invoker.
108
+ If it is empty, the LM invoker will use the default configuration.
109
+ 6. `output_parser_type` can either be:
110
+ 6.1. none: No output parser will be used.
111
+ 6.2. json: The JSONOutputParser will be used.
112
+ '''