mirror of
https://github.com/hibobmaster/matrix_chatgpt_bot.git
synced 2024-10-01 05:35:36 -04:00
Fix !gpt command
This commit is contained in:
parent
180826534b
commit
0197e8b3d2
@ -564,10 +564,11 @@ class Bot:
|
||||
sender_id=sender_id,
|
||||
user_message=raw_user_message,
|
||||
)
|
||||
except Exception:
|
||||
except Exception as e:
|
||||
await self.send_general_error_message(
|
||||
room_id, reply_to_event_id, sender_id, raw_user_message
|
||||
)
|
||||
logger.error(e)
|
||||
|
||||
# !lc command
|
||||
async def lc(
|
||||
|
@ -4,8 +4,7 @@ A simple wrapper for the official ChatGPT API
|
||||
"""
|
||||
import json
|
||||
from typing import AsyncGenerator
|
||||
from tenacity import retry, stop_after_attempt, wait_random_exponential
|
||||
|
||||
from tenacity import retry, wait_random_exponential, stop_after_attempt
|
||||
import httpx
|
||||
import tiktoken
|
||||
|
||||
@ -267,11 +266,16 @@ class Chatbot:
|
||||
model: str = None,
|
||||
**kwargs,
|
||||
) -> str:
|
||||
async with self.aclient.post(
|
||||
response = await self.aclient.post(
|
||||
url=self.api_url,
|
||||
json={
|
||||
"model": model or self.engine,
|
||||
"messages": prompt,
|
||||
"messages": [
|
||||
{
|
||||
"role": role,
|
||||
"content": prompt,
|
||||
}
|
||||
],
|
||||
# kwargs
|
||||
"temperature": kwargs.get("temperature", self.temperature),
|
||||
"top_p": kwargs.get("top_p", self.top_p),
|
||||
@ -287,6 +291,6 @@ class Chatbot:
|
||||
},
|
||||
headers={"Authorization": f"Bearer {kwargs.get('api_key', self.api_key)}"},
|
||||
timeout=kwargs.get("timeout", self.timeout),
|
||||
) as response:
|
||||
resp = await response.read()
|
||||
return json.loads(resp)["choices"][0]["message"]["content"]
|
||||
)
|
||||
resp = response.json()
|
||||
return resp["choices"][0]["message"]["content"]
|
||||
|
Loading…
Reference in New Issue
Block a user