llm-dialog-manager 0.3.5__tar.gz → 0.4.1__tar.gz
Sign up to get free protection for your applications and to get access to all the features.
- {llm_dialog_manager-0.3.5 → llm_dialog_manager-0.4.1}/PKG-INFO +2 -1
- {llm_dialog_manager-0.3.5 → llm_dialog_manager-0.4.1}/README.md +1 -0
- {llm_dialog_manager-0.3.5 → llm_dialog_manager-0.4.1}/llm_dialog_manager/__init__.py +1 -1
- {llm_dialog_manager-0.3.5 → llm_dialog_manager-0.4.1}/llm_dialog_manager/agent.py +57 -26
- {llm_dialog_manager-0.3.5 → llm_dialog_manager-0.4.1}/llm_dialog_manager.egg-info/PKG-INFO +2 -1
- llm_dialog_manager-0.4.1/pyproject.toml +32 -0
- llm_dialog_manager-0.3.5/pyproject.toml +0 -64
- {llm_dialog_manager-0.3.5 → llm_dialog_manager-0.4.1}/LICENSE +0 -0
- {llm_dialog_manager-0.3.5 → llm_dialog_manager-0.4.1}/llm_dialog_manager/chat_history.py +0 -0
- {llm_dialog_manager-0.3.5 → llm_dialog_manager-0.4.1}/llm_dialog_manager/key_manager.py +0 -0
- {llm_dialog_manager-0.3.5 → llm_dialog_manager-0.4.1}/llm_dialog_manager.egg-info/SOURCES.txt +0 -0
- {llm_dialog_manager-0.3.5 → llm_dialog_manager-0.4.1}/llm_dialog_manager.egg-info/dependency_links.txt +0 -0
- {llm_dialog_manager-0.3.5 → llm_dialog_manager-0.4.1}/llm_dialog_manager.egg-info/requires.txt +0 -0
- {llm_dialog_manager-0.3.5 → llm_dialog_manager-0.4.1}/llm_dialog_manager.egg-info/top_level.txt +0 -0
- {llm_dialog_manager-0.3.5 → llm_dialog_manager-0.4.1}/setup.cfg +0 -0
- {llm_dialog_manager-0.3.5 → llm_dialog_manager-0.4.1}/tests/test_agent.py +0 -0
- {llm_dialog_manager-0.3.5 → llm_dialog_manager-0.4.1}/tests/test_chat_history.py +0 -0
- {llm_dialog_manager-0.3.5 → llm_dialog_manager-0.4.1}/tests/test_key_manager.py +0 -0
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.2
|
2
2
|
Name: llm_dialog_manager
|
3
|
-
Version: 0.
|
3
|
+
Version: 0.4.1
|
4
4
|
Summary: A Python package for managing LLM chat conversation history
|
5
5
|
Author-email: xihajun <work@2333.fun>
|
6
6
|
License: MIT
|
@@ -64,6 +64,7 @@ A Python package for managing AI chat conversation history with support for mult
|
|
64
64
|
- Memory management options
|
65
65
|
- Conversation search and indexing
|
66
66
|
- Rich conversation display options
|
67
|
+
- Vision & Json Output enabled [20240111]
|
67
68
|
|
68
69
|
## Installation
|
69
70
|
|
@@ -38,8 +38,36 @@ def load_env_vars():
|
|
38
38
|
|
39
39
|
load_env_vars()
|
40
40
|
|
41
|
+
def format_messages_for_gemini(messages):
|
42
|
+
"""
|
43
|
+
将标准化的消息格式转化为 Gemini 格式。
|
44
|
+
system 消息应该通过 GenerativeModel 的 system_instruction 参数传入,
|
45
|
+
不在这个函数处理。
|
46
|
+
"""
|
47
|
+
gemini_messages = []
|
48
|
+
|
49
|
+
for msg in messages:
|
50
|
+
role = msg["role"]
|
51
|
+
content = msg["content"]
|
52
|
+
|
53
|
+
# 跳过 system 消息,因为它会通过 system_instruction 设置
|
54
|
+
if role == "system":
|
55
|
+
continue
|
56
|
+
|
57
|
+
# 处理 user/assistant 消息
|
58
|
+
# 如果 content 是单一对象,转换为列表
|
59
|
+
if not isinstance(content, list):
|
60
|
+
content = [content]
|
61
|
+
|
62
|
+
gemini_messages.append({
|
63
|
+
"role": role,
|
64
|
+
"parts": content # content 可以包含文本和 FileMedia
|
65
|
+
})
|
66
|
+
|
67
|
+
return gemini_messages
|
68
|
+
|
41
69
|
def completion(model: str, messages: List[Dict[str, Union[str, List[Union[str, Image.Image, Dict]]]]], max_tokens: int = 1000,
|
42
|
-
temperature: float = 0.5, api_key: Optional[str] = None,
|
70
|
+
temperature: float = 0.5, top_p: float = 1.0, top_k: int = 40, api_key: Optional[str] = None,
|
43
71
|
base_url: Optional[str] = None, json_format: bool = False) -> str:
|
44
72
|
"""
|
45
73
|
Generate a completion using the specified model and messages.
|
@@ -216,6 +244,9 @@ def completion(model: str, messages: List[Dict[str, Union[str, List[Union[str, I
|
|
216
244
|
|
217
245
|
response = client.chat.completions.create(
|
218
246
|
model=model,
|
247
|
+
max_tokens=max_tokens,
|
248
|
+
top_p=top_p,
|
249
|
+
top_k=top_k,
|
219
250
|
messages=formatted_messages,
|
220
251
|
temperature=temperature,
|
221
252
|
response_format=response_format # Added response_format
|
@@ -226,33 +257,31 @@ def completion(model: str, messages: List[Dict[str, Union[str, List[Union[str, I
|
|
226
257
|
# If OpenAI-style API fails, fall back to Google's genai library
|
227
258
|
logger.info("Falling back to Google's genai library")
|
228
259
|
genai.configure(api_key=api_key)
|
229
|
-
|
230
|
-
# Convert messages to Gemini format
|
231
|
-
gemini_messages = []
|
260
|
+
system_instruction = ""
|
232
261
|
for msg in messages:
|
233
262
|
if msg["role"] == "system":
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
else:
|
240
|
-
gemini_messages.append({"role": msg["role"], "parts": msg["content"]})
|
241
|
-
|
242
|
-
# Set response_mime_type based on json_format
|
263
|
+
system_instruction = msg["content"]
|
264
|
+
break
|
265
|
+
|
266
|
+
# 将其他消息转换为 gemini 格式
|
267
|
+
gemini_messages = format_messages_for_gemini(messages)
|
243
268
|
mime_type = "application/json" if json_format else "text/plain"
|
269
|
+
generation_config = genai.types.GenerationConfig(
|
270
|
+
temperature=temperature,
|
271
|
+
top_p=top_p,
|
272
|
+
top_k=top_k,
|
273
|
+
max_output_tokens=max_tokens,
|
274
|
+
response_mime_type=mime_type
|
275
|
+
)
|
244
276
|
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
generation_config=genai.types.GenerationConfig(
|
250
|
-
temperature=temperature,
|
251
|
-
response_mime_type=mime_type, # Modified based on json_format
|
252
|
-
max_output_tokens=max_tokens
|
253
|
-
)
|
277
|
+
model_instance = genai.GenerativeModel(
|
278
|
+
model_name=model,
|
279
|
+
system_instruction=system_instruction, # system 消息通过这里传入
|
280
|
+
generation_config=generation_config
|
254
281
|
)
|
255
282
|
|
283
|
+
response = model_instance.generate_content(gemini_messages, generation_config=generation_config)
|
284
|
+
|
256
285
|
return response.text
|
257
286
|
|
258
287
|
elif "grok" in model:
|
@@ -395,7 +424,7 @@ class Agent:
|
|
395
424
|
# Start a new user message with the image
|
396
425
|
self.history.add_message([image_block], "user")
|
397
426
|
|
398
|
-
def generate_response(self, max_tokens=3585, temperature=0.7, json_format: bool = False) -> str:
|
427
|
+
def generate_response(self, max_tokens=3585, temperature=0.7, top_p=1.0, top_k=40, json_format: bool = False) -> str:
|
399
428
|
"""Generate a response from the agent.
|
400
429
|
|
401
430
|
Args:
|
@@ -410,12 +439,14 @@ class Agent:
|
|
410
439
|
raise ValueError("No messages in history to generate response from")
|
411
440
|
|
412
441
|
messages = self.history.messages
|
413
|
-
|
442
|
+
print(self.model_name)
|
414
443
|
response_text = completion(
|
415
444
|
model=self.model_name,
|
416
445
|
messages=messages,
|
417
446
|
max_tokens=max_tokens,
|
418
447
|
temperature=temperature,
|
448
|
+
top_p=top_p,
|
449
|
+
top_k=top_k,
|
419
450
|
api_key=self.api_key,
|
420
451
|
json_format=json_format # Pass json_format to completion
|
421
452
|
)
|
@@ -486,13 +517,13 @@ class Agent:
|
|
486
517
|
if __name__ == "__main__":
|
487
518
|
# Example Usage
|
488
519
|
# Create an Agent instance (Gemini model)
|
489
|
-
agent = Agent("gemini-1.5-flash", "you are
|
520
|
+
agent = Agent("gemini-1.5-flash", "you are Jack101", memory_enabled=True)
|
490
521
|
|
491
522
|
# Add an image
|
492
523
|
agent.add_image(image_path="/Users/junfan/Projects/Personal/oneapi/dialog_manager/example.png")
|
493
524
|
|
494
525
|
# Add a user message
|
495
|
-
agent.add_message("user", "What's in this image?")
|
526
|
+
agent.add_message("user", "Who are you? What's in this image?")
|
496
527
|
|
497
528
|
# Generate response with JSON format enabled
|
498
529
|
try:
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.2
|
2
2
|
Name: llm_dialog_manager
|
3
|
-
Version: 0.
|
3
|
+
Version: 0.4.1
|
4
4
|
Summary: A Python package for managing LLM chat conversation history
|
5
5
|
Author-email: xihajun <work@2333.fun>
|
6
6
|
License: MIT
|
@@ -64,6 +64,7 @@ A Python package for managing AI chat conversation history with support for mult
|
|
64
64
|
- Memory management options
|
65
65
|
- Conversation search and indexing
|
66
66
|
- Rich conversation display options
|
67
|
+
- Vision & Json Output enabled [20240111]
|
67
68
|
|
68
69
|
## Installation
|
69
70
|
|
@@ -0,0 +1,32 @@
|
|
1
|
+
[build-system]
|
2
|
+
requires = [ "setuptools>=61.0", "wheel",]
|
3
|
+
build-backend = "setuptools.build_meta"
|
4
|
+
|
5
|
+
[project]
|
6
|
+
name = "llm_dialog_manager"
|
7
|
+
version = "0.4.1"
|
8
|
+
description = "A Python package for managing LLM chat conversation history"
|
9
|
+
readme = "README.md"
|
10
|
+
classifiers = [ "Development Status :: 3 - Alpha", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Topic :: Software Development :: Libraries :: Python Modules", "Topic :: Scientific/Engineering :: Artificial Intelligence",]
|
11
|
+
requires-python = ">=3.7"
|
12
|
+
dependencies = [ "openai>=1.54.2", "anthropic>=0.39.0", "google-generativeai>=0.1.0", "python-dotenv>=1.0.0", "typing-extensions>=4.0.0", "uuid>=1.30",]
|
13
|
+
[[project.authors]]
|
14
|
+
name = "xihajun"
|
15
|
+
email = "work@2333.fun"
|
16
|
+
|
17
|
+
[project.license]
|
18
|
+
text = "MIT"
|
19
|
+
|
20
|
+
[project.optional-dependencies]
|
21
|
+
dev = [ "pytest>=8.0.0", "pytest-asyncio>=0.21.1", "pytest-cov>=4.1.0", "black>=23.9.1", "isort>=5.12.0",]
|
22
|
+
test = [ "pytest>=6.0", "pytest-asyncio>=0.14.0", "pytest-cov>=2.0",]
|
23
|
+
lint = [ "black>=22.0", "isort>=5.0",]
|
24
|
+
all = [ "pytest>=8.0.0", "pytest-asyncio>=0.21.1", "pytest-cov>=4.1.0", "black>=23.9.1", "isort>=5.12.0",]
|
25
|
+
|
26
|
+
[project.urls]
|
27
|
+
"Bug Tracker" = "https://github.com/xihajun/llm_dialog_manager/issues"
|
28
|
+
Documentation = "https://github.com/xihajun/llm_dialog_manager#readme"
|
29
|
+
"Source Code" = "https://github.com/xihajun/llm_dialog_manager"
|
30
|
+
|
31
|
+
[tool.setuptools]
|
32
|
+
packages = [ "llm_dialog_manager",]
|
@@ -1,64 +0,0 @@
|
|
1
|
-
[build-system]
|
2
|
-
requires = ["setuptools>=61.0", "wheel"]
|
3
|
-
build-backend = "setuptools.build_meta"
|
4
|
-
|
5
|
-
[project]
|
6
|
-
name = "llm_dialog_manager"
|
7
|
-
version = "0.3.5"
|
8
|
-
description = "A Python package for managing LLM chat conversation history"
|
9
|
-
readme = "README.md"
|
10
|
-
authors = [{ name = "xihajun", email = "work@2333.fun" }]
|
11
|
-
license = { text = "MIT" }
|
12
|
-
classifiers = [
|
13
|
-
"Development Status :: 3 - Alpha",
|
14
|
-
"Intended Audience :: Developers",
|
15
|
-
"License :: OSI Approved :: MIT License",
|
16
|
-
"Operating System :: OS Independent",
|
17
|
-
"Programming Language :: Python :: 3.8",
|
18
|
-
"Programming Language :: Python :: 3.9",
|
19
|
-
"Programming Language :: Python :: 3.10",
|
20
|
-
"Topic :: Software Development :: Libraries :: Python Modules",
|
21
|
-
"Topic :: Scientific/Engineering :: Artificial Intelligence",
|
22
|
-
]
|
23
|
-
requires-python = ">=3.7"
|
24
|
-
dependencies = [
|
25
|
-
"openai>=1.54.2",
|
26
|
-
"anthropic>=0.39.0",
|
27
|
-
"google-generativeai>=0.1.0",
|
28
|
-
"python-dotenv>=1.0.0",
|
29
|
-
"typing-extensions>=4.0.0",
|
30
|
-
"uuid>=1.30",
|
31
|
-
]
|
32
|
-
|
33
|
-
[project.optional-dependencies]
|
34
|
-
dev = [
|
35
|
-
"pytest>=8.0.0",
|
36
|
-
"pytest-asyncio>=0.21.1",
|
37
|
-
"pytest-cov>=4.1.0",
|
38
|
-
"black>=23.9.1",
|
39
|
-
"isort>=5.12.0",
|
40
|
-
]
|
41
|
-
test = [
|
42
|
-
"pytest>=6.0",
|
43
|
-
"pytest-asyncio>=0.14.0",
|
44
|
-
"pytest-cov>=2.0",
|
45
|
-
]
|
46
|
-
lint = [
|
47
|
-
"black>=22.0",
|
48
|
-
"isort>=5.0",
|
49
|
-
]
|
50
|
-
all = [
|
51
|
-
"pytest>=8.0.0",
|
52
|
-
"pytest-asyncio>=0.21.1",
|
53
|
-
"pytest-cov>=4.1.0",
|
54
|
-
"black>=23.9.1",
|
55
|
-
"isort>=5.12.0",
|
56
|
-
]
|
57
|
-
|
58
|
-
[project.urls]
|
59
|
-
"Bug Tracker" = "https://github.com/xihajun/llm_dialog_manager/issues"
|
60
|
-
"Documentation" = "https://github.com/xihajun/llm_dialog_manager#readme"
|
61
|
-
"Source Code" = "https://github.com/xihajun/llm_dialog_manager"
|
62
|
-
|
63
|
-
[tool.setuptools]
|
64
|
-
packages = ["llm_dialog_manager"]
|
File without changes
|
File without changes
|
File without changes
|
{llm_dialog_manager-0.3.5 → llm_dialog_manager-0.4.1}/llm_dialog_manager.egg-info/SOURCES.txt
RENAMED
File without changes
|
File without changes
|
{llm_dialog_manager-0.3.5 → llm_dialog_manager-0.4.1}/llm_dialog_manager.egg-info/requires.txt
RENAMED
File without changes
|
{llm_dialog_manager-0.3.5 → llm_dialog_manager-0.4.1}/llm_dialog_manager.egg-info/top_level.txt
RENAMED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|