Skip to content

Commit

Permalink
1. update README Zeabur banner
Browse files Browse the repository at this point in the history
2. fixed bug: This model's maximum context length

3. Fix the logic error of replying to messages in Telegram
  • Loading branch information
yym68686 committed Nov 25, 2023
1 parent c7f2607 commit f19853c
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 5 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ Join the [Telegram Group](https://t.me/+_01cz9tAkUc1YzZl) chat to share your use

One-click deployment:

[![Deploy on Zeabur](https://zeabur.com/button.svg)](https://zeabur.com/templates/R5JY5O?referralCode=yym68686)
[![Deployed on Zeabur](https://zeabur.com/deployed-on-zeabur-dark.svg)](https://zeabur.com?referralCode=yym68686&utm_source=yym68686&utm_campaign=oss)
<!-- [![Deploy on Zeabur](https://zeabur.com/button.svg)](https://zeabur.com/templates/R5JY5O?referralCode=yym68686) -->

If you need follow-up function updates, the following deployment method is recommended:

Expand Down
2 changes: 1 addition & 1 deletion bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
translator_prompt = "You are a translation engine, you can only translate text and cannot interpret it, and do not explain. Translate the text to {}, please do not explain any sentences, just translate or leave them as they are. this is the content you need to translate: "
@decorators.Authorization
async def command_bot(update, context, language=None, prompt=translator_prompt, title="", robot=None, has_command=True):
if update.message.reply_to_message is None:
if update.message.reply_to_message is None or update.message.reply_to_message.text:
if has_command == False or len(context.args) > 0:
message = update.message.text if config.NICK is None else update.message.text[botNicKLength:].strip() if update.message.text[:botNicKLength].lower() == botNick else None
if has_command:
Expand Down
12 changes: 10 additions & 2 deletions chatgpt2api/chatgpt2api.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,10 @@ def ask_stream(
)
headers = {"Authorization": f"Bearer {kwargs.get('api_key', self.api_key)}"}

if self.engine == "gpt-4-1106-preview":
model_max_tokens = kwargs.get("max_tokens", self.max_tokens)
else:
model_max_tokens = min(self.get_max_tokens(convo_id=convo_id) - 500, kwargs.get("max_tokens", self.max_tokens))
json_post = {
"model": os.environ.get("MODEL_NAME") or model or self.engine,
"messages": self.conversation[convo_id] if pass_history else [{"role": "system","content": self.system_prompt},{"role": role, "content": prompt}],
Expand All @@ -313,7 +317,7 @@ def ask_stream(
),
"n": kwargs.get("n", self.reply_count),
"user": role,
"max_tokens": kwargs.get("max_tokens", self.max_tokens),
"max_tokens": model_max_tokens,
# "max_tokens": min(
# self.get_max_tokens(convo_id=convo_id),
# kwargs.get("max_tokens", self.max_tokens),
Expand Down Expand Up @@ -402,6 +406,10 @@ async def ask_stream_async(
self.reset(convo_id=convo_id, system_prompt=self.system_prompt)
self.add_to_conversation(prompt, "user", convo_id=convo_id)
self.__truncate_conversation(convo_id=convo_id)
if self.engine == "gpt-4-1106-preview":
model_max_tokens = kwargs.get("max_tokens", self.max_tokens)
else:
model_max_tokens = min(self.get_max_tokens(convo_id=convo_id) - 500, kwargs.get("max_tokens", self.max_tokens))
# Get response
async with self.aclient.stream(
"post",
Expand All @@ -424,7 +432,7 @@ async def ask_stream_async(
),
"n": kwargs.get("n", self.reply_count),
"user": role,
"max_tokens": kwargs.get("max_tokens", self.max_tokens),
"max_tokens": model_max_tokens,
# "max_tokens": min(
# self.get_max_tokens(convo_id=convo_id),
# kwargs.get("max_tokens", self.max_tokens),
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
--index-url https://pypi.python.org/simple/
tiktoken
requests
python-telegram-bot[webhook,rate-limiter]==20.6
python-telegram-bot[webhooks,rate-limiter]==20.6

# langchain
chromadb
Expand Down

0 comments on commit f19853c

Please sign in to comment.