update: 修改anthropic请求体
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
import json
|
import json
|
||||||
|
from collections import deque
|
||||||
|
|
||||||
from typing import List
|
from typing import List
|
||||||
|
|
||||||
@@ -83,15 +84,13 @@ class Anthropic(Platform):
|
|||||||
|
|
||||||
async def create_chat_completion(self, plugin: AbsExtraConfigPlugin, evt: MessageEvent) -> ChatCompletion:
|
async def create_chat_completion(self, plugin: AbsExtraConfigPlugin, evt: MessageEvent) -> ChatCompletion:
|
||||||
full_chat_context = []
|
full_chat_context = []
|
||||||
system_context = await maubot_llmplus.platforms.get_system_context(plugin, self, evt)
|
system_context = deque()
|
||||||
full_system_context = []
|
|
||||||
chat_context = await maubot_llmplus.platforms.get_chat_context(system_context, plugin, self, evt)
|
chat_context = await maubot_llmplus.platforms.get_chat_context(system_context, plugin, self, evt)
|
||||||
full_chat_context.extend(list(chat_context))
|
full_chat_context.extend(list(chat_context))
|
||||||
full_system_context.extend(list(system_context))
|
|
||||||
|
|
||||||
endpoint = f"{self.url}/v1/messages"
|
endpoint = f"{self.url}/v1/messages"
|
||||||
headers = {"x-api-key": self.api_key, "anthropic-version": "2023-06-01", "content-type": "application/json"}
|
headers = {"x-api-key": self.api_key, "anthropic-version": "2023-06-01", "content-type": "application/json"}
|
||||||
req_body = {"model": self.model, "max_tokens": self.max_tokens, "system": full_system_context, "messages": full_chat_context}
|
req_body = {"model": self.model, "max_tokens": self.max_tokens, "system": self.system_prompt, "messages": full_chat_context}
|
||||||
|
|
||||||
async with self.http.post(endpoint, headers=headers, data=json.dumps(req_body)) as response:
|
async with self.http.post(endpoint, headers=headers, data=json.dumps(req_body)) as response:
|
||||||
# plugin.log.debug(f"响应内容:{response.status}, {await response.json()}")
|
# plugin.log.debug(f"响应内容:{response.status}, {await response.json()}")
|
||||||
|
|||||||
Reference in New Issue
Block a user