Skip to content

Commit

Permalink
增加对私有化部署的支持,移除不必要的代码
Browse files Browse the repository at this point in the history
  • Loading branch information
Haibersut committed Jul 27, 2023
1 parent ab737f8 commit 0b22e39
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions adapter/chatgpt/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,10 @@ def count_tokens(self, session_id: str = "default", model: str = DEFAULT_ENGINE)
for message in self.conversation[session_id]:
num_tokens += tokens_per_message
for key, value in message.items():
num_tokens += len(encoding.encode(value))
if key == "name":
num_tokens += tokens_per_name
if value is not None:
num_tokens += len(encoding.encode(value))
if key == "name":
num_tokens += tokens_per_name
num_tokens += 3 # every reply is primed with assistant
return num_tokens

Expand Down Expand Up @@ -109,7 +110,6 @@ def __init__(self, session_id: str = "unknown"):
"gpt-4-32k-0314",
"gpt-4-0613",
"gpt-4-32k-0613",
"claude-2-web",
]

def manage_conversation(self, session_id: str, prompt: str):
Expand Down Expand Up @@ -252,9 +252,10 @@ async def request_with_stream(self, session_id: str = None, messages: list = Non
response_role = delta['role']
if 'content' in delta:
event_text = delta['content']
completion_text += event_text
self.latest_role = response_role
yield event_text
if event_text is not None:
completion_text += event_text
self.latest_role = response_role
yield event_text
self.bot.add_to_conversation(completion_text, response_role, session_id)

async def compressed_session(self, session_id: str):
Expand Down

0 comments on commit 0b22e39

Please sign in to comment.