PraisonAI 2.0.61__cp313-cp313-manylinux_2_39_x86_64.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 PraisonAI might be problematic. Click here for more details.
- praisonai/__init__.py +6 -0
- praisonai/__main__.py +10 -0
- praisonai/agents_generator.py +648 -0
- praisonai/api/call.py +292 -0
- praisonai/auto.py +238 -0
- praisonai/chainlit_ui.py +304 -0
- praisonai/cli.py +518 -0
- praisonai/deploy.py +138 -0
- praisonai/inbuilt_tools/__init__.py +24 -0
- praisonai/inbuilt_tools/autogen_tools.py +117 -0
- praisonai/inc/__init__.py +2 -0
- praisonai/inc/config.py +96 -0
- praisonai/inc/models.py +128 -0
- praisonai/public/android-chrome-192x192.png +0 -0
- praisonai/public/android-chrome-512x512.png +0 -0
- praisonai/public/apple-touch-icon.png +0 -0
- praisonai/public/fantasy.svg +3 -0
- praisonai/public/favicon-16x16.png +0 -0
- praisonai/public/favicon-32x32.png +0 -0
- praisonai/public/favicon.ico +0 -0
- praisonai/public/game.svg +3 -0
- praisonai/public/logo_dark.png +0 -0
- praisonai/public/logo_light.png +0 -0
- praisonai/public/movie.svg +3 -0
- praisonai/public/praison-ai-agents-architecture-dark.png +0 -0
- praisonai/public/praison-ai-agents-architecture.png +0 -0
- praisonai/public/thriller.svg +3 -0
- praisonai/setup/__init__.py +1 -0
- praisonai/setup/build.py +21 -0
- praisonai/setup/config.yaml +60 -0
- praisonai/setup/post_install.py +23 -0
- praisonai/setup/setup_conda_env.py +25 -0
- praisonai/setup/setup_conda_env.sh +72 -0
- praisonai/setup.py +16 -0
- praisonai/test.py +105 -0
- praisonai/train.py +276 -0
- praisonai/ui/README.md +21 -0
- praisonai/ui/agents.py +822 -0
- praisonai/ui/callbacks.py +57 -0
- praisonai/ui/chat.py +387 -0
- praisonai/ui/code.py +440 -0
- praisonai/ui/colab.py +474 -0
- praisonai/ui/colab_chainlit.py +81 -0
- praisonai/ui/components/aicoder.py +269 -0
- praisonai/ui/config/.chainlit/config.toml +120 -0
- praisonai/ui/config/.chainlit/translations/bn.json +231 -0
- praisonai/ui/config/.chainlit/translations/en-US.json +229 -0
- praisonai/ui/config/.chainlit/translations/gu.json +231 -0
- praisonai/ui/config/.chainlit/translations/he-IL.json +231 -0
- praisonai/ui/config/.chainlit/translations/hi.json +231 -0
- praisonai/ui/config/.chainlit/translations/kn.json +231 -0
- praisonai/ui/config/.chainlit/translations/ml.json +231 -0
- praisonai/ui/config/.chainlit/translations/mr.json +231 -0
- praisonai/ui/config/.chainlit/translations/ta.json +231 -0
- praisonai/ui/config/.chainlit/translations/te.json +231 -0
- praisonai/ui/config/.chainlit/translations/zh-CN.json +229 -0
- praisonai/ui/config/chainlit.md +1 -0
- praisonai/ui/config/translations/bn.json +231 -0
- praisonai/ui/config/translations/en-US.json +229 -0
- praisonai/ui/config/translations/gu.json +231 -0
- praisonai/ui/config/translations/he-IL.json +231 -0
- praisonai/ui/config/translations/hi.json +231 -0
- praisonai/ui/config/translations/kn.json +231 -0
- praisonai/ui/config/translations/ml.json +231 -0
- praisonai/ui/config/translations/mr.json +231 -0
- praisonai/ui/config/translations/ta.json +231 -0
- praisonai/ui/config/translations/te.json +231 -0
- praisonai/ui/config/translations/zh-CN.json +229 -0
- praisonai/ui/context.py +283 -0
- praisonai/ui/db.py +291 -0
- praisonai/ui/public/fantasy.svg +3 -0
- praisonai/ui/public/game.svg +3 -0
- praisonai/ui/public/logo_dark.png +0 -0
- praisonai/ui/public/logo_light.png +0 -0
- praisonai/ui/public/movie.svg +3 -0
- praisonai/ui/public/praison.css +3 -0
- praisonai/ui/public/thriller.svg +3 -0
- praisonai/ui/realtime.py +476 -0
- praisonai/ui/realtimeclient/__init__.py +653 -0
- praisonai/ui/realtimeclient/realtimedocs.txt +1484 -0
- praisonai/ui/realtimeclient/tools.py +236 -0
- praisonai/ui/sql_alchemy.py +707 -0
- praisonai/ui/tools.md +133 -0
- praisonai/version.py +1 -0
- praisonai-2.0.61.dist-info/LICENSE +20 -0
- praisonai-2.0.61.dist-info/METADATA +679 -0
- praisonai-2.0.61.dist-info/RECORD +89 -0
- praisonai-2.0.61.dist-info/WHEEL +4 -0
- praisonai-2.0.61.dist-info/entry_points.txt +5 -0
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
{
|
|
2
|
+
"components": {
|
|
3
|
+
"atoms": {
|
|
4
|
+
"buttons": {
|
|
5
|
+
"userButton": {
|
|
6
|
+
"menu": {
|
|
7
|
+
"settings": "\u8bbe\u7f6e",
|
|
8
|
+
"settingsKey": "S",
|
|
9
|
+
"APIKeys": "API \u5bc6\u94a5",
|
|
10
|
+
"logout": "\u767b\u51fa"
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"molecules": {
|
|
16
|
+
"newChatButton": {
|
|
17
|
+
"newChat": "\u65b0\u5efa\u5bf9\u8bdd"
|
|
18
|
+
},
|
|
19
|
+
"tasklist": {
|
|
20
|
+
"TaskList": {
|
|
21
|
+
"title": "\ud83d\uddd2\ufe0f \u4efb\u52a1\u5217\u8868",
|
|
22
|
+
"loading": "\u52a0\u8f7d\u4e2d...",
|
|
23
|
+
"error": "\u53d1\u751f\u9519\u8bef"
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
"attachments": {
|
|
27
|
+
"cancelUpload": "\u53d6\u6d88\u4e0a\u4f20",
|
|
28
|
+
"removeAttachment": "\u79fb\u9664\u9644\u4ef6"
|
|
29
|
+
},
|
|
30
|
+
"newChatDialog": {
|
|
31
|
+
"createNewChat": "\u521b\u5efa\u65b0\u5bf9\u8bdd\uff1f",
|
|
32
|
+
"clearChat": "\u8fd9\u5c06\u6e05\u9664\u5f53\u524d\u6d88\u606f\u5e76\u5f00\u59cb\u65b0\u7684\u5bf9\u8bdd\u3002",
|
|
33
|
+
"cancel": "\u53d6\u6d88",
|
|
34
|
+
"confirm": "\u786e\u8ba4"
|
|
35
|
+
},
|
|
36
|
+
"settingsModal": {
|
|
37
|
+
"settings": "\u8bbe\u7f6e",
|
|
38
|
+
"expandMessages": "\u5c55\u5f00\u6d88\u606f",
|
|
39
|
+
"hideChainOfThought": "\u9690\u85cf\u601d\u8003\u94fe",
|
|
40
|
+
"darkMode": "\u6697\u8272\u6a21\u5f0f"
|
|
41
|
+
},
|
|
42
|
+
"detailsButton": {
|
|
43
|
+
"using": "\u4f7f\u7528",
|
|
44
|
+
"used": "\u5df2\u7528"
|
|
45
|
+
},
|
|
46
|
+
"auth": {
|
|
47
|
+
"authLogin": {
|
|
48
|
+
"title": "\u767b\u5f55\u4ee5\u8bbf\u95ee\u5e94\u7528\u3002",
|
|
49
|
+
"form": {
|
|
50
|
+
"email": "\u7535\u5b50\u90ae\u7bb1\u5730\u5740",
|
|
51
|
+
"password": "\u5bc6\u7801",
|
|
52
|
+
"noAccount": "\u6ca1\u6709\u8d26\u6237\uff1f",
|
|
53
|
+
"alreadyHaveAccount": "\u5df2\u6709\u8d26\u6237\uff1f",
|
|
54
|
+
"signup": "\u6ce8\u518c",
|
|
55
|
+
"signin": "\u767b\u5f55",
|
|
56
|
+
"or": "\u6216\u8005",
|
|
57
|
+
"continue": "\u7ee7\u7eed",
|
|
58
|
+
"forgotPassword": "\u5fd8\u8bb0\u5bc6\u7801\uff1f",
|
|
59
|
+
"passwordMustContain": "\u60a8\u7684\u5bc6\u7801\u5fc5\u987b\u5305\u542b\uff1a",
|
|
60
|
+
"emailRequired": "\u7535\u5b50\u90ae\u7bb1\u662f\u5fc5\u586b\u9879",
|
|
61
|
+
"passwordRequired": "\u5bc6\u7801\u662f\u5fc5\u586b\u9879"
|
|
62
|
+
},
|
|
63
|
+
"error": {
|
|
64
|
+
"default": "\u65e0\u6cd5\u767b\u5f55\u3002",
|
|
65
|
+
"signin": "\u5c1d\u8bd5\u4f7f\u7528\u4e0d\u540c\u7684\u8d26\u6237\u767b\u5f55\u3002",
|
|
66
|
+
"oauthsignin": "\u5c1d\u8bd5\u4f7f\u7528\u4e0d\u540c\u7684\u8d26\u6237\u767b\u5f55\u3002",
|
|
67
|
+
"redirect_uri_mismatch": "\u91cd\u5b9a\u5411URI\u4e0eOAuth\u5e94\u7528\u914d\u7f6e\u4e0d\u5339\u914d\u3002",
|
|
68
|
+
"oauthcallbackerror": "\u5c1d\u8bd5\u4f7f\u7528\u4e0d\u540c\u7684\u8d26\u6237\u767b\u5f55\u3002",
|
|
69
|
+
"oauthcreateaccount": "\u5c1d\u8bd5\u4f7f\u7528\u4e0d\u540c\u7684\u8d26\u6237\u767b\u5f55\u3002",
|
|
70
|
+
"emailcreateaccount": "\u5c1d\u8bd5\u4f7f\u7528\u4e0d\u540c\u7684\u8d26\u6237\u767b\u5f55\u3002",
|
|
71
|
+
"callback": "\u5c1d\u8bd5\u4f7f\u7528\u4e0d\u540c\u7684\u8d26\u6237\u767b\u5f55\u3002",
|
|
72
|
+
"oauthaccountnotlinked": "\u4e3a\u4e86\u9a8c\u8bc1\u60a8\u7684\u8eab\u4efd\uff0c\u8bf7\u4f7f\u7528\u6700\u521d\u4f7f\u7528\u7684\u540c\u4e00\u8d26\u6237\u767b\u5f55\u3002",
|
|
73
|
+
"emailsignin": "\u65e0\u6cd5\u53d1\u9001\u90ae\u4ef6\u3002",
|
|
74
|
+
"emailverify": "\u8bf7\u9a8c\u8bc1\u60a8\u7684\u7535\u5b50\u90ae\u4ef6\uff0c\u5df2\u53d1\u9001\u4e00\u5c01\u65b0\u90ae\u4ef6\u3002",
|
|
75
|
+
"credentialssignin": "\u767b\u5f55\u5931\u8d25\u3002\u8bf7\u68c0\u67e5\u60a8\u63d0\u4f9b\u7684\u8be6\u7ec6\u4fe1\u606f\u662f\u5426\u6b63\u786e\u3002",
|
|
76
|
+
"sessionrequired": "\u8bf7\u767b\u5f55\u4ee5\u8bbf\u95ee\u6b64\u9875\u9762\u3002"
|
|
77
|
+
}
|
|
78
|
+
},
|
|
79
|
+
"authVerifyEmail": {
|
|
80
|
+
"almostThere": "\u60a8\u5feb\u6210\u529f\u4e86\uff01\u6211\u4eec\u5df2\u5411 ",
|
|
81
|
+
"verifyEmailLink": "\u8bf7\u5355\u51fb\u8be5\u90ae\u4ef6\u4e2d\u7684\u94fe\u63a5\u4ee5\u5b8c\u6210\u6ce8\u518c\u3002",
|
|
82
|
+
"didNotReceive": "\u6ca1\u627e\u5230\u90ae\u4ef6\uff1f",
|
|
83
|
+
"resendEmail": "\u91cd\u65b0\u53d1\u9001\u90ae\u4ef6",
|
|
84
|
+
"goBack": "\u8fd4\u56de",
|
|
85
|
+
"emailSent": "\u90ae\u4ef6\u5df2\u6210\u529f\u53d1\u9001\u3002",
|
|
86
|
+
"verifyEmail": "\u9a8c\u8bc1\u60a8\u7684\u7535\u5b50\u90ae\u4ef6\u5730\u5740"
|
|
87
|
+
},
|
|
88
|
+
"providerButton": {
|
|
89
|
+
"continue": "\u4f7f\u7528{{provider}}\u7ee7\u7eed",
|
|
90
|
+
"signup": "\u4f7f\u7528{{provider}}\u6ce8\u518c"
|
|
91
|
+
},
|
|
92
|
+
"authResetPassword": {
|
|
93
|
+
"newPasswordRequired": "\u65b0\u5bc6\u7801\u662f\u5fc5\u586b\u9879",
|
|
94
|
+
"passwordsMustMatch": "\u5bc6\u7801\u5fc5\u987b\u4e00\u81f4",
|
|
95
|
+
"confirmPasswordRequired": "\u786e\u8ba4\u5bc6\u7801\u662f\u5fc5\u586b\u9879",
|
|
96
|
+
"newPassword": "\u65b0\u5bc6\u7801",
|
|
97
|
+
"confirmPassword": "\u786e\u8ba4\u5bc6\u7801",
|
|
98
|
+
"resetPassword": "\u91cd\u7f6e\u5bc6\u7801"
|
|
99
|
+
},
|
|
100
|
+
"authForgotPassword": {
|
|
101
|
+
"email": "\u7535\u5b50\u90ae\u7bb1\u5730\u5740",
|
|
102
|
+
"emailRequired": "\u7535\u5b50\u90ae\u7bb1\u662f\u5fc5\u586b\u9879",
|
|
103
|
+
"emailSent": "\u8bf7\u68c0\u67e5\u7535\u5b50\u90ae\u7bb1{{email}}\u4ee5\u83b7\u53d6\u91cd\u7f6e\u5bc6\u7801\u7684\u6307\u793a\u3002",
|
|
104
|
+
"enterEmail": "\u8bf7\u8f93\u5165\u60a8\u7684\u7535\u5b50\u90ae\u7bb1\u5730\u5740\uff0c\u6211\u4eec\u5c06\u53d1\u9001\u91cd\u7f6e\u5bc6\u7801\u7684\u6307\u793a\u3002",
|
|
105
|
+
"resendEmail": "\u91cd\u65b0\u53d1\u9001\u90ae\u4ef6",
|
|
106
|
+
"continue": "\u7ee7\u7eed",
|
|
107
|
+
"goBack": "\u8fd4\u56de"
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
},
|
|
111
|
+
"organisms": {
|
|
112
|
+
"chat": {
|
|
113
|
+
"history": {
|
|
114
|
+
"index": {
|
|
115
|
+
"showHistory": "\u663e\u793a\u5386\u53f2",
|
|
116
|
+
"lastInputs": "\u6700\u540e\u8f93\u5165",
|
|
117
|
+
"noInputs": "\u5982\u6b64\u7a7a\u65f7...",
|
|
118
|
+
"loading": "\u52a0\u8f7d\u4e2d..."
|
|
119
|
+
}
|
|
120
|
+
},
|
|
121
|
+
"inputBox": {
|
|
122
|
+
"input": {
|
|
123
|
+
"placeholder": "\u5728\u8fd9\u91cc\u8f93\u5165\u60a8\u7684\u6d88\u606f..."
|
|
124
|
+
},
|
|
125
|
+
"speechButton": {
|
|
126
|
+
"start": "\u5f00\u59cb\u5f55\u97f3",
|
|
127
|
+
"stop": "\u505c\u6b62\u5f55\u97f3"
|
|
128
|
+
},
|
|
129
|
+
"SubmitButton": {
|
|
130
|
+
"sendMessage": "\u53d1\u9001\u6d88\u606f",
|
|
131
|
+
"stopTask": "\u505c\u6b62\u4efb\u52a1"
|
|
132
|
+
},
|
|
133
|
+
"UploadButton": {
|
|
134
|
+
"attachFiles": "\u9644\u52a0\u6587\u4ef6"
|
|
135
|
+
},
|
|
136
|
+
"waterMark": {
|
|
137
|
+
"text": "\u4f7f\u7528"
|
|
138
|
+
}
|
|
139
|
+
},
|
|
140
|
+
"Messages": {
|
|
141
|
+
"index": {
|
|
142
|
+
"running": "\u8fd0\u884c\u4e2d",
|
|
143
|
+
"executedSuccessfully": "\u6267\u884c\u6210\u529f",
|
|
144
|
+
"failed": "\u5931\u8d25",
|
|
145
|
+
"feedbackUpdated": "\u53cd\u9988\u66f4\u65b0",
|
|
146
|
+
"updating": "\u6b63\u5728\u66f4\u65b0"
|
|
147
|
+
}
|
|
148
|
+
},
|
|
149
|
+
"dropScreen": {
|
|
150
|
+
"dropYourFilesHere": "\u5728\u8fd9\u91cc\u62d6\u653e\u60a8\u7684\u6587\u4ef6"
|
|
151
|
+
},
|
|
152
|
+
"index": {
|
|
153
|
+
"failedToUpload": "\u4e0a\u4f20\u5931\u8d25",
|
|
154
|
+
"cancelledUploadOf": "\u53d6\u6d88\u4e0a\u4f20",
|
|
155
|
+
"couldNotReachServer": "\u65e0\u6cd5\u8fde\u63a5\u5230\u670d\u52a1\u5668",
|
|
156
|
+
"continuingChat": "\u7ee7\u7eed\u4e4b\u524d\u7684\u5bf9\u8bdd"
|
|
157
|
+
},
|
|
158
|
+
"settings": {
|
|
159
|
+
"settingsPanel": "\u8bbe\u7f6e\u9762\u677f",
|
|
160
|
+
"reset": "\u91cd\u7f6e",
|
|
161
|
+
"cancel": "\u53d6\u6d88",
|
|
162
|
+
"confirm": "\u786e\u8ba4"
|
|
163
|
+
}
|
|
164
|
+
},
|
|
165
|
+
"threadHistory": {
|
|
166
|
+
"sidebar": {
|
|
167
|
+
"filters": {
|
|
168
|
+
"FeedbackSelect": {
|
|
169
|
+
"feedbackAll": "\u53cd\u9988\uff1a\u5168\u90e8",
|
|
170
|
+
"feedbackPositive": "\u53cd\u9988\uff1a\u6b63\u9762",
|
|
171
|
+
"feedbackNegative": "\u53cd\u9988\uff1a\u8d1f\u9762"
|
|
172
|
+
},
|
|
173
|
+
"SearchBar": {
|
|
174
|
+
"search": "\u641c\u7d22"
|
|
175
|
+
}
|
|
176
|
+
},
|
|
177
|
+
"DeleteThreadButton": {
|
|
178
|
+
"confirmMessage": "\u8fd9\u5c06\u5220\u9664\u7ebf\u7a0b\u53ca\u5176\u6d88\u606f\u548c\u5143\u7d20\u3002",
|
|
179
|
+
"cancel": "\u53d6\u6d88",
|
|
180
|
+
"confirm": "\u786e\u8ba4",
|
|
181
|
+
"deletingChat": "\u5220\u9664\u5bf9\u8bdd",
|
|
182
|
+
"chatDeleted": "\u5bf9\u8bdd\u5df2\u5220\u9664"
|
|
183
|
+
},
|
|
184
|
+
"index": {
|
|
185
|
+
"pastChats": "\u8fc7\u5f80\u5bf9\u8bdd"
|
|
186
|
+
},
|
|
187
|
+
"ThreadList": {
|
|
188
|
+
"empty": "\u7a7a\u7684...",
|
|
189
|
+
"today": "\u4eca\u5929",
|
|
190
|
+
"yesterday": "\u6628\u5929",
|
|
191
|
+
"previous7days": "\u524d7\u5929",
|
|
192
|
+
"previous30days": "\u524d30\u5929"
|
|
193
|
+
},
|
|
194
|
+
"TriggerButton": {
|
|
195
|
+
"closeSidebar": "\u5173\u95ed\u4fa7\u8fb9\u680f",
|
|
196
|
+
"openSidebar": "\u6253\u5f00\u4fa7\u8fb9\u680f"
|
|
197
|
+
}
|
|
198
|
+
},
|
|
199
|
+
"Thread": {
|
|
200
|
+
"backToChat": "\u8fd4\u56de\u5bf9\u8bdd",
|
|
201
|
+
"chatCreatedOn": "\u6b64\u5bf9\u8bdd\u521b\u5efa\u4e8e"
|
|
202
|
+
}
|
|
203
|
+
},
|
|
204
|
+
"header": {
|
|
205
|
+
"chat": "\u5bf9\u8bdd",
|
|
206
|
+
"readme": "\u8bf4\u660e"
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
},
|
|
210
|
+
"hooks": {
|
|
211
|
+
"useLLMProviders": {
|
|
212
|
+
"failedToFetchProviders": "\u83b7\u53d6\u63d0\u4f9b\u8005\u5931\u8d25:"
|
|
213
|
+
}
|
|
214
|
+
},
|
|
215
|
+
"pages": {
|
|
216
|
+
"Design": {},
|
|
217
|
+
"Env": {
|
|
218
|
+
"savedSuccessfully": "\u4fdd\u5b58\u6210\u529f",
|
|
219
|
+
"requiredApiKeys": "\u5fc5\u9700\u7684API\u5bc6\u94a5",
|
|
220
|
+
"requiredApiKeysInfo": "\u8981\u4f7f\u7528\u6b64\u5e94\u7528\uff0c\u9700\u8981\u4ee5\u4e0bAPI\u5bc6\u94a5\u3002\u8fd9\u4e9b\u5bc6\u94a5\u5b58\u50a8\u5728\u60a8\u7684\u8bbe\u5907\u672c\u5730\u5b58\u50a8\u4e2d\u3002"
|
|
221
|
+
},
|
|
222
|
+
"Page": {
|
|
223
|
+
"notPartOfProject": "\u60a8\u4e0d\u662f\u6b64\u9879\u76ee\u7684\u4e00\u90e8\u5206\u3002"
|
|
224
|
+
},
|
|
225
|
+
"ResumeButton": {
|
|
226
|
+
"resumeChat": "\u6062\u590d\u5bf9\u8bdd"
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
}
|
praisonai/ui/context.py
ADDED
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import fnmatch
|
|
3
|
+
import yaml
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
import logging
|
|
6
|
+
|
|
7
|
+
# Set up logging
|
|
8
|
+
logger = logging.getLogger(__name__)
|
|
9
|
+
log_level = os.getenv("LOGLEVEL", "INFO").upper()
|
|
10
|
+
logger.handlers = []
|
|
11
|
+
|
|
12
|
+
# Set up logging to console
|
|
13
|
+
console_handler = logging.StreamHandler()
|
|
14
|
+
console_handler.setLevel(log_level)
|
|
15
|
+
console_formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
|
|
16
|
+
console_handler.setFormatter(console_formatter)
|
|
17
|
+
logger.addHandler(console_handler)
|
|
18
|
+
|
|
19
|
+
# Set the logging level for the logger
|
|
20
|
+
logger.setLevel(log_level)
|
|
21
|
+
|
|
22
|
+
class ContextGatherer:
|
|
23
|
+
def __init__(self, directory='.', output_file='context.txt',
|
|
24
|
+
relevant_extensions=None, max_file_size=1_000_000, max_tokens=900000):
|
|
25
|
+
self.directory = directory
|
|
26
|
+
self.output_file = output_file
|
|
27
|
+
self.relevant_extensions = relevant_extensions or [
|
|
28
|
+
'.py', '.js', '.ts', '.java', '.rb', '.php', '.pl', '.pm', '.c', '.h',
|
|
29
|
+
'.cpp', '.hpp', '.cs', '.vb', '.swift', '.kt', '.m', '.mm', '.go', '.rs',
|
|
30
|
+
'.hs', '.r', '.lua', '.sh', '.bat', '.clj', '.scala', '.erl', '.ex',
|
|
31
|
+
'.ml', '.fs', '.groovy', '.jsm', '.jsx', '.tsx', '.yaml'
|
|
32
|
+
]
|
|
33
|
+
self.max_file_size = max_file_size
|
|
34
|
+
self.max_tokens = int(os.getenv("PRAISONAI_MAX_TOKENS", max_tokens))
|
|
35
|
+
self.ignore_patterns = self.get_ignore_patterns()
|
|
36
|
+
self.include_paths = self.get_include_paths()
|
|
37
|
+
self.included_files = []
|
|
38
|
+
|
|
39
|
+
def get_ignore_patterns(self):
|
|
40
|
+
"""
|
|
41
|
+
Loads ignore patterns from various sources, prioritizing them in
|
|
42
|
+
the following order:
|
|
43
|
+
1. .praisonignore
|
|
44
|
+
2. settings.yaml (under code.ignore_files)
|
|
45
|
+
3. PRAISONAI_IGNORE_FILES environment variable
|
|
46
|
+
4. .gitignore
|
|
47
|
+
5. Default patterns
|
|
48
|
+
"""
|
|
49
|
+
ignore_patterns = []
|
|
50
|
+
|
|
51
|
+
def load_from_file(filepath):
|
|
52
|
+
if os.path.exists(filepath):
|
|
53
|
+
with open(filepath, 'r') as f:
|
|
54
|
+
ignore_patterns.extend(
|
|
55
|
+
line.strip() for line in f
|
|
56
|
+
if line.strip() and not line.startswith('#')
|
|
57
|
+
)
|
|
58
|
+
|
|
59
|
+
# 1. Load from .praisonignore
|
|
60
|
+
load_from_file(os.path.join(self.directory, '.praisonignore'))
|
|
61
|
+
|
|
62
|
+
# 2. Load from settings.yaml
|
|
63
|
+
settings_path = os.path.join(self.directory, 'settings.yaml')
|
|
64
|
+
if os.path.exists(settings_path):
|
|
65
|
+
with open(settings_path, 'r') as f:
|
|
66
|
+
settings = yaml.safe_load(f)
|
|
67
|
+
if 'code' in settings and 'ignore_files' in settings['code']:
|
|
68
|
+
ignore_patterns.extend(settings['code']['ignore_files'])
|
|
69
|
+
|
|
70
|
+
# 3. Load from environment variable
|
|
71
|
+
ignore_files_env = os.getenv("PRAISONAI_IGNORE_FILES")
|
|
72
|
+
if ignore_files_env:
|
|
73
|
+
ignore_patterns.extend(ignore_files_env.split(","))
|
|
74
|
+
|
|
75
|
+
# 4. Load from .gitignore
|
|
76
|
+
load_from_file(os.path.join(self.directory, '.gitignore'))
|
|
77
|
+
|
|
78
|
+
# 5. Default patterns (only if no patterns loaded from above sources)
|
|
79
|
+
if not ignore_patterns:
|
|
80
|
+
ignore_patterns = [
|
|
81
|
+
".*", "*.pyc", "__pycache__", ".git", ".gitignore", ".vscode",
|
|
82
|
+
".idea", ".DS_Store", "*.lock", "*.pyc", ".env", "docs", "tests",
|
|
83
|
+
"test", "tmp", "temp", "*.txt", "*.md", "*.json", "*.csv", "*.tsv",
|
|
84
|
+
"public", "*.sql", "*.sqlite", "*.db", "*.db3", "*.sqlite3",
|
|
85
|
+
"*.log", "*.zip", "*.gz", "*.tar", "*.rar", "*.7z", "*.pdf",
|
|
86
|
+
"*.jpg", "*.jpeg", "*.png", "*.gif", "*.svg", "cookbooks",
|
|
87
|
+
"assets", "__pycache__", "dist", "build", "node_modules", "venv"
|
|
88
|
+
]
|
|
89
|
+
logger.debug(f"Using default ignore patterns: {ignore_patterns}")
|
|
90
|
+
|
|
91
|
+
# Modify patterns to match directories and add leading '*' if necessary
|
|
92
|
+
modified_ignore_patterns = [
|
|
93
|
+
'*' + pattern if not pattern.startswith('.') and not pattern.startswith('*') else pattern
|
|
94
|
+
for pattern in ignore_patterns
|
|
95
|
+
]
|
|
96
|
+
logger.debug(f"Final ignore patterns: {modified_ignore_patterns}")
|
|
97
|
+
return modified_ignore_patterns
|
|
98
|
+
|
|
99
|
+
def get_include_paths(self):
|
|
100
|
+
"""
|
|
101
|
+
Loads include paths from:
|
|
102
|
+
1. .praisoninclude (includes ONLY files/directories listed)
|
|
103
|
+
2. .praisoncontext (if .praisoninclude doesn't exist, this is used
|
|
104
|
+
to include all other relevant files, excluding ignore patterns)
|
|
105
|
+
"""
|
|
106
|
+
include_paths = []
|
|
107
|
+
include_all = False # Flag to indicate if we need to include all files
|
|
108
|
+
|
|
109
|
+
include_file = os.path.join(self.directory, '.praisoncontext')
|
|
110
|
+
if os.path.exists(include_file):
|
|
111
|
+
with open(include_file, 'r') as f:
|
|
112
|
+
include_paths.extend(
|
|
113
|
+
line.strip() for line in f
|
|
114
|
+
if line.strip() and not line.startswith('#')
|
|
115
|
+
)
|
|
116
|
+
|
|
117
|
+
# If .praisoncontext doesn't exist, fall back to .praisoninclude
|
|
118
|
+
# for including all relevant files
|
|
119
|
+
if not include_paths:
|
|
120
|
+
include_file = os.path.join(self.directory, '.praisoninclude')
|
|
121
|
+
if os.path.exists(include_file):
|
|
122
|
+
with open(include_file, 'r') as f:
|
|
123
|
+
include_paths.extend(
|
|
124
|
+
line.strip() for line in f
|
|
125
|
+
if line.strip() and not line.startswith('#')
|
|
126
|
+
)
|
|
127
|
+
include_all = True # Include all files along with specified paths
|
|
128
|
+
|
|
129
|
+
return include_paths, include_all
|
|
130
|
+
|
|
131
|
+
def should_ignore(self, file_path):
|
|
132
|
+
"""
|
|
133
|
+
Check if a file or directory should be ignored based on patterns.
|
|
134
|
+
Handles both file names and directory names for more comprehensive filtering.
|
|
135
|
+
"""
|
|
136
|
+
relative_path = os.path.relpath(file_path, self.directory)
|
|
137
|
+
if relative_path.startswith('.'):
|
|
138
|
+
return True
|
|
139
|
+
for pattern in self.ignore_patterns:
|
|
140
|
+
if fnmatch.fnmatch(relative_path, pattern) or \
|
|
141
|
+
fnmatch.fnmatch(os.path.basename(file_path), pattern):
|
|
142
|
+
return True
|
|
143
|
+
return False
|
|
144
|
+
|
|
145
|
+
def is_relevant_file(self, file_path):
|
|
146
|
+
"""Determine if a file is relevant for the context."""
|
|
147
|
+
return os.path.isfile(file_path) and \
|
|
148
|
+
os.path.getsize(file_path) <= self.max_file_size and \
|
|
149
|
+
any(file_path.endswith(ext) for ext in self.relevant_extensions)
|
|
150
|
+
|
|
151
|
+
def gather_context(self):
|
|
152
|
+
"""
|
|
153
|
+
Gather context from relevant files, respecting ignore patterns
|
|
154
|
+
and include options from .praisoninclude and .praisoncontext.
|
|
155
|
+
"""
|
|
156
|
+
context = []
|
|
157
|
+
total_files = 0
|
|
158
|
+
processed_files = 0
|
|
159
|
+
self.include_paths, include_all = self.get_include_paths()
|
|
160
|
+
|
|
161
|
+
def add_file_content(file_path):
|
|
162
|
+
"""Helper function to add file content to context."""
|
|
163
|
+
try:
|
|
164
|
+
with open(file_path, 'r', encoding='utf-8') as f:
|
|
165
|
+
content = f.read()
|
|
166
|
+
context.append(
|
|
167
|
+
f"File: {file_path}\n\n{content}\n\n{'=' * 50}\n"
|
|
168
|
+
)
|
|
169
|
+
self.included_files.append(
|
|
170
|
+
Path(file_path).relative_to(self.directory)
|
|
171
|
+
)
|
|
172
|
+
except Exception as e:
|
|
173
|
+
logger.error(f"Error reading {file_path}: {e}")
|
|
174
|
+
|
|
175
|
+
def process_path(path):
|
|
176
|
+
"""Helper function to process a single path (file or directory)."""
|
|
177
|
+
nonlocal total_files, processed_files
|
|
178
|
+
if os.path.isdir(path):
|
|
179
|
+
for root, dirs, files in os.walk(path):
|
|
180
|
+
total_files += len(files)
|
|
181
|
+
dirs[:] = [
|
|
182
|
+
d
|
|
183
|
+
for d in dirs
|
|
184
|
+
if not self.should_ignore(os.path.join(root, d))
|
|
185
|
+
]
|
|
186
|
+
for file in files:
|
|
187
|
+
file_path = os.path.join(root, file)
|
|
188
|
+
if not self.should_ignore(file_path) and self.is_relevant_file(file_path):
|
|
189
|
+
add_file_content(file_path)
|
|
190
|
+
processed_files += 1
|
|
191
|
+
print(
|
|
192
|
+
f"\rProcessed {processed_files}/{total_files} files",
|
|
193
|
+
end="",
|
|
194
|
+
flush=True,
|
|
195
|
+
)
|
|
196
|
+
elif os.path.isfile(path) and self.is_relevant_file(path):
|
|
197
|
+
add_file_content(path)
|
|
198
|
+
processed_files += 1
|
|
199
|
+
print(
|
|
200
|
+
f"\rProcessed {processed_files}/1 files",
|
|
201
|
+
end="",
|
|
202
|
+
flush=True,
|
|
203
|
+
)
|
|
204
|
+
|
|
205
|
+
if include_all:
|
|
206
|
+
# Include ALL relevant files from the entire directory
|
|
207
|
+
process_path(self.directory)
|
|
208
|
+
|
|
209
|
+
# Include files from .praisoninclude specifically
|
|
210
|
+
for include_path in self.include_paths:
|
|
211
|
+
full_path = os.path.join(self.directory, include_path)
|
|
212
|
+
process_path(full_path)
|
|
213
|
+
elif self.include_paths:
|
|
214
|
+
# Include only files specified in .praisoncontext
|
|
215
|
+
for include_path in self.include_paths:
|
|
216
|
+
full_path = os.path.join(self.directory, include_path)
|
|
217
|
+
process_path(full_path)
|
|
218
|
+
else:
|
|
219
|
+
# No include options, process the entire directory
|
|
220
|
+
process_path(self.directory)
|
|
221
|
+
|
|
222
|
+
print() # New line after progress indicator
|
|
223
|
+
return "\n".join(context)
|
|
224
|
+
|
|
225
|
+
def count_tokens(self, text):
|
|
226
|
+
"""Count tokens using a simple whitespace-based tokenizer."""
|
|
227
|
+
return len(text.split())
|
|
228
|
+
|
|
229
|
+
def truncate_context(self, context):
|
|
230
|
+
"""Truncate context to stay within the token limit."""
|
|
231
|
+
tokens = context.split()
|
|
232
|
+
if len(tokens) > self.max_tokens:
|
|
233
|
+
truncated_context = ' '.join(tokens[:self.max_tokens])
|
|
234
|
+
logger.warning("Context truncated due to token limit.")
|
|
235
|
+
return truncated_context
|
|
236
|
+
return context
|
|
237
|
+
|
|
238
|
+
def save_context(self, context):
|
|
239
|
+
"""Save the gathered context to a file."""
|
|
240
|
+
with open(self.output_file, 'w', encoding='utf-8') as f:
|
|
241
|
+
f.write(context)
|
|
242
|
+
|
|
243
|
+
def get_context_tree(self):
|
|
244
|
+
"""Generate a formatted tree structure of included files and folders."""
|
|
245
|
+
tree = []
|
|
246
|
+
start_dir = Path(self.directory)
|
|
247
|
+
|
|
248
|
+
def add_to_tree(path, prefix=''):
|
|
249
|
+
contents = sorted(path.iterdir())
|
|
250
|
+
pointers = [('└── ' if i == len(contents) - 1 else '├── ') for i in range(len(contents))]
|
|
251
|
+
for pointer, item in zip(pointers, contents):
|
|
252
|
+
rel_path = item.relative_to(start_dir)
|
|
253
|
+
if rel_path in self.included_files:
|
|
254
|
+
tree.append(f"{prefix}{pointer}{rel_path}")
|
|
255
|
+
|
|
256
|
+
if item.is_dir():
|
|
257
|
+
add_to_tree(item, prefix + (' ' if pointer == '└── ' else '│ '))
|
|
258
|
+
|
|
259
|
+
add_to_tree(start_dir)
|
|
260
|
+
return '\n'.join(tree)
|
|
261
|
+
|
|
262
|
+
def run(self):
|
|
263
|
+
"""Execute the context gathering, truncation, and reporting."""
|
|
264
|
+
context = self.gather_context()
|
|
265
|
+
context = self.truncate_context(context)
|
|
266
|
+
token_count = self.count_tokens(context)
|
|
267
|
+
print(f"Context gathered successfully.")
|
|
268
|
+
print(f"Total number of tokens (estimated): {token_count}")
|
|
269
|
+
# self.save_context(context)
|
|
270
|
+
context_tree = self.get_context_tree()
|
|
271
|
+
logger.debug(f"Context tree:\n{context_tree}")
|
|
272
|
+
return context, token_count, context_tree
|
|
273
|
+
|
|
274
|
+
def main():
|
|
275
|
+
gatherer = ContextGatherer()
|
|
276
|
+
context, token_count, context_tree = gatherer.run()
|
|
277
|
+
print(context_tree)
|
|
278
|
+
print(f"\nThe context contains approximately {token_count} tokens.")
|
|
279
|
+
print("First 500 characters of context:")
|
|
280
|
+
print(context[:500] + "...")
|
|
281
|
+
|
|
282
|
+
if __name__ == "__main__":
|
|
283
|
+
main()
|