langroid 0.31.2__py3-none-any.whl → 0.33.3__py3-none-any.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.
Files changed (163) hide show
  1. {langroid-0.31.2.dist-info → langroid-0.33.3.dist-info}/METADATA +150 -124
  2. langroid-0.33.3.dist-info/RECORD +7 -0
  3. {langroid-0.31.2.dist-info → langroid-0.33.3.dist-info}/WHEEL +1 -1
  4. langroid-0.33.3.dist-info/entry_points.txt +4 -0
  5. pyproject.toml +317 -212
  6. langroid/__init__.py +0 -106
  7. langroid/agent/.chainlit/config.toml +0 -121
  8. langroid/agent/.chainlit/translations/bn.json +0 -231
  9. langroid/agent/.chainlit/translations/en-US.json +0 -229
  10. langroid/agent/.chainlit/translations/gu.json +0 -231
  11. langroid/agent/.chainlit/translations/he-IL.json +0 -231
  12. langroid/agent/.chainlit/translations/hi.json +0 -231
  13. langroid/agent/.chainlit/translations/kn.json +0 -231
  14. langroid/agent/.chainlit/translations/ml.json +0 -231
  15. langroid/agent/.chainlit/translations/mr.json +0 -231
  16. langroid/agent/.chainlit/translations/ta.json +0 -231
  17. langroid/agent/.chainlit/translations/te.json +0 -231
  18. langroid/agent/.chainlit/translations/zh-CN.json +0 -229
  19. langroid/agent/__init__.py +0 -41
  20. langroid/agent/base.py +0 -1981
  21. langroid/agent/batch.py +0 -398
  22. langroid/agent/callbacks/__init__.py +0 -0
  23. langroid/agent/callbacks/chainlit.py +0 -598
  24. langroid/agent/chat_agent.py +0 -1899
  25. langroid/agent/chat_document.py +0 -454
  26. langroid/agent/helpers.py +0 -0
  27. langroid/agent/junk +0 -13
  28. langroid/agent/openai_assistant.py +0 -882
  29. langroid/agent/special/__init__.py +0 -59
  30. langroid/agent/special/arangodb/__init__.py +0 -0
  31. langroid/agent/special/arangodb/arangodb_agent.py +0 -656
  32. langroid/agent/special/arangodb/system_messages.py +0 -186
  33. langroid/agent/special/arangodb/tools.py +0 -107
  34. langroid/agent/special/arangodb/utils.py +0 -36
  35. langroid/agent/special/doc_chat_agent.py +0 -1466
  36. langroid/agent/special/lance_doc_chat_agent.py +0 -262
  37. langroid/agent/special/lance_rag/__init__.py +0 -9
  38. langroid/agent/special/lance_rag/critic_agent.py +0 -198
  39. langroid/agent/special/lance_rag/lance_rag_task.py +0 -82
  40. langroid/agent/special/lance_rag/query_planner_agent.py +0 -260
  41. langroid/agent/special/lance_tools.py +0 -61
  42. langroid/agent/special/neo4j/__init__.py +0 -0
  43. langroid/agent/special/neo4j/csv_kg_chat.py +0 -174
  44. langroid/agent/special/neo4j/neo4j_chat_agent.py +0 -433
  45. langroid/agent/special/neo4j/system_messages.py +0 -120
  46. langroid/agent/special/neo4j/tools.py +0 -32
  47. langroid/agent/special/relevance_extractor_agent.py +0 -127
  48. langroid/agent/special/retriever_agent.py +0 -56
  49. langroid/agent/special/sql/__init__.py +0 -17
  50. langroid/agent/special/sql/sql_chat_agent.py +0 -654
  51. langroid/agent/special/sql/utils/__init__.py +0 -21
  52. langroid/agent/special/sql/utils/description_extractors.py +0 -190
  53. langroid/agent/special/sql/utils/populate_metadata.py +0 -85
  54. langroid/agent/special/sql/utils/system_message.py +0 -35
  55. langroid/agent/special/sql/utils/tools.py +0 -64
  56. langroid/agent/special/table_chat_agent.py +0 -263
  57. langroid/agent/structured_message.py +0 -9
  58. langroid/agent/task.py +0 -2093
  59. langroid/agent/tool_message.py +0 -393
  60. langroid/agent/tools/__init__.py +0 -38
  61. langroid/agent/tools/duckduckgo_search_tool.py +0 -50
  62. langroid/agent/tools/file_tools.py +0 -234
  63. langroid/agent/tools/google_search_tool.py +0 -39
  64. langroid/agent/tools/metaphor_search_tool.py +0 -67
  65. langroid/agent/tools/orchestration.py +0 -303
  66. langroid/agent/tools/recipient_tool.py +0 -235
  67. langroid/agent/tools/retrieval_tool.py +0 -32
  68. langroid/agent/tools/rewind_tool.py +0 -137
  69. langroid/agent/tools/segment_extract_tool.py +0 -41
  70. langroid/agent/typed_task.py +0 -19
  71. langroid/agent/xml_tool_message.py +0 -382
  72. langroid/agent_config.py +0 -0
  73. langroid/cachedb/__init__.py +0 -17
  74. langroid/cachedb/base.py +0 -58
  75. langroid/cachedb/momento_cachedb.py +0 -108
  76. langroid/cachedb/redis_cachedb.py +0 -153
  77. langroid/embedding_models/__init__.py +0 -39
  78. langroid/embedding_models/base.py +0 -74
  79. langroid/embedding_models/clustering.py +0 -189
  80. langroid/embedding_models/models.py +0 -461
  81. langroid/embedding_models/protoc/__init__.py +0 -0
  82. langroid/embedding_models/protoc/embeddings.proto +0 -19
  83. langroid/embedding_models/protoc/embeddings_pb2.py +0 -33
  84. langroid/embedding_models/protoc/embeddings_pb2.pyi +0 -50
  85. langroid/embedding_models/protoc/embeddings_pb2_grpc.py +0 -79
  86. langroid/embedding_models/remote_embeds.py +0 -153
  87. langroid/exceptions.py +0 -65
  88. langroid/experimental/team-save.py +0 -391
  89. langroid/language_models/.chainlit/config.toml +0 -121
  90. langroid/language_models/.chainlit/translations/en-US.json +0 -231
  91. langroid/language_models/__init__.py +0 -53
  92. langroid/language_models/azure_openai.py +0 -153
  93. langroid/language_models/base.py +0 -678
  94. langroid/language_models/config.py +0 -18
  95. langroid/language_models/mock_lm.py +0 -124
  96. langroid/language_models/openai_gpt.py +0 -1923
  97. langroid/language_models/prompt_formatter/__init__.py +0 -16
  98. langroid/language_models/prompt_formatter/base.py +0 -40
  99. langroid/language_models/prompt_formatter/hf_formatter.py +0 -132
  100. langroid/language_models/prompt_formatter/llama2_formatter.py +0 -75
  101. langroid/language_models/utils.py +0 -147
  102. langroid/mytypes.py +0 -84
  103. langroid/parsing/__init__.py +0 -52
  104. langroid/parsing/agent_chats.py +0 -38
  105. langroid/parsing/code-parsing.md +0 -86
  106. langroid/parsing/code_parser.py +0 -121
  107. langroid/parsing/config.py +0 -0
  108. langroid/parsing/document_parser.py +0 -718
  109. langroid/parsing/image_text.py +0 -32
  110. langroid/parsing/para_sentence_split.py +0 -62
  111. langroid/parsing/parse_json.py +0 -155
  112. langroid/parsing/parser.py +0 -313
  113. langroid/parsing/repo_loader.py +0 -790
  114. langroid/parsing/routing.py +0 -36
  115. langroid/parsing/search.py +0 -275
  116. langroid/parsing/spider.py +0 -102
  117. langroid/parsing/table_loader.py +0 -94
  118. langroid/parsing/url_loader.py +0 -111
  119. langroid/parsing/url_loader_cookies.py +0 -73
  120. langroid/parsing/urls.py +0 -273
  121. langroid/parsing/utils.py +0 -373
  122. langroid/parsing/web_search.py +0 -155
  123. langroid/prompts/__init__.py +0 -9
  124. langroid/prompts/chat-gpt4-system-prompt.md +0 -68
  125. langroid/prompts/dialog.py +0 -17
  126. langroid/prompts/prompts_config.py +0 -5
  127. langroid/prompts/templates.py +0 -141
  128. langroid/pydantic_v1/__init__.py +0 -10
  129. langroid/pydantic_v1/main.py +0 -4
  130. langroid/utils/.chainlit/config.toml +0 -121
  131. langroid/utils/.chainlit/translations/en-US.json +0 -231
  132. langroid/utils/__init__.py +0 -19
  133. langroid/utils/algorithms/__init__.py +0 -3
  134. langroid/utils/algorithms/graph.py +0 -103
  135. langroid/utils/configuration.py +0 -98
  136. langroid/utils/constants.py +0 -30
  137. langroid/utils/docker.py +0 -37
  138. langroid/utils/git_utils.py +0 -252
  139. langroid/utils/globals.py +0 -49
  140. langroid/utils/llms/__init__.py +0 -0
  141. langroid/utils/llms/strings.py +0 -8
  142. langroid/utils/logging.py +0 -135
  143. langroid/utils/object_registry.py +0 -66
  144. langroid/utils/output/__init__.py +0 -20
  145. langroid/utils/output/citations.py +0 -41
  146. langroid/utils/output/printing.py +0 -99
  147. langroid/utils/output/status.py +0 -40
  148. langroid/utils/pandas_utils.py +0 -30
  149. langroid/utils/pydantic_utils.py +0 -602
  150. langroid/utils/system.py +0 -286
  151. langroid/utils/types.py +0 -93
  152. langroid/utils/web/__init__.py +0 -0
  153. langroid/utils/web/login.py +0 -83
  154. langroid/vector_store/__init__.py +0 -50
  155. langroid/vector_store/base.py +0 -357
  156. langroid/vector_store/chromadb.py +0 -214
  157. langroid/vector_store/lancedb.py +0 -401
  158. langroid/vector_store/meilisearch.py +0 -299
  159. langroid/vector_store/momento.py +0 -278
  160. langroid/vector_store/qdrant_cloud.py +0 -6
  161. langroid/vector_store/qdrantdb.py +0 -468
  162. langroid-0.31.2.dist-info/RECORD +0 -162
  163. {langroid-0.31.2.dist-info → langroid-0.33.3.dist-info/licenses}/LICENSE +0 -0
