llm-dialog-manager 0.3.1__tar.gz → 0.3.4__tar.gz

Sign up to get free protection for your applications and to get access to all the features.
Files changed (18) hide show
  1. {llm_dialog_manager-0.3.1 → llm_dialog_manager-0.3.4}/PKG-INFO +1 -1
  2. {llm_dialog_manager-0.3.1 → llm_dialog_manager-0.3.4}/llm_dialog_manager/__init__.py +1 -1
  3. {llm_dialog_manager-0.3.1 → llm_dialog_manager-0.3.4}/llm_dialog_manager/agent.py +33 -0
  4. {llm_dialog_manager-0.3.1 → llm_dialog_manager-0.3.4}/llm_dialog_manager.egg-info/PKG-INFO +1 -1
  5. {llm_dialog_manager-0.3.1 → llm_dialog_manager-0.3.4}/pyproject.toml +1 -1
  6. llm_dialog_manager-0.3.4/tests/test_agent.py +60 -0
  7. llm_dialog_manager-0.3.1/tests/test_agent.py +0 -35
  8. {llm_dialog_manager-0.3.1 → llm_dialog_manager-0.3.4}/LICENSE +0 -0
  9. {llm_dialog_manager-0.3.1 → llm_dialog_manager-0.3.4}/README.md +0 -0
  10. {llm_dialog_manager-0.3.1 → llm_dialog_manager-0.3.4}/llm_dialog_manager/chat_history.py +0 -0
  11. {llm_dialog_manager-0.3.1 → llm_dialog_manager-0.3.4}/llm_dialog_manager/key_manager.py +0 -0
  12. {llm_dialog_manager-0.3.1 → llm_dialog_manager-0.3.4}/llm_dialog_manager.egg-info/SOURCES.txt +0 -0
  13. {llm_dialog_manager-0.3.1 → llm_dialog_manager-0.3.4}/llm_dialog_manager.egg-info/dependency_links.txt +0 -0
  14. {llm_dialog_manager-0.3.1 → llm_dialog_manager-0.3.4}/llm_dialog_manager.egg-info/requires.txt +0 -0
  15. {llm_dialog_manager-0.3.1 → llm_dialog_manager-0.3.4}/llm_dialog_manager.egg-info/top_level.txt +0 -0
  16. {llm_dialog_manager-0.3.1 → llm_dialog_manager-0.3.4}/setup.cfg +0 -0
  17. {llm_dialog_manager-0.3.1 → llm_dialog_manager-0.3.4}/tests/test_chat_history.py +0 -0
  18. {llm_dialog_manager-0.3.1 → llm_dialog_manager-0.3.4}/tests/test_key_manager.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: llm_dialog_manager
3
- Version: 0.3.1
3
+ Version: 0.3.4
4
4
  Summary: A Python package for managing LLM chat conversation history
5
5
  Author-email: xihajun <work@2333.fun>
6
6
  License: MIT
@@ -1,4 +1,4 @@
1
1
  from .chat_history import ChatHistory
2
2
  from .agent import Agent
3
3
 
4
- __version__ = "0.3.1"
4
+ __version__ = "0.3.4"
@@ -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):
@@ -271,6 +281,29 @@ class Agent:
271
281
  messages = json.load(file)
272
282
  self.history = ChatHistory(messages)
273
283
 
284
+ def add_repo(self, repo_url: Optional[str] = None, username: Optional[str] = None, repo_name: Optional[str] = None, commit_hash: Optional[str] = None):
285
+ if username and repo_name:
286
+ if commit_hash:
287
+ repo_url = f"https://github.com/{username}/{repo_name}/archive/{commit_hash}.zip"
288
+ else:
289
+ repo_url = f"https://github.com/{username}/{repo_name}/archive/refs/heads/main.zip"
290
+
291
+ if not repo_url:
292
+ raise ValueError("Either repo_url or both username and repo_name must be provided")
293
+
294
+ response = requests.get(repo_url)
295
+ if response.status_code == 200:
296
+ repo_content = ""
297
+ with zipfile.ZipFile(io.BytesIO(response.content)) as z:
298
+ for file_info in z.infolist():
299
+ if not file_info.is_dir() and file_info.filename.endswith(('.py', '.txt')):
300
+ with z.open(file_info) as f:
301
+ content = f.read().decode('utf-8')
302
+ repo_content += f"{file_info.filename}\n```\n{content}\n```\n"
303
+ self.repo_content.append(repo_content)
304
+ else:
305
+ raise ValueError(f"Failed to download repository from {repo_url}")
306
+
274
307
  if __name__ == "__main__":
