commandchat 0.0.6__tar.gz → 0.0.7__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.
Files changed (24) hide show
  1. {commandchat-0.0.6 → commandchat-0.0.7}/PKG-INFO +1 -1
  2. {commandchat-0.0.6 → commandchat-0.0.7}/commandchat.egg-info/PKG-INFO +1 -1
  3. {commandchat-0.0.6 → commandchat-0.0.7}/occ/CommandChat.py +34 -1
  4. {commandchat-0.0.6 → commandchat-0.0.7}/occ/configuration/profile_config.py +12 -2
  5. {commandchat-0.0.6 → commandchat-0.0.7}/pyproject.toml +1 -1
  6. {commandchat-0.0.6 → commandchat-0.0.7}/LICENSE +0 -0
  7. {commandchat-0.0.6 → commandchat-0.0.7}/README.md +0 -0
  8. {commandchat-0.0.6 → commandchat-0.0.7}/commandchat.egg-info/SOURCES.txt +0 -0
  9. {commandchat-0.0.6 → commandchat-0.0.7}/commandchat.egg-info/dependency_links.txt +0 -0
  10. {commandchat-0.0.6 → commandchat-0.0.7}/commandchat.egg-info/entry_points.txt +0 -0
  11. {commandchat-0.0.6 → commandchat-0.0.7}/commandchat.egg-info/requires.txt +0 -0
  12. {commandchat-0.0.6 → commandchat-0.0.7}/commandchat.egg-info/top_level.txt +0 -0
  13. {commandchat-0.0.6 → commandchat-0.0.7}/occ/ConvertLogToMarkDown.py +0 -0
  14. {commandchat-0.0.6 → commandchat-0.0.7}/occ/__init__.py +0 -0
  15. {commandchat-0.0.6 → commandchat-0.0.7}/occ/command/__init__.py +0 -0
  16. {commandchat-0.0.6 → commandchat-0.0.7}/occ/command/__main__.py +0 -0
  17. {commandchat-0.0.6 → commandchat-0.0.7}/occ/commons/__init__.py +0 -0
  18. {commandchat-0.0.6 → commandchat-0.0.7}/occ/commons/config.py +0 -0
  19. {commandchat-0.0.6 → commandchat-0.0.7}/occ/configuration/__init__.py +0 -0
  20. {commandchat-0.0.6 → commandchat-0.0.7}/occ/utils/CommonUtil.py +0 -0
  21. {commandchat-0.0.6 → commandchat-0.0.7}/occ/utils/__init__.py +0 -0
  22. {commandchat-0.0.6 → commandchat-0.0.7}/occ/utils/logger.py +0 -0
  23. {commandchat-0.0.6 → commandchat-0.0.7}/setup.cfg +0 -0
  24. {commandchat-0.0.6 → commandchat-0.0.7}/setup.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: commandchat
3
- Version: 0.0.6
3
+ Version: 0.0.7
4
4
  Summary: use command to chat with openai models
5
5
  Home-page: https://github.com/
6
6
  Author: xoto
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: commandchat
3
- Version: 0.0.6
3
+ Version: 0.0.7
4
4
  Summary: use command to chat with openai models
5
5
  Home-page: https://github.com/
6
6
  Author: xoto
@@ -1,6 +1,7 @@
1
1
  import json
2
2
  import openai
3
3
  from openai import OpenAI
4
+ from openai import AzureOpenAI
4
5
  import os
5
6
 
6
7
  from occ.commons.config import get_env
@@ -34,7 +35,12 @@ class CommandChat:
34
35
  if not os.path.exists(self.file_name):
35
36
  open(self.file_name, 'w').close()
36
37
  self.messages = [json.loads(line) for line in (line.strip() for line in open(self.file_name)) if line.strip()]
37
- self.client = OpenAI()
38
+ if "azure" == get_env(profile or DEFAULT_PROFILE, "api_server_type"):
39
+ self.client = AzureOpenAI(api_key=self.api_key,
40
+ api_version=get_env(profile or DEFAULT_PROFILE, "api_version"),
41
+ azure_endpoint=self.api_base)
42
+ else:
43
+ self.client = OpenAI()
38
44
 
39
45
  def image_create(self, description, size, num):
40
46
  try:
@@ -64,7 +70,29 @@ class CommandChat:
64
70
  print(e.http_status)
65
71
  print(e.error)
66
72
 
73
+ def completions(self, message, model):
74
+ waiting_start()
75
+ stream = self.client.completions.create(
76
+ model=model,
77
+ prompt=message,
78
+ max_tokens=4090 - len(message),
79
+ temperature=0.1,
80
+ stream=True
81
+ )
82
+ waiting_stop()
83
+ for completion in stream:
84
+ for choice in completion.choices:
85
+ print(choice.text, end="")
86
+
87
+ print("\n")
88
+
67
89
  def chat(self, message, model):
90
+ if model == "gpt-35-turbo-instruct":
91
+ self.completions(message, model)
92
+ else:
93
+ self.chat_completions(message, model)
94
+
95
+ def chat_completions(self, message, model):
68
96
  openai.api_key = self.api_key
69
97
  openai.api_base = self.api_base
70
98
  message = {"role": "user", "content": message}
@@ -117,3 +145,8 @@ class CommandChat:
117
145
  f.seek(0)
118
146
  f.truncate()
119
147
  f.writelines(lines)
148
+
149
+
150
+ if __name__ == '__main__':
151
+ command_chat = CommandChat()
152
+ command_chat.chat("帮我写一个python的冒泡排序算法", "gpt-35-turbo-instruct")
@@ -9,14 +9,22 @@ def add_default_profile():
9
9
  default=config.get_default_env("api_key"), type=str)
10
10
  config.set_env('default', 'api_key', api_key)
11
11
 
12
- api_key = click.prompt(logger.style('\n[default] Your api_base_url(Optional) '),
12
+ api_base_url = click.prompt(logger.style('\n[default] Your api_base_url(Optional) '),
13
13
  default=config.get_default_env("api_base_url"), type=str)
14
- config.set_env('default', 'api_base_url', api_key)
14
+ config.set_env('default', 'api_base_url', api_base_url)
15
15
 
16
16
  limit_history = click.prompt(logger.style('\n[default] Your default limit_history '),
17
17
  default=config.get_default_env("limit_history"), type=str)
18
18
  config.set_env('default', 'limit_history', limit_history)
19
19
 
20
+ api_server_type = click.prompt(logger.style('\n[default] Your default api_server_type '),
21
+ default=config.get_default_env("api_server_type"), type=str)
22
+ config.set_env('default', 'api_server_type', api_server_type)
23
+
24
+ api_version = click.prompt(logger.style('\n[default] Your default api_version '),
25
+ default=config.get_default_env("api_version"), type=str)
26
+ config.set_env('default', 'api_version', api_version)
27
+
20
28
 
21
29
  def input_config_vars(profile_name, key_name, is_default_exist):
22
30
  if is_default_exist:
@@ -34,3 +42,5 @@ def add_profile(profile_name):
34
42
  input_config_vars(profile_name, 'api_key', False)
35
43
  input_config_vars(profile_name, 'api_base_url', False)
36
44
  input_config_vars(profile_name, 'limit_history', False)
45
+ input_config_vars(profile_name, 'api_server_type', False)
46
+ input_config_vars(profile_name, 'api_version', False)
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "commandchat"
7
- version = "0.0.6"
7
+ version = "0.0.7"
8
8
  description = "use command to chat with openai models"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.8"
File without changes
File without changes
File without changes
File without changes
File without changes