llm-dialog-manager 0.2.14__py3-none-any.whl → 0.3.2__py3-none-any.whl

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,4 +1,4 @@
1
1
  from .chat_history import ChatHistory
2
2
  from .agent import Agent
3
3
 
4
- __version__ = "0.2.14"
4
+ __version__ = "0.3.2"
@@ -6,6 +6,9 @@ from typing import List, Dict, Optional
6
6
  import logging
7
7
  from pathlib import Path
8
8
  import random
9
+ import requests
10
+ import zipfile
11
+ import io
9
12
 
10
13
  # Third-party imports
11
14
  import anthropic
@@ -234,8 +237,15 @@ class Agent:
234
237
  self.history = ChatHistory(messages)
235
238
  self.memory_enabled = memory_enabled
236
239
  self.api_key = api_key
240
+ self.repo_content = []
237
241
 
238
242
  def add_message(self, role, content):
243
+ repo_content = ""
244
+ while self.repo_content:
245
+ repo = self.repo_content.pop()
246
+ repo_content += f"<repo>\n{repo}\n</repo>\n"
247
+
248
+ content = repo_content + content
239
249
  self.history.add_message(content, role)
240
250
 
241
251
  def generate_response(self, max_tokens=3585, temperature=0.7):
@@ -264,12 +274,37 @@ class Agent:
264
274
  with open(filename, 'w', encoding='utf-8') as file:
265
275
  json.dump(self.history.messages, file, ensure_ascii=False, indent=4)
266
276
 
267
- def load_conversation(self):
268
- filename = f"{self.id}.json"
277
+ def load_conversation(self, filename=None):
278
+ if filename is None:
279
+ filename = f"{self.id}.json"
269
280
  with open(filename, 'r', encoding='utf-8') as file:
270
281
  messages = json.load(file)
271
282
  self.history = ChatHistory(messages)
272
283
 
284
+ def load_repo(self, repo_name: Optional[str] = None, commit_hash: Optional[str] = None):
285
+ """eg: repo_name: xihajun/llm_dialog_manager"""
286
+ if repo_name:
287
+ if commit_hash:
288
+ repo_url = f"https://github.com/{repo_name}/archive/{commit_hash}.zip"
289
+ else:
290
+ repo_url = f"https://github.com/{repo_name}/archive/refs/heads/main.zip"
291
+
292
+ if not repo_url:
293
+ raise ValueError("Either repo_url or both username and repo_name must be provided")
294
+
295
+ response = requests.get(repo_url)
296
+ if response.status_code == 200:
297
+ repo_content = ""
298
+ with zipfile.ZipFile(io.BytesIO(response.content)) as z:
299
+ for file_info in z.infolist():
300
+ if not file_info.is_dir() and file_info.filename.endswith(('.py', '.txt')):
301
+ with z.open(file_info) as f:
302
+ content = f.read().decode('utf-8')
303
+ repo_content += f"{file_info.filename}\n```\n{content}\n```\n"
304
+ self.repo_content.append(repo_content)
305
+ else:
306
+ raise ValueError(f"Failed to download repository from {repo_url}")
307
+
273
308
  if __name__ == "__main__":
274
309
 
275
310
  # write a test for detect finding agent
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: llm_dialog_manager
3
- Version: 0.2.14
3
+ Version: 0.3.2
4
4
  Summary: A Python package for managing LLM chat conversation history
5
5
  Author-email: xihajun <work@2333.fun>
6
6
  License: MIT
@@ -0,0 +1,9 @@
1
+ llm_dialog_manager/__init__.py,sha256=u9m9_3UUibXqNSRzkf63lAbkw_l5RmGcxlVOhmeShlg,86
2
+ llm_dialog_manager/agent.py,sha256=o0ayPp9eS_8Vx78GYMPlIxHrK1UHTbu_I3dEsk4Agdo,13268
3
+ llm_dialog_manager/chat_history.py,sha256=xKA-oQCv8jv_g8EhXrG9h1S8Icbj2FfqPIhbty5vra4,6033
4
+ llm_dialog_manager/key_manager.py,sha256=shvxmn4zUtQx_p-x1EFyOmnk-WlhigbpKtxTKve-zXk,4421
5
+ llm_dialog_manager-0.3.2.dist-info/LICENSE,sha256=vWGbYgGuWpWrXL8-xi6pNcX5UzD6pWoIAZmcetyfbus,1064
6
+ llm_dialog_manager-0.3.2.dist-info/METADATA,sha256=-DNhRHechHF38K6DGrHCeHVTj2JX3sxw4ZYFQr6Sj5I,4152
7
+ llm_dialog_manager-0.3.2.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
8
+ llm_dialog_manager-0.3.2.dist-info/top_level.txt,sha256=u2EQEXW0NGAt0AAHT7jx1odXZ4rZfjcgbmJhvKFuMkI,19
9
+ llm_dialog_manager-0.3.2.dist-info/RECORD,,
@@ -1,9 +0,0 @@
1
- llm_dialog_manager/__init__.py,sha256=5dGJgpXgC90NkUYbGpzObrhFeVnAiJRI790kDGZ4eok,87
2
- llm_dialog_manager/agent.py,sha256=aST_n9jU1tuHjMUK0ytCmWq3wYkZp9VHLcg4Q4Y7Tcw,11731
3
- llm_dialog_manager/chat_history.py,sha256=xKA-oQCv8jv_g8EhXrG9h1S8Icbj2FfqPIhbty5vra4,6033
4
- llm_dialog_manager/key_manager.py,sha256=shvxmn4zUtQx_p-x1EFyOmnk-WlhigbpKtxTKve-zXk,4421
5
- llm_dialog_manager-0.2.14.dist-info/LICENSE,sha256=vWGbYgGuWpWrXL8-xi6pNcX5UzD6pWoIAZmcetyfbus,1064
6
- llm_dialog_manager-0.2.14.dist-info/METADATA,sha256=o-NVoztedCK3QHUCbggAubl6BV6eUnpslFL-pmVp19I,4153
7
- llm_dialog_manager-0.2.14.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
8
- llm_dialog_manager-0.2.14.dist-info/top_level.txt,sha256=u2EQEXW0NGAt0AAHT7jx1odXZ4rZfjcgbmJhvKFuMkI,19
9
- llm_dialog_manager-0.2.14.dist-info/RECORD,,