@@ -1,121 +0,0 @@
1
- [project]
2
- # Whether to enable telemetry (default: true). No personal data is collected.
3
- enable_telemetry = true
4
-
5
-
6
- # List of environment variables to be provided by each user to use the app.
7
- user_env = []
8
-
9
- # Duration (in seconds) during which the session is saved when the connection is lost
10
- session_timeout = 3600
11
-
12
- # Enable third parties caching (e.g LangChain cache)
13
- cache = false
14
-
15
- # Authorized origins
16
- allow_origins = ["*"]
17
-
18
- # Follow symlink for asset mount (see https://github.com/Chainlit/chainlit/issues/317)
19
- # follow_symlink = false
20
-
21
- [features]
22
- # Show the prompt playground
23
- prompt_playground = true
24
-
25
- # Process and display HTML in messages. This can be a security risk (see https://stackoverflow.com/questions/19603097/why-is-it-dangerous-to-render-user-generated-html-or-javascript)
26
- unsafe_allow_html = false
27
-
28
- # Process and display mathematical expressions. This can clash with "$" characters in messages.
29
- latex = false
30
-
31
- # Automatically tag threads with the current chat profile (if a chat profile is used)
32
- auto_tag_thread = true
33
-
34
- # Authorize users to spontaneously upload files with messages
35
- [features.spontaneous_file_upload]
36
- enabled = true
37
- accept = ["*/*"]
38
- max_files = 20
39
- max_size_mb = 500
40
-
41
- [features.audio]
42
- # Threshold for audio recording
43
- min_decibels = -45
44
- # Delay for the user to start speaking in MS
45
- initial_silence_timeout = 3000
46
- # Delay for the user to continue speaking in MS. If the user stops speaking for this duration, the recording will stop.
47
- silence_timeout = 1500
48
- # Above this duration (MS), the recording will forcefully stop.
49
- max_duration = 15000
50
- # Duration of the audio chunks in MS
51
- chunk_duration = 1000
52
- # Sample rate of the audio
53
- sample_rate = 44100
54
-
55
- [UI]
56
- # Name of the app and chatbot.
57
- name = "Chatbot"
58
-
59
- # Show the readme while the thread is empty.
60
- show_readme_as_default = true
61
-
62
- # Description of the app and chatbot. This is used for HTML tags.
63
- # description = ""
64
-
65
- # Large size content are by default collapsed for a cleaner ui
66
- default_collapse_content = true
67
-
68
- # The default value for the expand messages settings.
69
- default_expand_messages = false
70
-
71
- # Hide the chain of thought details from the user in the UI.
72
- hide_cot = false
73
-
74
- # Link to your github repo. This will add a github button in the UI's header.
75
- # github = ""
76
-
77
- # Specify a CSS file that can be used to customize the user interface.
78
- # The CSS file can be served from the public directory or via an external link.
79
- # custom_css = "/public/test.css"
80
-
81
- # Specify a Javascript file that can be used to customize the user interface.
82
- # The Javascript file can be served from the public directory.
83
- # custom_js = "/public/test.js"
84
-
85
- # Specify a custom font url.
86
- # custom_font = "https://fonts.googleapis.com/css2?family=Inter:wght@400;500;700&display=swap"
87
-
88
- # Specify a custom meta image url.
89
- # custom_meta_image_url = "https://chainlit-cloud.s3.eu-west-3.amazonaws.com/logo/chainlit_banner.png"
90
-
91
- # Specify a custom build directory for the frontend.
92
- # This can be used to customize the frontend code.
93
- # Be careful: If this is a relative path, it should not start with a slash.
94
- # custom_build = "./public/build"
95
-
96
- [UI.theme]
97
- #layout = "wide"
98
- #font_family = "Inter, sans-serif"
99
- # Override default MUI light theme. (Check theme.ts)
100
- [UI.theme.light]
101
- #background = "#FAFAFA"
102
- #paper = "#FFFFFF"
103
-
104
- [UI.theme.light.primary]
105
- #main = "#F80061"
106
- #dark = "#980039"
107
- #light = "#FFE7EB"
108
-
109
- # Override default MUI dark theme. (Check theme.ts)
110
- [UI.theme.dark]
111
- #background = "#FAFAFA"
112
- #paper = "#FFFFFF"
113
-
114
- [UI.theme.dark.primary]
115
- #main = "#F80061"
116
- #dark = "#980039"
117
- #light = "#FFE7EB"
118
-
119
-
120
- [meta]
121
- generated_by = "1.1.202"
@@ -1,231 +0,0 @@
1
- {
2
- "components": {
3
- "atoms": {
4
- "buttons": {
5
- "userButton": {
6
- "menu": {
7
- "settings": "Settings",
8
- "settingsKey": "S",
9
- "APIKeys": "API Keys",
10
- "logout": "Logout"
11
- }
12
- }
13
- }
14
- },
15
- "molecules": {
16
- "newChatButton": {
17
- "newChat": "New Chat"
18
- },
19
- "tasklist": {
20
- "TaskList": {
21
- "title": "\ud83d\uddd2\ufe0f Task List",
22
- "loading": "Loading...",
23
- "error": "An error occured"
24
- }
25
- },
26
- "attachments": {
27
- "cancelUpload": "Cancel upload",
28
- "removeAttachment": "Remove attachment"
29
- },
30
- "newChatDialog": {
31
- "createNewChat": "Create new chat?",
32
- "clearChat": "This will clear the current messages and start a new chat.",
33
- "cancel": "Cancel",
34
- "confirm": "Confirm"
35
- },
36
- "settingsModal": {
37
- "settings": "Settings",
38
- "expandMessages": "Expand Messages",
39
- "hideChainOfThought": "Hide Chain of Thought",
40
- "darkMode": "Dark Mode"
41
- },
42
- "detailsButton": {
43
- "using": "Using",
44
- "running": "Running",
45
- "took_one": "Took {{count}} step",
46
- "took_other": "Took {{count}} steps"
47
- },
48
- "auth": {
49
- "authLogin": {
50
- "title": "Login to access the app.",
51
- "form": {
52
- "email": "Email address",
53
- "password": "Password",
54
- "noAccount": "Don't have an account?",
55
- "alreadyHaveAccount": "Already have an account?",
56
- "signup": "Sign Up",
57
- "signin": "Sign In",
58
- "or": "OR",
59
- "continue": "Continue",
60
- "forgotPassword": "Forgot password?",
61
- "passwordMustContain": "Your password must contain:",
62
- "emailRequired": "email is a required field",
63
- "passwordRequired": "password is a required field"
64
- },
65
- "error": {
66
- "default": "Unable to sign in.",
67
- "signin": "Try signing in with a different account.",
68
- "oauthsignin": "Try signing in with a different account.",
69
- "redirect_uri_mismatch": "The redirect URI is not matching the oauth app configuration.",
70
- "oauthcallbackerror": "Try signing in with a different account.",
71
- "oauthcreateaccount": "Try signing in with a different account.",
72
- "emailcreateaccount": "Try signing in with a different account.",
73
- "callback": "Try signing in with a different account.",
74
- "oauthaccountnotlinked": "To confirm your identity, sign in with the same account you used originally.",
75
- "emailsignin": "The e-mail could not be sent.",
76
- "emailverify": "Please verify your email, a new email has been sent.",
77
- "credentialssignin": "Sign in failed. Check the details you provided are correct.",
78
- "sessionrequired": "Please sign in to access this page."
79
- }
80
- },
81
- "authVerifyEmail": {
82
- "almostThere": "You're almost there! We've sent an email to ",
83
- "verifyEmailLink": "Please click on the link in that email to complete your signup.",
84
- "didNotReceive": "Can't find the email?",
85
- "resendEmail": "Resend email",
86
- "goBack": "Go Back",
87
- "emailSent": "Email sent successfully.",
88
- "verifyEmail": "Verify your email address"
89
- },
90
- "providerButton": {
91
- "continue": "Continue with {{provider}}",
92
- "signup": "Sign up with {{provider}}"
93
- },
94
- "authResetPassword": {
95
- "newPasswordRequired": "New password is a required field",
96
- "passwordsMustMatch": "Passwords must match",
97
- "confirmPasswordRequired": "Confirm password is a required field",
98
- "newPassword": "New password",
99
- "confirmPassword": "Confirm password",
100
- "resetPassword": "Reset Password"
101
- },
102
- "authForgotPassword": {
103
- "email": "Email address",
104
- "emailRequired": "email is a required field",
105
- "emailSent": "Please check the email address {{email}} for instructions to reset your password.",
106
- "enterEmail": "Enter your email address and we will send you instructions to reset your password.",
107
- "resendEmail": "Resend email",
108
- "continue": "Continue",
109
- "goBack": "Go Back"
110
- }
111
- }
112
- },
113
- "organisms": {
114
- "chat": {
115
- "history": {
116
- "index": {
117
- "showHistory": "Show history",
118
- "lastInputs": "Last Inputs",
119
- "noInputs": "Such empty...",
120
- "loading": "Loading..."
121
- }
122
- },
123
- "inputBox": {
124
- "input": {
125
- "placeholder": "Type your message here..."
126
- },
127
- "speechButton": {
128
- "start": "Start recording",
129
- "stop": "Stop recording"
130
- },
131
- "SubmitButton": {
132
- "sendMessage": "Send message",
133
- "stopTask": "Stop Task"
134
- },
135
- "UploadButton": {
136
- "attachFiles": "Attach files"
137
- },
138
- "waterMark": {
139
- "text": "Built with"
140
- }
141
- },
142
- "Messages": {
143
- "index": {
144
- "running": "Running",
145
- "executedSuccessfully": "executed successfully",
146
- "failed": "failed",
147
- "feedbackUpdated": "Feedback updated",
148
- "updating": "Updating"
149
- }
150
- },
151
- "dropScreen": {
152
- "dropYourFilesHere": "Drop your files here"
153
- },
154
- "index": {
155
- "failedToUpload": "Failed to upload",
156
- "cancelledUploadOf": "Cancelled upload of",
157
- "couldNotReachServer": "Could not reach the server",
158
- "continuingChat": "Continuing previous chat"
159
- },
160
- "settings": {
161
- "settingsPanel": "Settings panel",
162
- "reset": "Reset",
163
- "cancel": "Cancel",
164
- "confirm": "Confirm"
165
- }
166
- },
167
- "threadHistory": {
168
- "sidebar": {
169
- "filters": {
170
- "FeedbackSelect": {
171
- "feedbackAll": "Feedback: All",
172
- "feedbackPositive": "Feedback: Positive",
173
- "feedbackNegative": "Feedback: Negative"
174
- },
175
- "SearchBar": {
176
- "search": "Search"
177
- }
178
- },
179
- "DeleteThreadButton": {
180
- "confirmMessage": "This will delete the thread as well as it's messages and elements.",
181
- "cancel": "Cancel",
182
- "confirm": "Confirm",
183
- "deletingChat": "Deleting chat",
184
- "chatDeleted": "Chat deleted"
185
- },
186
- "index": {
187
- "pastChats": "Past Chats"
188
- },
189
- "ThreadList": {
190
- "empty": "Empty...",
191
- "today": "Today",
192
- "yesterday": "Yesterday",
193
- "previous7days": "Previous 7 days",
194
- "previous30days": "Previous 30 days"
195
- },
196
- "TriggerButton": {
197
- "closeSidebar": "Close sidebar",
198
- "openSidebar": "Open sidebar"
199
- }
200
- },
201
- "Thread": {
202
- "backToChat": "Go back to chat",
203
- "chatCreatedOn": "This chat was created on"
204
- }
205
- },
206
- "header": {
207
- "chat": "Chat",
208
- "readme": "Readme"
209
- }
210
- }
211
- },
212
- "hooks": {
213
- "useLLMProviders": {
214
- "failedToFetchProviders": "Failed to fetch providers:"
215
- }
216
- },
217
- "pages": {
218
- "Design": {},
219
- "Env": {
220
- "savedSuccessfully": "Saved successfully",
221
- "requiredApiKeys": "Required API Keys",
222
- "requiredApiKeysInfo": "To use this app, the following API keys are required. The keys are stored on your device's local storage."
223
- },
224
- "Page": {
225
- "notPartOfProject": "You are not part of this project."
226
- },
227
- "ResumeButton": {
228
- "resumeChat": "Resume Chat"
229
- }
230
- }
231
- }
@@ -1,53 +0,0 @@
1
- from . import utils
2
- from . import config
3
- from . import base
4
- from . import openai_gpt
5
- from . import azure_openai
6
- from . import prompt_formatter
7
-
8
- from .base import (
9
- LLMConfig,
10
- LLMMessage,
11
- LLMFunctionCall,
12
- LLMFunctionSpec,
13
- Role,
14
- LLMTokenUsage,
15
- LLMResponse,
16
- )
17
- from .openai_gpt import (
18
- OpenAIChatModel,
19
- AnthropicModel,
20
- GeminiModel,
21
- OpenAICompletionModel,
22
- OpenAIGPTConfig,
23
- OpenAIGPT,
24
- )
25
- from .mock_lm import MockLM, MockLMConfig
26
- from .azure_openai import AzureConfig, AzureGPT
27
-
28
-
29
- __all__ = [
30
- "utils",
31
- "config",
32
- "base",
33
- "openai_gpt",
34
- "azure_openai",
35
- "prompt_formatter",
36
- "LLMConfig",
37
- "LLMMessage",
38
- "LLMFunctionCall",
39
- "LLMFunctionSpec",
40
- "Role",
41
- "LLMTokenUsage",
42
- "LLMResponse",
43
- "OpenAIChatModel",
44
- "AnthropicModel",
45
- "GeminiModel",
46
- "OpenAICompletionModel",
47
- "OpenAIGPTConfig",
48
- "OpenAIGPT",
49
- "AzureConfig",
50
- "AzureGPT",
51
- "MockLM",
52
- "MockLMConfig",
53
- ]
@@ -1,153 +0,0 @@
1
- import logging
2
- from typing import Callable
3
-
4
- from dotenv import load_dotenv
5
- from httpx import Timeout
6
- from openai import AsyncAzureOpenAI, AzureOpenAI
7
-
8
- from langroid.language_models.openai_gpt import (
9
- OpenAIGPT,
10
- OpenAIGPTConfig,
11
- )
12
-
13
- azureStructuredOutputList = [
14
- "2024-08-06",
15
- "2024-11-20",
16
- ]
17
-
18
- azureStructuredOutputAPIMin = "2024-08-01-preview"
19
-
20
- logger = logging.getLogger(__name__)
21
-
22
-
23
- class AzureConfig(OpenAIGPTConfig):
24
- """
25
- Configuration for Azure OpenAI GPT.
26
-
27
- Attributes:
28
- type (str): should be ``azure.``
29
- api_version (str): can be set in the ``.env`` file as
30
- ``AZURE_OPENAI_API_VERSION.``
31
- deployment_name (str): can be set in the ``.env`` file as
32
- ``AZURE_OPENAI_DEPLOYMENT_NAME`` and should be based the custom name you
33
- chose for your deployment when you deployed a model.
34
- model_name (str): can be set in the ``.env``
35
- file as ``AZURE_OPENAI_MODEL_NAME``
36
- and should be based on the model name chosen during setup.
37
- model_version (str): can be set in the ``.env`` file as
38
- ``AZURE_OPENAI_MODEL_VERSION`` and should be based on the model name
39
- chosen during setup.
40
- """
41
-
42
- api_key: str = "" # CAUTION: set this ONLY via env var AZURE_OPENAI_API_KEY
43
- type: str = "azure"
44
- api_version: str = "2023-05-15"
45
- deployment_name: str = ""
46
- model_name: str = ""
47
- model_version: str = "" # is used to determine the cost of using the model
48
- api_base: str = ""
49
-
50
- # Alternatively, bring your own clients:
51
- azure_openai_client_provider: Callable[[], AzureOpenAI] | None = None
52
- azure_openai_async_client_provider: Callable[[], AsyncAzureOpenAI] | None = None
53
-
54
- # all of the vars above can be set via env vars,
55
- # by upper-casing the name and prefixing with `env_prefix`, e.g.
56
- # AZURE_OPENAI_API_VERSION=2023-05-15
57
- # This is either done in the .env file, or via an explicit
58
- # `export AZURE_OPENAI_API_VERSION=...`
59
- class Config:
60
- env_prefix = "AZURE_OPENAI_"
61
-
62
-
63
- class AzureGPT(OpenAIGPT):
64
- """
65
- Class to access OpenAI LLMs via Azure. These env variables can be obtained from the
66
- file `.azure_env`. Azure OpenAI doesn't support ``completion``
67
- Attributes:
68
- config (AzureConfig): AzureConfig object
69
- api_key (str): Azure API key
70
- api_base (str): Azure API base url
71
- api_version (str): Azure API version
72
- model_name (str): the name of gpt model in your deployment
73
- model_version (str): the version of gpt model in your deployment
74
- """
75
-
76
- def __init__(self, config: AzureConfig):
77
- # This will auto-populate config values from .env file
78
- load_dotenv()
79
- super().__init__(config)
80
- self.config: AzureConfig = config
81
- if self.config.deployment_name == "":
82
- raise ValueError(
83
- """
84
- AZURE_OPENAI_DEPLOYMENT_NAME not set in .env file,
85
- please set it to your Azure openai deployment name."""
86
- )
87
- self.deployment_name = self.config.deployment_name
88
-
89
- if self.config.model_name == "":
90
- raise ValueError(
91
- """
92
- AZURE_OPENAI_MODEL_NAME not set in .env file,
93
- please set it to chat model name in your deployment."""
94
- )
95
-
96
- if (
97
- self.config.azure_openai_client_provider
98
- or self.config.azure_openai_async_client_provider
99
- ):
100
- if not self.config.azure_openai_client_provider:
101
- self.client = None
102
- logger.warning(
103
- "Using user-provided Azure OpenAI client, but only async "
104
- "client has been provided. Synchronous calls will fail."
105
- )
106
- if not self.config.azure_openai_async_client_provider:
107
- self.async_client = None
108
- logger.warning(
109
- "Using user-provided Azure OpenAI client, but no async "
110
- "client has been provided. Asynchronous calls will fail."
111
- )
112
-
113
- if self.config.azure_openai_client_provider:
114
- self.client = self.config.azure_openai_client_provider()
115
- if self.config.azure_openai_async_client_provider:
116
- self.async_client = self.config.azure_openai_async_client_provider()
117
- self.async_client.timeout = Timeout(self.config.timeout)
118
- else:
119
- if self.config.api_key == "":
120
- raise ValueError(
121
- """
122
- AZURE_OPENAI_API_KEY not set in .env file,
123
- please set it to your Azure API key."""
124
- )
125
-
126
- if self.config.api_base == "":
127
- raise ValueError(
128
- """
129
- AZURE_OPENAI_API_BASE not set in .env file,
130
- please set it to your Azure API key."""
131
- )
132
-
133
- self.client = AzureOpenAI(
134
- api_key=self.config.api_key,
135
- azure_endpoint=self.config.api_base,
136
- api_version=self.config.api_version,
137
- azure_deployment=self.config.deployment_name,
138
- )
139
- self.async_client = AsyncAzureOpenAI(
140
- api_key=self.config.api_key,
141
- azure_endpoint=self.config.api_base,
142
- api_version=self.config.api_version,
143
- azure_deployment=self.config.deployment_name,
144
- timeout=Timeout(self.config.timeout),
145
- )
146
-
147
- # set the chat model to be the same as the model_name
148
- self.config.chat_model = self.config.model_name
149
-
150
- self.supports_json_schema = (
151
- self.config.api_version >= azureStructuredOutputAPIMin
152
- and self.config.model_version in azureStructuredOutputList
153
- )