update: 函数使用异步方式
This commit is contained in:
@@ -124,7 +124,7 @@ class XAi(Platform):
|
|||||||
def __init__(self, config: BaseProxyConfig, http: ClientSession) -> None:
|
def __init__(self, config: BaseProxyConfig, http: ClientSession) -> None:
|
||||||
super().__init__(config, http)
|
super().__init__(config, http)
|
||||||
|
|
||||||
def create_chat_completion(self, plugin: AbsExtraConfigPlugin, evt: MessageEvent) -> ChatCompletion:
|
async def create_chat_completion(self, plugin: AbsExtraConfigPlugin, evt: MessageEvent) -> ChatCompletion:
|
||||||
full_context = []
|
full_context = []
|
||||||
context = await maubot_llmplus.platforms.get_context(plugin, self, evt)
|
context = await maubot_llmplus.platforms.get_context(plugin, self, evt)
|
||||||
full_context.extend(list(context))
|
full_context.extend(list(context))
|
||||||
@@ -143,7 +143,7 @@ class XAi(Platform):
|
|||||||
request_body["temperature"] = self.temperature
|
request_body["temperature"] = self.temperature
|
||||||
|
|
||||||
endpoint = f"{self.url}/v1/chat/completions"
|
endpoint = f"{self.url}/v1/chat/completions"
|
||||||
with self.http.post(url=endpoint, data=json.dumps(request_body), headers=headers) as resp:
|
async with self.http.post(url=endpoint, data=json.dumps(request_body), headers=headers) as resp:
|
||||||
# plugin.log.debug(f"响应内容:{response.status}, {await response.json()}")
|
# plugin.log.debug(f"响应内容:{response.status}, {await response.json()}")
|
||||||
if response.status != 200:
|
if response.status != 200:
|
||||||
return ChatCompletion(
|
return ChatCompletion(
|
||||||
@@ -161,7 +161,7 @@ class XAi(Platform):
|
|||||||
|
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def list_models(self) -> List[str]:
|
async def list_models(self) -> List[str]:
|
||||||
# 调用openai接口获取模型列表
|
# 调用openai接口获取模型列表
|
||||||
full_url = f"{self.url}/v1/models"
|
full_url = f"{self.url}/v1/models"
|
||||||
async with self.http.get(full_url) as response:
|
async with self.http.get(full_url) as response:
|
||||||
|
|||||||
Reference in New Issue
Block a user