yGuy / chatgpt-mattermost-bot

A very simple implementation of a service for a mattermost bot that uses ChatGPT in the backend.
MIT License
145 stars 50 forks source link

[FeatureRequest] Channel Content processable with chatgpt #28

Open PatrickHuetter opened 1 year ago

PatrickHuetter commented 1 year ago

A friend of mine has build a similar bot for slack.

One thing he can do with it, is to summarize the conversations of a channel in a specific time frame (see screenshot).

It would be nice if this bot could also do something like this. In my opinion an UI isn't needed. A short command to chatgpt with the params should be enough.

It could also be used for different commands that have channel content as context.

image

Result:

image

yGuy commented 1 year ago

Not sure, whether this is really necessary, because you can do that already with some prompt "engineering": However for very long threads, we might run into token limits.

image

yGuy commented 1 year ago

Adding a GUI is currently out of the scope of this project, as this is an external add-on and not a Mattermost Plugin. I would prefer if we implemented this similarly to the way it has been done, above, just via regular chat. We could improve the prompting for this, of course.

PatrickHuetter commented 1 year ago

@yGuy I wouldn't expect a GUI for this. A prompt is perfect. But currently it's not possible in channels since context is missing. It only works for threads. I would be nice if we could use channel as a context, maybe limited to a concrete number of posts in a channel.

yGuy commented 1 year ago

OK, I guess the idea would be to use two queries: the first one detects whether the user was asking for a summarization and tries to infer the scope of the summarization. In case this "matches" we parse the scope from the answer, collect all entries in the scope and pass them to the LLM for summarization.

That would work and I would be willing to help with the implementation if someone does the initial prompting work.

yGuy commented 1 year ago

You might want to try out version 2.0.0 which should be able to do some of this, now. It knows the names of the persons talking and has access to a method that will provide it with the necessary context. Let us know how this works for you!

PatrickHuetter commented 1 year ago

@yGuy i just updated to the new version but now the whole bot doesn't work anymore. Sorry, but I encountered an internal error when trying to process your message

Log output:

{"level":"ERROR","time":"2023-07-20T12:50:21.623Z","name":"bot","msg":"Request failed with status code 400","pid":1,"hostname":"mattermost-chatgpt-55b4877585-8tmrb","diff":0,"err │
│ ":{"name":"Error","stack":"Error: Request failed with status code 400\n    at createError (/app/node_modules/axios/lib/core/createError.js:16:15)\n    at settle (/app/node_module │
│ s/axios/lib/core/settle.js:17:12)\n    at IncomingMessage.handleStreamEnd (/app/node_modules/axios/lib/adapters/http.js:322:11)\n    at IncomingMessage.emit (node:events:525:35)\ │
│ n    at endReadableNT (node:internal/streams/readable:1359:12)\n    at process.processTicksAndRejections (node:internal/process/task_queues:82:21)","config":{"transitional":{"sil │
│ entJSONParsing":true,"forcedJSONParsing":true,"clarifyTimeoutError":false},"transformRequest":[null],"transformResponse":[null],"timeout":0,"xsrfCookieName":"XSRF-TOKEN","xsrfHea │
│ derName":"X-XSRF-TOKEN","maxContentLength":-1,"maxBodyLength":-1,"headers":{"Accept":"application/json, text/plain, */*","Content-Type":"application/json","User-Agent":"OpenAI/No │
│ deJS/3.3.0","Authorization":"Bearer sk-adsiuhasdjhassomeBearerTOKEN","Content-Length":1357},"method":"post","data":"{\"model\":\"gpt-3.5-turbo\",\"messages\": │
│ [{\"role\":\"system\",\"content\":\"Your name is @chatgpt and you are a helpful assistant. Whenever the user asks you for help you will provide him with succinct answers. When us │
│ ing functions check for each function argument if the user provided enough information to satisfy the requirements of the argument. If not, ask the user for more information and  │
│ do not call the function. You know the users name as it is provided within the meta data of his messages.\"},{\"role\":\"user\",\"name\":\"p.huetter\",\"content\":\"@chatgpt bist │
│  du da?\"}],\"max_tokens\":2000,\"temperature\":1,\"functions\":[{\"name\":\"exit-plugin\",\"description\":\"Says goodbye to the user and wish him a good day.\",\"parameters\":{\ │
│ "type\":\"object\",\"properties\":{},\"required\":[]}},{\"name\":\"message-collect-plugin\",\"description\":\"Collects messages in the thread for a specific user or time\",\"para │
│ meters\":{\"type\":\"object\",\"properties\":{\"lookBackTime\":{\"type\":\"number\",\"description\":\"The time in milliseconds to look back in time and collect messages which wer │
│ e posted within this timespan. Omit this parameter if the collected messages are independent from the time they were sent.\"},\"messageCount\":{\"type\":\"number\",\"description\ │
│ ":\"The number of messages which should be collected. Omit this parameter if you want to collect all messages.\"}},\"required\":[]}}],\"function_call\":\"auto\"}","url":"https:// │
│ api.openai.com/v1/chat/completions"},"status":400}}
yGuy commented 1 year ago

:-(

This is due to #46

MichaelH201 commented 1 year ago

Oh oh. It seems like OpenAI does not like your username. This is a circumstance we weren't aware of.

{
  "error": {
    "message": "'p.huetter' does not match '^[a-zA-Z0-9_-]{1,64}$' - 'messages.1.name'",
    "type": "invalid_request_error",
    "param": null,
    "code": null
  }
}

https://github.com/yGuy/chatgpt-mattermost-bot/blob/c6203ebb4265901f38b0baf1ed203c241789d278/src/botservice.ts#L187 This is the line where we obtain the username from mattermost. A possibility would be to remove every character from the username which does not follow the regex from OpenAI ^[a-zA-Z0-9_-]{1,64}$

PatrickHuetter commented 1 year ago

Is it possible to use the display name instead of the username if exists? That would be more convenient. The problem with the special characters in the username is already fixed as i can see.

yGuy commented 1 year ago

We could be using the display name, too, of course. Although chances are even bigger that it won't work with OpenAI. No Spaces allowed, e.g., only very limited set of ASCIIs characters (see the regex). I don't understand why, but that's how the OpenAI API wants it to be.

yGuy commented 11 months ago

The last issue could be solved by fixing https://github.com/yGuy/chatgpt-mattermost-bot/issues/55