langroid 0.58.2__py3-none-any.whl → 0.59.0b1__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.
- langroid/agent/base.py +39 -17
- langroid/agent/base.py-e +2216 -0
- langroid/agent/callbacks/chainlit.py +2 -1
- langroid/agent/chat_agent.py +73 -55
- langroid/agent/chat_agent.py-e +2086 -0
- langroid/agent/chat_document.py +7 -7
- langroid/agent/chat_document.py-e +513 -0
- langroid/agent/openai_assistant.py +9 -9
- langroid/agent/openai_assistant.py-e +882 -0
- langroid/agent/special/arangodb/arangodb_agent.py +10 -18
- langroid/agent/special/arangodb/arangodb_agent.py-e +648 -0
- langroid/agent/special/arangodb/tools.py +3 -3
- langroid/agent/special/doc_chat_agent.py +16 -14
- langroid/agent/special/lance_rag/critic_agent.py +2 -2
- langroid/agent/special/lance_rag/query_planner_agent.py +4 -4
- langroid/agent/special/lance_tools.py +6 -5
- langroid/agent/special/lance_tools.py-e +61 -0
- langroid/agent/special/neo4j/neo4j_chat_agent.py +3 -7
- langroid/agent/special/neo4j/neo4j_chat_agent.py-e +430 -0
- langroid/agent/special/relevance_extractor_agent.py +1 -1
- langroid/agent/special/sql/sql_chat_agent.py +11 -3
- langroid/agent/task.py +9 -87
- langroid/agent/task.py-e +2418 -0
- langroid/agent/tool_message.py +33 -17
- langroid/agent/tool_message.py-e +400 -0
- langroid/agent/tools/file_tools.py +4 -2
- langroid/agent/tools/file_tools.py-e +234 -0
- langroid/agent/tools/mcp/fastmcp_client.py +19 -6
- langroid/agent/tools/mcp/fastmcp_client.py-e +584 -0
- langroid/agent/tools/orchestration.py +22 -17
- langroid/agent/tools/orchestration.py-e +301 -0
- langroid/agent/tools/recipient_tool.py +3 -3
- langroid/agent/tools/task_tool.py +22 -16
- langroid/agent/tools/task_tool.py-e +249 -0
- langroid/agent/xml_tool_message.py +90 -35
- langroid/agent/xml_tool_message.py-e +392 -0
- langroid/cachedb/base.py +1 -1
- langroid/embedding_models/base.py +2 -2
- langroid/embedding_models/models.py +3 -7
- langroid/embedding_models/models.py-e +563 -0
- langroid/exceptions.py +4 -1
- langroid/language_models/azure_openai.py +2 -2
- langroid/language_models/azure_openai.py-e +134 -0
- langroid/language_models/base.py +6 -4
- langroid/language_models/base.py-e +812 -0
- langroid/language_models/client_cache.py +64 -0
- langroid/language_models/config.py +2 -4
- langroid/language_models/config.py-e +18 -0
- langroid/language_models/model_info.py +9 -1
- langroid/language_models/model_info.py-e +483 -0
- langroid/language_models/openai_gpt.py +119 -20
- langroid/language_models/openai_gpt.py-e +2280 -0
- langroid/language_models/provider_params.py +3 -22
- langroid/language_models/provider_params.py-e +153 -0
- langroid/mytypes.py +11 -4
- langroid/mytypes.py-e +132 -0
- langroid/parsing/code_parser.py +1 -1
- langroid/parsing/file_attachment.py +1 -1
- langroid/parsing/file_attachment.py-e +246 -0
- langroid/parsing/md_parser.py +14 -4
- langroid/parsing/md_parser.py-e +574 -0
- langroid/parsing/parser.py +22 -7
- langroid/parsing/parser.py-e +410 -0
- langroid/parsing/repo_loader.py +3 -1
- langroid/parsing/repo_loader.py-e +812 -0
- langroid/parsing/search.py +1 -1
- langroid/parsing/url_loader.py +17 -51
- langroid/parsing/url_loader.py-e +683 -0
- langroid/parsing/urls.py +5 -4
- langroid/parsing/urls.py-e +279 -0
- langroid/prompts/prompts_config.py +1 -1
- langroid/pydantic_v1/__init__.py +45 -6
- langroid/pydantic_v1/__init__.py-e +36 -0
- langroid/pydantic_v1/main.py +11 -4
- langroid/pydantic_v1/main.py-e +11 -0
- langroid/utils/configuration.py +13 -11
- langroid/utils/configuration.py-e +141 -0
- langroid/utils/constants.py +1 -1
- langroid/utils/constants.py-e +32 -0
- langroid/utils/globals.py +21 -5
- langroid/utils/globals.py-e +49 -0
- langroid/utils/html_logger.py +2 -1
- langroid/utils/html_logger.py-e +825 -0
- langroid/utils/object_registry.py +1 -1
- langroid/utils/object_registry.py-e +66 -0
- langroid/utils/pydantic_utils.py +55 -28
- langroid/utils/pydantic_utils.py-e +602 -0
- langroid/utils/types.py +2 -2
- langroid/utils/types.py-e +113 -0
- langroid/vector_store/base.py +3 -3
- langroid/vector_store/lancedb.py +5 -5
- langroid/vector_store/lancedb.py-e +404 -0
- langroid/vector_store/meilisearch.py +2 -2
- langroid/vector_store/pineconedb.py +4 -4
- langroid/vector_store/pineconedb.py-e +427 -0
- langroid/vector_store/postgres.py +1 -1
- langroid/vector_store/qdrantdb.py +3 -3
- langroid/vector_store/weaviatedb.py +1 -1
- {langroid-0.58.2.dist-info → langroid-0.59.0b1.dist-info}/METADATA +3 -2
- langroid-0.59.0b1.dist-info/RECORD +181 -0
- langroid/agent/special/doc_chat_task.py +0 -0
- langroid/mcp/__init__.py +0 -1
- langroid/mcp/server/__init__.py +0 -1
- langroid-0.58.2.dist-info/RECORD +0 -145
- {langroid-0.58.2.dist-info → langroid-0.59.0b1.dist-info}/WHEEL +0 -0
- {langroid-0.58.2.dist-info → langroid-0.59.0b1.dist-info}/licenses/LICENSE +0 -0
@@ -0,0 +1,134 @@
|
|
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
|
+
from pydantic import ConfigDict
|
13
|
+
|
14
|
+
azureStructuredOutputList = [
|
15
|
+
"2024-08-06",
|
16
|
+
"2024-11-20",
|
17
|
+
]
|
18
|
+
|
19
|
+
azureStructuredOutputAPIMin = "2024-08-01-preview"
|
20
|
+
|
21
|
+
logger = logging.getLogger(__name__)
|
22
|
+
|
23
|
+
|
24
|
+
class AzureConfig(OpenAIGPTConfig):
|
25
|
+
"""
|
26
|
+
Configuration for Azure OpenAI GPT.
|
27
|
+
|
28
|
+
Attributes:
|
29
|
+
type (str): should be ``azure.``
|
30
|
+
api_version (str): can be set in the ``.env`` file as
|
31
|
+
``AZURE_OPENAI_API_VERSION.``
|
32
|
+
deployment_name (str|None): can be optionally set in the ``.env`` file as
|
33
|
+
``AZURE_OPENAI_DEPLOYMENT_NAME`` and should be based the custom name you
|
34
|
+
chose for your deployment when you deployed a model.
|
35
|
+
model_name (str): [DEPRECATED] can be set in the ``.env``
|
36
|
+
file as ``AZURE_OPENAI_MODEL_NAME``
|
37
|
+
and should be based on the model name chosen during setup.
|
38
|
+
chat_model (str): the chat model name to use. Can be set via
|
39
|
+
the env variable ``AZURE_OPENAI_CHAT_MODEL``.
|
40
|
+
Recommended to use this instead of ``model_name``.
|
41
|
+
|
42
|
+
"""
|
43
|
+
|
44
|
+
api_key: str = "" # CAUTION: set this ONLY via env var AZURE_OPENAI_API_KEY
|
45
|
+
type: str = "azure"
|
46
|
+
api_version: str = "2023-05-15"
|
47
|
+
deployment_name: str | None = None
|
48
|
+
model_name: str = ""
|
49
|
+
api_base: str = ""
|
50
|
+
|
51
|
+
# Alternatively, bring your own clients:
|
52
|
+
azure_openai_client_provider: Callable[[], AzureOpenAI] | None = None
|
53
|
+
azure_openai_async_client_provider: Callable[[], AsyncAzureOpenAI] | None = None
|
54
|
+
|
55
|
+
# all of the vars above can be set via env vars,
|
56
|
+
# by upper-casing the name and prefixing with `env_prefix`, e.g.
|
57
|
+
# AZURE_OPENAI_API_VERSION=2023-05-15
|
58
|
+
# This is either done in the .env file, or via an explicit
|
59
|
+
# `export AZURE_OPENAI_API_VERSION=...`
|
60
|
+
model_config = ConfigDict(env_prefix="AZURE_OPENAI_")
|
61
|
+
|
62
|
+
def __init__(self, **kwargs) -> None: # type: ignore
|
63
|
+
if "model_name" in kwargs and "chat_model" not in kwargs:
|
64
|
+
kwargs["chat_model"] = kwargs["model_name"]
|
65
|
+
super().__init__(**kwargs)
|
66
|
+
|
67
|
+
|
68
|
+
class AzureGPT(OpenAIGPT):
|
69
|
+
"""
|
70
|
+
Class to access OpenAI LLMs via Azure. These env variables can be obtained from the
|
71
|
+
file `.azure_env`. Azure OpenAI doesn't support ``completion``
|
72
|
+
"""
|
73
|
+
|
74
|
+
def __init__(self, config: AzureConfig):
|
75
|
+
# This will auto-populate config values from .env file
|
76
|
+
load_dotenv()
|
77
|
+
super().__init__(config)
|
78
|
+
self.config: AzureConfig = config
|
79
|
+
|
80
|
+
if (
|
81
|
+
self.config.azure_openai_client_provider
|
82
|
+
or self.config.azure_openai_async_client_provider
|
83
|
+
):
|
84
|
+
if not self.config.azure_openai_client_provider:
|
85
|
+
self.client = None
|
86
|
+
logger.warning(
|
87
|
+
"Using user-provided Azure OpenAI client, but only async "
|
88
|
+
"client has been provided. Synchronous calls will fail."
|
89
|
+
)
|
90
|
+
if not self.config.azure_openai_async_client_provider:
|
91
|
+
self.async_client = None
|
92
|
+
logger.warning(
|
93
|
+
"Using user-provided Azure OpenAI client, but no async "
|
94
|
+
"client has been provided. Asynchronous calls will fail."
|
95
|
+
)
|
96
|
+
|
97
|
+
if self.config.azure_openai_client_provider:
|
98
|
+
self.client = self.config.azure_openai_client_provider()
|
99
|
+
if self.config.azure_openai_async_client_provider:
|
100
|
+
self.async_client = self.config.azure_openai_async_client_provider()
|
101
|
+
self.async_client.timeout = Timeout(self.config.timeout)
|
102
|
+
else:
|
103
|
+
if self.config.api_key == "":
|
104
|
+
raise ValueError(
|
105
|
+
"""
|
106
|
+
AZURE_OPENAI_API_KEY not set in .env file,
|
107
|
+
please set it to your Azure API key."""
|
108
|
+
)
|
109
|
+
|
110
|
+
if self.config.api_base == "":
|
111
|
+
raise ValueError(
|
112
|
+
"""
|
113
|
+
AZURE_OPENAI_API_BASE not set in .env file,
|
114
|
+
please set it to your Azure API key."""
|
115
|
+
)
|
116
|
+
|
117
|
+
self.client = AzureOpenAI(
|
118
|
+
api_key=self.config.api_key,
|
119
|
+
azure_endpoint=self.config.api_base,
|
120
|
+
api_version=self.config.api_version,
|
121
|
+
azure_deployment=self.config.deployment_name,
|
122
|
+
)
|
123
|
+
self.async_client = AsyncAzureOpenAI(
|
124
|
+
api_key=self.config.api_key,
|
125
|
+
azure_endpoint=self.config.api_base,
|
126
|
+
api_version=self.config.api_version,
|
127
|
+
azure_deployment=self.config.deployment_name,
|
128
|
+
timeout=Timeout(self.config.timeout),
|
129
|
+
)
|
130
|
+
|
131
|
+
self.supports_json_schema = (
|
132
|
+
self.config.api_version >= azureStructuredOutputAPIMin
|
133
|
+
and self.config.api_version in azureStructuredOutputList
|
134
|
+
)
|
langroid/language_models/base.py
CHANGED
@@ -17,6 +17,9 @@ from typing import (
|
|
17
17
|
cast,
|
18
18
|
)
|
19
19
|
|
20
|
+
from pydantic import BaseModel, Field
|
21
|
+
from pydantic_settings import BaseSettings
|
22
|
+
|
20
23
|
from langroid.cachedb.base import CacheDBConfig
|
21
24
|
from langroid.cachedb.redis_cachedb import RedisCacheConfig
|
22
25
|
from langroid.language_models.model_info import ModelInfo, get_model_info
|
@@ -24,7 +27,6 @@ from langroid.parsing.agent_chats import parse_message
|
|
24
27
|
from langroid.parsing.file_attachment import FileAttachment
|
25
28
|
from langroid.parsing.parse_json import parse_imperfect_json, top_level_json_field
|
26
29
|
from langroid.prompts.dialog import collate_chat_history
|
27
|
-
from langroid.pydantic_v1 import BaseModel, BaseSettings, Field
|
28
30
|
from langroid.utils.configuration import settings
|
29
31
|
from langroid.utils.output.printing import show_if_debug
|
30
32
|
|
@@ -140,7 +142,7 @@ class LLMFunctionCall(BaseModel):
|
|
140
142
|
return fun_call
|
141
143
|
|
142
144
|
def __str__(self) -> str:
|
143
|
-
return "FUNC: " + json.dumps(self.
|
145
|
+
return "FUNC: " + json.dumps(self.model_dump(), indent=2)
|
144
146
|
|
145
147
|
|
146
148
|
class LLMFunctionSpec(BaseModel):
|
@@ -186,7 +188,7 @@ class OpenAIToolCall(BaseModel):
|
|
186
188
|
def __str__(self) -> str:
|
187
189
|
if self.function is None:
|
188
190
|
return ""
|
189
|
-
return "OAI-TOOL: " + json.dumps(self.function.
|
191
|
+
return "OAI-TOOL: " + json.dumps(self.function.model_dump(), indent=2)
|
190
192
|
|
191
193
|
|
192
194
|
class OpenAIToolSpec(BaseModel):
|
@@ -292,7 +294,7 @@ class LLMMessage(BaseModel):
|
|
292
294
|
Returns:
|
293
295
|
dict: dictionary representation of LLM message
|
294
296
|
"""
|
295
|
-
d = self.
|
297
|
+
d = self.model_dump()
|
296
298
|
files: List[FileAttachment] = d.pop("files")
|
297
299
|
if len(files) > 0 and self.role == Role.USER:
|
298
300
|
# In there are files, then content is an array of
|