mirror of
https://github.com/FoundationAgents/MetaGPT.git
synced 2026-05-12 17:22:37 +02:00
fixed
This commit is contained in:
parent
e315d8365b
commit
5709e48713
2 changed files with 18 additions and 17 deletions
|
|
@ -17,7 +17,7 @@ from metagpt.logs import logger
|
|||
from metagpt.roles import Role
|
||||
from metagpt.schema import Message
|
||||
from metagpt.utils.common import NoMoneyException
|
||||
from metagpt.llm import LLM
|
||||
from metagpt.llm import DEFAULT_LLM
|
||||
正方一辩提示词='''
|
||||
##角色
|
||||
现在你是一名高水平,有辩论技巧,有强大表达能力的辩手。
|
||||
|
|
@ -105,7 +105,7 @@ def main(
|
|||
asyncio.run(startup(zf,ff))
|
||||
|
||||
async def startup(正方辩题:str,反方辩题:str):
|
||||
llm=LLM()
|
||||
llm=DEFAULT_LLM
|
||||
#一辩环节
|
||||
#正方
|
||||
|
||||
|
|
|
|||
|
|
@ -10,19 +10,20 @@ from datetime import datetime
|
|||
from time import mktime
|
||||
from urllib.parse import urlencode
|
||||
from wsgiref.handlers import format_date_time
|
||||
from metagpt.logs import logger
|
||||
|
||||
import websocket # 使用websocket_client
|
||||
answer = ""
|
||||
|
||||
class Ws_Param(object):
|
||||
# 初始化
|
||||
def __init__(self, APPID, APIKey, APISecret, Spark_url):
|
||||
self.APPID = APPID
|
||||
self.APIKey = APIKey
|
||||
self.APISecret = APISecret
|
||||
self.host = urlparse(Spark_url).netloc
|
||||
self.path = urlparse(Spark_url).path
|
||||
self.Spark_url = Spark_url
|
||||
def __init__(self, appid, apikey, apiSecret, spark_url):
|
||||
self.appid = appid
|
||||
self.apikey = apikey
|
||||
self.apiSecret = apiSecret
|
||||
self.host = urlparse(spark_url).netloc
|
||||
self.path = urlparse(spark_url).path
|
||||
self.spark_url = spark_url
|
||||
|
||||
# 生成url
|
||||
def create_url(self):
|
||||
|
|
@ -36,12 +37,12 @@ class Ws_Param(object):
|
|||
signature_origin += "GET " + self.path + " HTTP/1.1"
|
||||
|
||||
# 进行hmac-sha256进行加密
|
||||
signature_sha = hmac.new(self.APISecret.encode('utf-8'), signature_origin.encode('utf-8'),
|
||||
signature_sha = hmac.new(self.apiSecret.encode('utf-8'), signature_origin.encode('utf-8'),
|
||||
digestmod=hashlib.sha256).digest()
|
||||
|
||||
signature_sha_base64 = base64.b64encode(signature_sha).decode(encoding='utf-8')
|
||||
|
||||
authorization_origin = f'api_key="{self.APIKey}", algorithm="hmac-sha256", headers="host date request-line", signature="{signature_sha_base64}"'
|
||||
authorization_origin = f'api_key="{self.apikey}", algorithm="hmac-sha256", headers="host date request-line", signature="{signature_sha_base64}"'
|
||||
|
||||
authorization = base64.b64encode(authorization_origin.encode('utf-8')).decode(encoding='utf-8')
|
||||
|
||||
|
|
@ -52,19 +53,19 @@ class Ws_Param(object):
|
|||
"host": self.host
|
||||
}
|
||||
# 拼接鉴权参数,生成url
|
||||
url = self.Spark_url + '?' + urlencode(v)
|
||||
url = self.spark_url + '?' + urlencode(v)
|
||||
# 此处打印出建立连接时候的url,参考本demo的时候可取消上方打印的注释,比对相同参数时生成的url与自己代码生成的url是否一致
|
||||
return url
|
||||
|
||||
|
||||
# 收到websocket错误的处理
|
||||
def on_error(ws, error):
|
||||
print("### error:", error)
|
||||
logger.error("### error:"+error)
|
||||
|
||||
|
||||
# 收到websocket关闭的处理
|
||||
def on_close(ws,one,two):
|
||||
print(" ")
|
||||
logger.error("websocket关闭")
|
||||
|
||||
|
||||
# 收到websocket连接建立的处理
|
||||
|
|
@ -83,7 +84,7 @@ def on_message(ws, message):
|
|||
data = json.loads(message)
|
||||
code = data['header']['code']
|
||||
if code != 0:
|
||||
print(f'请求错误: {code}, {data}')
|
||||
logger.error(f'请求错误: {code}, {data}')
|
||||
ws.close()
|
||||
else:
|
||||
choices = data["payload"]["choices"]
|
||||
|
|
@ -123,9 +124,9 @@ def gen_params(appid, domain,question):
|
|||
return data
|
||||
|
||||
|
||||
def main(appid, api_key, api_secret, Spark_url,domain, question):
|
||||
def main(appid, api_key, api_secret, spark_url,domain, question):
|
||||
# print("星火:")
|
||||
wsParam = Ws_Param(appid, api_key, api_secret, Spark_url)
|
||||
wsParam = Ws_Param(appid, api_key, api_secret, spark_url)
|
||||
websocket.enableTrace(False)
|
||||
wsUrl = wsParam.create_url()
|
||||
ws = websocket.WebSocketApp(wsUrl, on_message=on_message, on_error=on_error, on_close=on_close, on_open=on_open)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue