langroid 0.1.40__py3-none-any.whl → 0.1.41__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/special/table_chat_agent.py +63 -7
- langroid/language_models/openai_gpt.py +3 -3
- {langroid-0.1.40.dist-info → langroid-0.1.41.dist-info}/METADATA +17 -2
- {langroid-0.1.40.dist-info → langroid-0.1.41.dist-info}/RECORD +6 -6
- {langroid-0.1.40.dist-info → langroid-0.1.41.dist-info}/LICENSE +0 -0
- {langroid-0.1.40.dist-info → langroid-0.1.41.dist-info}/WHEEL +0 -0
@@ -10,7 +10,9 @@ the code and returns the result as a string.
|
|
10
10
|
import io
|
11
11
|
import logging
|
12
12
|
import sys
|
13
|
+
from typing import no_type_check
|
13
14
|
|
15
|
+
import numpy as np
|
14
16
|
import pandas as pd
|
15
17
|
from rich.console import Console
|
16
18
|
|
@@ -26,16 +28,72 @@ logger = logging.getLogger(__name__)
|
|
26
28
|
console = Console()
|
27
29
|
|
28
30
|
DEFAULT_TABLE_CHAT_SYSTEM_MESSAGE = """
|
29
|
-
You are a savvy data scientist, with expertise in analyzing tabular
|
31
|
+
You are a savvy data scientist, with expertise in analyzing tabular datasets,
|
30
32
|
using Python and the Pandas library for dataframe manipulation.
|
31
33
|
Since you do not have access to the dataframe 'df', you
|
32
34
|
will need to use the `run_code` tool/function-call to answer the question.
|
33
|
-
|
34
|
-
{
|
35
|
+
Here is a summary of the dataframe:
|
36
|
+
{summary}
|
35
37
|
Do not assume any columns other than those shown.
|
38
|
+
In the code you submit to the `run_code` tool/function,
|
39
|
+
do not forget to include any necessary imports, such as `import pandas as pd`.
|
40
|
+
Sometimes you may not be able to answer the question in a single call to `run_code`,
|
41
|
+
so you can use a series of calls to `run_code` to build up the answer.
|
42
|
+
For example you may first want to know something about the possible values in a column.
|
43
|
+
|
44
|
+
If you receive a null or other unexpected result, see if you have made an assumption
|
45
|
+
in your code, and try another way, or use `run_code` to explore the dataframe
|
46
|
+
before submitting your final code.
|
47
|
+
|
48
|
+
Start by asking me what I want to know about the data.
|
36
49
|
"""
|
37
50
|
|
38
51
|
|
52
|
+
@no_type_check
|
53
|
+
def dataframe_summary(df: pd.DataFrame) -> str:
|
54
|
+
"""
|
55
|
+
Generate a structured summary for a pandas DataFrame containing numerical
|
56
|
+
and categorical values.
|
57
|
+
|
58
|
+
Args:
|
59
|
+
df (pd.DataFrame): The input DataFrame to summarize.
|
60
|
+
|
61
|
+
Returns:
|
62
|
+
str: A nicely structured and formatted summary string.
|
63
|
+
"""
|
64
|
+
|
65
|
+
# Column names display
|
66
|
+
col_names_str = (
|
67
|
+
"COLUMN NAMES:\n" + " ".join([f"'{col}'" for col in df.columns]) + "\n\n"
|
68
|
+
)
|
69
|
+
|
70
|
+
# Numerical data summary
|
71
|
+
num_summary = df.describe().applymap(lambda x: "{:.2f}".format(x))
|
72
|
+
num_str = "Numerical Column Summary:\n" + num_summary.to_string() + "\n\n"
|
73
|
+
|
74
|
+
# Categorical data summary
|
75
|
+
cat_columns = df.select_dtypes(include=[np.object_]).columns
|
76
|
+
cat_summary_list = []
|
77
|
+
|
78
|
+
for col in cat_columns:
|
79
|
+
unique_values = df[col].unique()
|
80
|
+
if len(unique_values) < 10:
|
81
|
+
cat_summary_list.append(f"'{col}': {', '.join(map(str, unique_values))}")
|
82
|
+
else:
|
83
|
+
cat_summary_list.append(f"'{col}': {df[col].nunique()} unique values")
|
84
|
+
|
85
|
+
cat_str = "Categorical Column Summary:\n" + "\n".join(cat_summary_list) + "\n\n"
|
86
|
+
|
87
|
+
# Missing values summary
|
88
|
+
nan_summary = df.isnull().sum().rename("missing_values").to_frame()
|
89
|
+
nan_str = "Missing Values Column Summary:\n" + nan_summary.to_string() + "\n"
|
90
|
+
|
91
|
+
# Combine the summaries into one structured string
|
92
|
+
summary_str = col_names_str + num_str + cat_str + nan_str
|
93
|
+
|
94
|
+
return summary_str
|
95
|
+
|
96
|
+
|
39
97
|
class TableChatAgentConfig(ChatAgentConfig):
|
40
98
|
system_message: str = DEFAULT_TABLE_CHAT_SYSTEM_MESSAGE
|
41
99
|
user_message: None | str = None
|
@@ -77,10 +135,8 @@ class TableChatAgent(ChatAgent):
|
|
77
135
|
df = read_tabular_data(config.data, config.separator)
|
78
136
|
|
79
137
|
self.df = df
|
80
|
-
|
81
|
-
config.system_message = config.system_message.format(
|
82
|
-
columns=", ".join(columns_with_quotes)
|
83
|
-
)
|
138
|
+
summary = dataframe_summary(df)
|
139
|
+
config.system_message = config.system_message.format(summary=summary)
|
84
140
|
|
85
141
|
super().__init__(config)
|
86
142
|
self.config: TableChatAgentConfig = config
|
@@ -4,7 +4,7 @@ import logging
|
|
4
4
|
import os
|
5
5
|
import sys
|
6
6
|
from enum import Enum
|
7
|
-
from typing import Any, Dict, List, Optional, Tuple, Union
|
7
|
+
from typing import Any, Dict, List, Optional, Tuple, Union
|
8
8
|
|
9
9
|
import openai
|
10
10
|
from dotenv import load_dotenv
|
@@ -361,13 +361,13 @@ class OpenAIGPT(LanguageModel):
|
|
361
361
|
LLMResponse object
|
362
362
|
"""
|
363
363
|
openai.api_key = self.api_key
|
364
|
-
if
|
364
|
+
if isinstance(messages, str):
|
365
365
|
llm_messages = [
|
366
366
|
LLMMessage(role=Role.SYSTEM, content="You are a helpful assistant."),
|
367
367
|
LLMMessage(role=Role.USER, content=messages),
|
368
368
|
]
|
369
369
|
else:
|
370
|
-
llm_messages =
|
370
|
+
llm_messages = messages
|
371
371
|
|
372
372
|
@retry_with_exponential_backoff
|
373
373
|
def completions_with_backoff(**kwargs): # type: ignore
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: langroid
|
3
|
-
Version: 0.1.
|
3
|
+
Version: 0.1.41
|
4
4
|
Summary: Harness LLMs with Multi-Agent Programming
|
5
5
|
License: MIT
|
6
6
|
Author: Prasad Chalasani
|
@@ -39,6 +39,7 @@ Requires-Dist: openai (>=0.27.5,<0.28.0)
|
|
39
39
|
Requires-Dist: pandas (>=2.0.3,<3.0.0)
|
40
40
|
Requires-Dist: pre-commit (>=3.3.2,<4.0.0)
|
41
41
|
Requires-Dist: prettytable (>=3.8.0,<4.0.0)
|
42
|
+
Requires-Dist: psycopg2 (>=2.9.7,<3.0.0)
|
42
43
|
Requires-Dist: pydantic (==1.10.11)
|
43
44
|
Requires-Dist: pygithub (>=1.58.1,<2.0.0)
|
44
45
|
Requires-Dist: pygments (>=2.15.1,<3.0.0)
|
@@ -77,6 +78,8 @@ Description-Content-Type: text/markdown
|
|
77
78
|
[](https://discord.gg/ZU36McDgDs)
|
78
79
|
[](https://colab.research.google.com/github/langroid/langroid/blob/main/examples/langroid_quick_examples.ipynb)
|
79
80
|
|
81
|
+
[](https://twitter.com/intent/tweet?text=Langroid%20is%20a%20powerful,%20elegant%20new%20framework%20to%20easily%20build%20%23LLM%20applications.%20You%20set%20up%20LLM-powered%20Agents%20with%20vector-stores,%20assign%20tasks,%20and%20have%20them%20collaboratively%20solve%20problems%20via%20message-transformations.%20https://github.com/langroid/langroid)
|
82
|
+
[](https://www.linkedin.com/shareArticle?mini=true&url=https://github.com/langroid/langroid&title=Langroid:%20A%20Powerful,%20Elegant%20Framework&summary=Langroid%20is%20a%20powerful,%20elegant%20new%20framework%20to%20easily%20build%20%23LLM%20applications.%20You%20set%20up%20LLM-powered%20Agents%20with%20vector-stores,%20assign%20tasks,%20and%20have%20them%20collaboratively%20solve%20problems%20via%20message-transformations.)
|
80
83
|
|
81
84
|
</div>
|
82
85
|
|
@@ -114,6 +117,7 @@ for ideas on what to contribute.
|
|
114
117
|
<summary> <b>:fire: Updates/Releases</b></summary>
|
115
118
|
|
116
119
|
- **Aug 2023:**
|
120
|
+
- **Example:** [Answer questions](examples/docqa/chat-search.py) using Google Search + vecdb-retrieval from URL contents.
|
117
121
|
- **0.1.39:** [`GoogleSearchTool`](langroid/agent/stateless_tools/google_search_tool.py) to enable Agents (their LLM) to do Google searches via function-calling/tools.
|
118
122
|
See [this chat example](examples/basic/chat-search.py) for how easy it is to add this tool to an agent.
|
119
123
|
- **Colab notebook** to try the quick-start examples: [](https://colab.research.google.com/github/langroid/langroid/blob/main/examples/langroid_quick_examples.ipynb)
|
@@ -662,7 +666,18 @@ script in the `langroid-examples` repo.
|
|
662
666
|
|
663
667
|
# :heart: Thank you to our [supporters](https://github.com/langroid/langroid/stargazers)
|
664
668
|
|
665
|
-
If you like this
|
669
|
+
If you like this project, please give it a star ⭐ and 📢 spread the word in your network:
|
670
|
+
|
671
|
+
[](https://twitter.com/intent/tweet?text=Langroid%20is%20a%20powerful,%20elegant%20new%20framework%20to%20easily%20build%20%23LLM%20applications.%20You%20set%20up%20LLM-powered%20Agents%20with%20vector-stores,%20assign%20tasks,%20and%20have%20them%20collaboratively%20solve%20problems%20via%20message-transformations.%20https://github.com/langroid/langroid)
|
672
|
+
[](https://www.linkedin.com/shareArticle?mini=true&url=https://github.com/langroid/langroid&title=Langroid:%20A%20Powerful,%20Elegant%20Framework&summary=Langroid%20is%20a%20powerful,%20elegant%20new%20framework%20to%20easily%20build%20%23LLM%20applications.%20You%20set%20up%20LLM-powered%20Agents%20with%20vector-stores,%20assign%20tasks,%20and%20have%20them%20collaboratively%20solve%20problems%20via%20message-transformations.)
|
673
|
+
|
674
|
+
|
675
|
+
|
676
|
+
|
677
|
+
Your support will help build Langroid's momentum and community.
|
678
|
+
|
679
|
+
|
680
|
+
|
666
681
|
|
667
682
|
# Langroid Co-Founders
|
668
683
|
|
@@ -10,7 +10,7 @@ langroid/agent/special/doc_chat_agent.py,sha256=FjuHxV6OyHvPcHuPgsm9kXMIL8qVhOM8
|
|
10
10
|
langroid/agent/special/recipient_validator_agent.py,sha256=x2UprcGlh-fyxQCZbb_fkKrruU5Om0mgOnNzk_PYBNM,4527
|
11
11
|
langroid/agent/special/retriever_agent.py,sha256=DeOB5crFjXBvDEZT9k9ZVinOfFM2VgS6tQWWFyXSk9o,7204
|
12
12
|
langroid/agent/special/sql_chat_agent.py,sha256=2pw8o-0ul909HAOUO3G7SVVAaB3qVBkjtaXneNzy1x0,10215
|
13
|
-
langroid/agent/special/table_chat_agent.py,sha256=
|
13
|
+
langroid/agent/special/table_chat_agent.py,sha256=L0T6Tj_3AMckwWI2HTb19hyp7r3P77KEFMldkT3acUU,7058
|
14
14
|
langroid/agent/stateless_tools/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
15
15
|
langroid/agent/stateless_tools/google_search_tool.py,sha256=64F9oMNdS237BBOitrvYXN4Il_ES_fNrHkh35tBEDfA,1160
|
16
16
|
langroid/agent/task.py,sha256=KJZt6lSfCAVctyFfBJWLFcfys73kjrQJV4Y3aMVwO1M,26233
|
@@ -26,7 +26,7 @@ langroid/embedding_models/clustering.py,sha256=tZWElUqXl9Etqla0FAa7og96iDKgjqWju
|
|
26
26
|
langroid/embedding_models/models.py,sha256=1xcv9hqmCTsbUbS8v7XeZRsf25Tu79JUoSipIYpvNoo,2765
|
27
27
|
langroid/language_models/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
28
28
|
langroid/language_models/base.py,sha256=7FMiUyJ3Kf9Uiqvjh-lNGfwnCibY0SbnK4jdORCv3SM,12657
|
29
|
-
langroid/language_models/openai_gpt.py,sha256=
|
29
|
+
langroid/language_models/openai_gpt.py,sha256=L5Lm3ApOflqMI3405rR5Wp6tAFKTGsPc0iQAVNdV9N8,17947
|
30
30
|
langroid/language_models/utils.py,sha256=rmnSn-sJ3aKl_wBdeLPkck0Li4Ed6zkCxZYYl7n1V34,4668
|
31
31
|
langroid/mytypes.py,sha256=YA42IJcooJnTxAwk-B4FmZ1hqzIIF1ZZKcpUKzBTGGo,1537
|
32
32
|
langroid/parsing/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
@@ -68,7 +68,7 @@ langroid/vector_store/base.py,sha256=QZx3NUNwf2I0r3A7iuoUHIRGbqt_pFGD0hq1R-Yg8iM
|
|
68
68
|
langroid/vector_store/chromadb.py,sha256=s5pQkKjaMP-Tt5A8M10EInFzttaALPbJAq7q4gf0TKg,5235
|
69
69
|
langroid/vector_store/qdrant_cloud.py,sha256=3im4Mip0QXLkR6wiqVsjV1QvhSElfxdFSuDKddBDQ-4,188
|
70
70
|
langroid/vector_store/qdrantdb.py,sha256=KRvIIj1IZG2zFqejofMnRs2hT86B-27LgBEnuczdqOU,9072
|
71
|
-
langroid-0.1.
|
72
|
-
langroid-0.1.
|
73
|
-
langroid-0.1.
|
74
|
-
langroid-0.1.
|
71
|
+
langroid-0.1.41.dist-info/LICENSE,sha256=EgVbvA6VSYgUlvC3RvPKehSg7MFaxWDsFuzLOsPPfJg,1065
|
72
|
+
langroid-0.1.41.dist-info/WHEEL,sha256=vVCvjcmxuUltf8cYhJ0sJMRDLr1XsPuxEId8YDzbyCY,88
|
73
|
+
langroid-0.1.41.dist-info/METADATA,sha256=eIqNnzfP3fq3V05ResrFM7U8k16CYgJ8Je4VTZEjqLo,29766
|
74
|
+
langroid-0.1.41.dist-info/RECORD,,
|
File without changes
|
File without changes
|