commandchat 0.0.10__tar.gz → 0.0.12__tar.gz
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.
- {commandchat-0.0.10 → commandchat-0.0.12}/PKG-INFO +1 -1
- {commandchat-0.0.10 → commandchat-0.0.12}/commandchat.egg-info/PKG-INFO +1 -1
- {commandchat-0.0.10 → commandchat-0.0.12}/occ/CommandChat.py +10 -12
- {commandchat-0.0.10 → commandchat-0.0.12}/occ/command/__main__.py +0 -1
- {commandchat-0.0.10 → commandchat-0.0.12}/pyproject.toml +1 -1
- {commandchat-0.0.10 → commandchat-0.0.12}/LICENSE +0 -0
- {commandchat-0.0.10 → commandchat-0.0.12}/README.md +0 -0
- {commandchat-0.0.10 → commandchat-0.0.12}/commandchat.egg-info/SOURCES.txt +0 -0
- {commandchat-0.0.10 → commandchat-0.0.12}/commandchat.egg-info/dependency_links.txt +0 -0
- {commandchat-0.0.10 → commandchat-0.0.12}/commandchat.egg-info/entry_points.txt +0 -0
- {commandchat-0.0.10 → commandchat-0.0.12}/commandchat.egg-info/requires.txt +0 -0
- {commandchat-0.0.10 → commandchat-0.0.12}/commandchat.egg-info/top_level.txt +0 -0
- {commandchat-0.0.10 → commandchat-0.0.12}/occ/ConvertLogToMarkDown.py +0 -0
- {commandchat-0.0.10 → commandchat-0.0.12}/occ/__init__.py +0 -0
- {commandchat-0.0.10 → commandchat-0.0.12}/occ/command/__init__.py +0 -0
- {commandchat-0.0.10 → commandchat-0.0.12}/occ/commons/__init__.py +0 -0
- {commandchat-0.0.10 → commandchat-0.0.12}/occ/commons/config.py +0 -0
- {commandchat-0.0.10 → commandchat-0.0.12}/occ/configuration/__init__.py +0 -0
- {commandchat-0.0.10 → commandchat-0.0.12}/occ/configuration/profile_config.py +0 -0
- {commandchat-0.0.10 → commandchat-0.0.12}/occ/utils/CommonUtil.py +0 -0
- {commandchat-0.0.10 → commandchat-0.0.12}/occ/utils/__init__.py +0 -0
- {commandchat-0.0.10 → commandchat-0.0.12}/occ/utils/logger.py +0 -0
- {commandchat-0.0.10 → commandchat-0.0.12}/setup.cfg +0 -0
- {commandchat-0.0.10 → commandchat-0.0.12}/setup.py +0 -0
|
@@ -1,26 +1,23 @@
|
|
|
1
1
|
import asyncio
|
|
2
2
|
import json
|
|
3
|
+
import os
|
|
3
4
|
import sys
|
|
4
5
|
import time
|
|
5
6
|
from pathlib import Path
|
|
6
7
|
from typing import AsyncGenerator
|
|
7
8
|
|
|
8
|
-
import openai
|
|
9
|
-
from openai import OpenAI, Stream
|
|
10
9
|
from openai import AzureOpenAI
|
|
11
|
-
import
|
|
12
|
-
|
|
13
|
-
from openai.types.chat import ChatCompletionChunk
|
|
10
|
+
from openai import OpenAI
|
|
14
11
|
from openai.types.chat.chat_completion_chunk import Choice
|
|
15
12
|
from prompt_toolkit import print_formatted_text, HTML, Application
|
|
13
|
+
from prompt_toolkit.clipboard.pyperclip import PyperclipClipboard
|
|
16
14
|
from prompt_toolkit.layout import Layout, HSplit
|
|
17
15
|
from prompt_toolkit.widgets import TextArea
|
|
18
16
|
from rich.console import Console
|
|
19
|
-
from rich.markdown import Markdown
|
|
20
17
|
from rich.live import Live
|
|
18
|
+
from rich.markdown import Markdown
|
|
21
19
|
|
|
22
20
|
from occ.commons.config import get_env
|
|
23
|
-
from occ.utils.CommonUtil import save_and_copy_image, waiting_start, waiting_stop
|
|
24
21
|
|
|
25
22
|
DEFAULT_CHAT_LOG_ID = "chat-1"
|
|
26
23
|
DEFAULT_PROFILE = "default"
|
|
@@ -37,9 +34,9 @@ def get_home_path():
|
|
|
37
34
|
return homedir
|
|
38
35
|
|
|
39
36
|
|
|
37
|
+
clip = PyperclipClipboard()
|
|
40
38
|
console = Console()
|
|
41
39
|
|
|
42
|
-
|
|
43
40
|
def print_formatted(content: str, live: Live):
|
|
44
41
|
md = Markdown(content)
|
|
45
42
|
live.update(md)
|
|
@@ -99,6 +96,7 @@ class CommandChat:
|
|
|
99
96
|
for choice in completion.choices:
|
|
100
97
|
completion_text += choice.text
|
|
101
98
|
print_formatted(completion_text, live)
|
|
99
|
+
clip.set_text(completion_text)
|
|
102
100
|
print("\n")
|
|
103
101
|
|
|
104
102
|
def chat_completions(self, message, model):
|
|
@@ -108,7 +106,7 @@ class CommandChat:
|
|
|
108
106
|
loop = asyncio.new_event_loop()
|
|
109
107
|
asyncio.set_event_loop(loop)
|
|
110
108
|
try:
|
|
111
|
-
final_text = loop.run_until_complete(self.
|
|
109
|
+
final_text = loop.run_until_complete(self.print_streaming(self.async_stream))
|
|
112
110
|
except KeyboardInterrupt:
|
|
113
111
|
final_text = None
|
|
114
112
|
finally:
|
|
@@ -119,8 +117,8 @@ class CommandChat:
|
|
|
119
117
|
sys.exit(0)
|
|
120
118
|
md = Markdown(final_text)
|
|
121
119
|
self.append_to_history(final_text)
|
|
122
|
-
console.clear()
|
|
123
120
|
console.print(md)
|
|
121
|
+
clip.set_text(final_text)
|
|
124
122
|
self.record_chat_logs(message, {"role": self.role, "content": final_text.replace("\n\n", "")})
|
|
125
123
|
|
|
126
124
|
async def async_stream(self) -> AsyncGenerator[Choice, None]:
|
|
@@ -139,7 +137,7 @@ class CommandChat:
|
|
|
139
137
|
await asyncio.sleep(0.01)
|
|
140
138
|
yield choice
|
|
141
139
|
|
|
142
|
-
async def
|
|
140
|
+
async def print_streaming(self, async_stream):
|
|
143
141
|
self.partial_text = []
|
|
144
142
|
text_area = TextArea(
|
|
145
143
|
text="",
|
|
@@ -208,4 +206,4 @@ class CommandChat:
|
|
|
208
206
|
|
|
209
207
|
if __name__ == '__main__':
|
|
210
208
|
command_chat = CommandChat()
|
|
211
|
-
command_chat.chat("帮我写一个python
|
|
209
|
+
command_chat.chat("帮我写一个python的冒泡排序算法", "o1-mini")
|
|
@@ -53,7 +53,6 @@ def chat(message, id, profile, model, file):
|
|
|
53
53
|
style=style_from_pygments_cls(TangoStyle), multiline=True, wrap_lines=True,
|
|
54
54
|
cursor=ModalCursorShapeConfig(),
|
|
55
55
|
)
|
|
56
|
-
print_formatted_text(HTML("<ansibrightwhite>AI model Terminal</ansibrightwhite>\n"))
|
|
57
56
|
while True:
|
|
58
57
|
try:
|
|
59
58
|
message = session.prompt("👤 You: \n")
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|