275
308
 
276
309
  # 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.3.1
3
+ Version: 0.3.4
4
4
  Summary: A Python package for managing LLM chat conversation history
5
5
  Author-email: xihajun <work@2333.fun>
6
6
  License: MIT
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "llm_dialog_manager"
7
- version = "0.3.1"
7
+ version = "0.3.4"
8
8
  description = "A Python package for managing LLM chat conversation history"
9
9
  readme = "README.md"
10
10
  authors = [{ name = "xihajun", email = "work@2333.fun" }]
@@ -0,0 +1,60 @@
1
+ import pytest
2
+ from llm_dialog_manager.agent import Agent
3
+
4
+ def test_agent_initialization(env_setup):
5
+ # Test valid model initialization
6
+ agent = Agent("claude-2.1")
7
+ assert agent.model_name == "claude-2.1"
8
+
9
+ # Test invalid model
10
+ with pytest.raises(ValueError):
11
+ Agent("invalid-model")
12
+
13
+ # Test add_repo method
14
+ agent.add_repo("https://github.com/some/repo/archive/refs/heads/main.zip")
15
+ assert "some content from the repo" in agent.history.messages[-1]["content"]
16
+
17
+ # Test add_repo method with username and repo name
18
+ agent.add_repo(repo_url="", username="someuser", repo_name="somerepo")
19
+ assert "some content from the repo" in agent.history.messages[-1]["content"]
20
+
21
+ def test_agent_message_handling(env_setup):
22
+ agent = Agent("claude-2.1", memory_enabled=True)
23
+
24
+ # Test adding messages
25
+ agent.add_message("system", "You are a helpful assistant")
26
+ agent.add_message("user", "Hello!")
27
+
28
+ assert len(agent.history) == 2
29
+ assert agent.history.messages[-1]["role"] == "user"
30
+
31
+ # Test add_repo method
32
+ agent.add_repo("https://github.com/some/repo/archive/refs/heads/main.zip")
33
+ assert "some content from the repo" in agent.history.messages[-1]["content"]
34
+
35
+ # Test add_repo method with username and repo name
36
+ agent.add_repo(repo_url="", username="someuser", repo_name="somerepo")
37
+ assert "some content from the repo" in agent.history.messages[-1]["content"]
38
+
39
+ def test_conversation_save_load(env_setup, tmp_path):
40
+ agent = Agent("claude-2.1")
41
+ agent.add_message("system", "Test message")
42
+
43
+ # Save conversation
44
+ agent.save_conversation()
45
+
46
+ # Create new agent and load conversation
47
+ new_agent = Agent("claude-2.1")
48
+ new_agent.load_conversation()
49
+
50
+ assert len(new_agent.history) == 1
51
+ assert new_agent.history.messages[0]["content"] == "Test message"
52
+
53
+ def test_add_repo_with_github_repo(env_setup):
54
+ agent = Agent("claude-2.1", memory_enabled=True)
55
+
56
+ # Test add_repo method with a real GitHub repository
57
+ agent.add_repo(repo_url="https://github.com/xihajun/llm_dialog_manager/archive/refs/heads/main.zip")
58
+
59
+ # Check if .env.example file content is in the repo_content
60
+ assert any(".env.example" in content for content in agent.repo_content)
@@ -1,35 +0,0 @@
1
- import pytest
2
- from llm_dialog_manager.agent import Agent
3
-
4
- def test_agent_initialization(env_setup):
5
- # Test valid model initialization
6
- agent = Agent("claude-2.1")
7
- assert agent.model_name == "claude-2.1"
8
-
9
- # Test invalid model
10
- with pytest.raises(ValueError):
11
- Agent("invalid-model")
12
-
13
- def test_agent_message_handling(env_setup):
14
- agent = Agent("claude-2.1", memory_enabled=True)
15
-
16
- # Test adding messages
17
- agent.add_message("system", "You are a helpful assistant")
18
- agent.add_message("user", "Hello!")
19
-
20
- assert len(agent.history) == 2
21
- assert agent.history.messages[-1]["role"] == "user"
22
-
23
- def test_conversation_save_load(env_setup, tmp_path):
24
- agent = Agent("claude-2.1")
25
- agent.add_message("system", "Test message")
26
-
27
- # Save conversation
28
- agent.save_conversation()
29
-
30
- # Create new agent and load conversation
31
- new_agent = Agent("claude-2.1")
32
- new_agent.load_conversation()
33
-
34
- assert len(new_agent.history) == 1
35
- assert new_agent.history.messages[0]["content"] == "Test message"