mattermost / mattermost-plugin-ai

Mattermost Copilot plugin supporting multiple LLMs
https://mattermost.com/copilot
Apache License 2.0
135 stars 26 forks source link

🐛 bug: Anthropic model integration Issue: Header requirement error and failed responses #145

Closed McHarryDentaire closed 8 months ago

McHarryDentaire commented 8 months ago

Description

I have encountered an issue with the Anthropic model integration on Mattermost using the mattermost-plugin-ai. After following the documentation for installing the module and configuring it to use the Anthropic model, I am unable to receive any responses due to errors.

Ai_services

The errors encountered are as follows:

  1. "error [2024-03-05 21:05:43.872 +01:00] failed to get github plugin status caller="app/plugin_api.go:988" plugin_id=mattermost-ai error="not found"
  2. "error [2024-03-05 21:05:44.256 +01:00] Streaming result to post failed caller="app/plugin_api.go:988" plugin_id=mattermost-ai error="non 200 response from anthropic: 400 Bad Request Body: {"type":"error","error":{"type":"invalid_request_error","message":"anthropic-version: header is required"}} github.com/mattermost/mattermost-plugin-ai/server/ai/anthropic.(*Client).Completion.func1 github.com/mattermost/mattermost-plugin-ai/server/ai/anthropic/client.go:132 runtime.goexit runtime/asm_amd64.s:1650"
  3. "error [2024-03-05 21:05:44.281 +01:00] Failed to generate title caller="app/plugin_api.go:988" plugin_id=mattermost-ai error="failed to get title: failed to send query to anthropic: non 200 response from anthropic: 400 Bad Request"

Here is my configuration:

It seems like there is an issue with the plugin not properly sending or including the required anthropic-version header when making requests to the Anthropic model, resulting in a 400 Bad Request error.

Additionally, I have tested the Anthropic API directly through my Python scripts, and it works as expected, which indicates that the issue might be specifically related to the mattermost-plugin-ai configuration or its interaction with the API. I suspect that the problem may arise from a missing header configuration in the plugin code. It seems that the req.Header.Set("anthropic-version", "<VERSION>") might not be properly set in the server/ai/anthropic/client.go file, which could lead to the observed 400 Bad Request error due to the missing anthropic-version header. Including this header configuration might resolve the issue.

I would appreciate any guidance or a fix for this issue.

McHarryDentaire commented 8 months ago

I've added the following line:

req.Header.Set("anthropic-version", "2023-06-01")

to the following functions (server/ai/anthropic/client.go):

func (c *Client) CompletionNoStream(...)
func (c *Client) Completion(prompt string) ...

After implementing this change, the previous error was resolved. However, I encountered a new issue:

error [2024-03-07 20:38:14.246 +01:00] websocket request handling error caller="wsapi/websocket_handler.go:58" action=user_typing seq=3 user_id=xxxxxxxxxxxxxxxxx error_message="Invalid channel_id parameter." error="websocket: user_typing: Invalid channel_id parameter." error [2024-03-07 20:38:15.016 +01:00] failed to get github plugin status caller="app/plugin_api.go:988" plugin_id=mattermost-ai error="not found"

Additionally, I just updated Mattermost from 9.4.2 to 9.6.0. I encountered a similar error:

error [2024-03-07 21:17:10.125 +01:00] failed to get GitHub plugin status caller="app/plugin_api.go:1003" plugin_id=mattermost-ai error="not found"

crspeller commented 8 months ago

@McHarryDentaire Fixed with #147, thanks for reporting this! Decided to do a bit of overkill and update the whole client to use the newer Messages API.

As for your other error, that should not effect the operation of the plugin, it is occurring because you don't have the Github plugin installed. Are you experiencing operational issues or just the log message? Try with #147 and let me know if that works.

McHarryDentaire commented 8 months ago

@crspeller Great, thank you. It works like a charm.

Regarding the GitHub plugin not being installed, I'm not experiencing any operational issues, just seeing this error log.

crspeller commented 8 months ago

Great! https://github.com/mattermost/mattermost-plugin-ai/pull/148 will remove that unnecessary error log.

cedarice commented 6 months ago

I got the similar issue using ollama server with qwen 14b LLM. The error message is "websocket: user_typing: Invalid channel_id parameter.". I can receive responses from AI, but occasionally irrelevant content appears. These irrelevant content suggested that the reply may contain elements of other users' responses.