Skip to content

Commit

Permalink
Fix ThreadIDProp and regeneration issues (#102)
Browse files Browse the repository at this point in the history
* Fix some regeneration issues

* Fix ThreadIDProp being able to be used by others.
  • Loading branch information
crspeller authored Jan 3, 2024
1 parent 925d9cb commit e3223a5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
15 changes: 10 additions & 5 deletions server/api_post.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,16 @@ func (p *Plugin) handleRegenerate(c *gin.Context) {
post := c.MustGet(ContextPostKey).(*model.Post)
channel := c.MustGet(ContextChannelKey).(*model.Channel)

if post.UserId != p.botid {
c.AbortWithError(http.StatusBadRequest, errors.New("Not a AI bot post"))
return
}

if post.GetProp("llm_requester_user_id") != userID {
c.AbortWithError(http.StatusForbidden, errors.New("only the original poster can regenerate"))
return
}

user, err := p.pluginAPI.User.Get(userID)
if err != nil {
c.AbortWithError(http.StatusInternalServerError, err)
Expand All @@ -141,11 +151,6 @@ func (p *Plugin) handleRegenerate(c *gin.Context) {

postToRegenerate := threadData.latestPost()

if user.Id != postToRegenerate.UserId {
c.AbortWithError(http.StatusForbidden, errors.New("only the original poster can regenerate"))
return
}

context := p.MakeConversationContext(user, channel, postToRegenerate)
conversation, err := p.prompts.ChatCompletion(ai.PromptDirectMessageQuestion, context)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion server/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func (p *Plugin) continueConversation(context ai.ConversationContext) error {
// Special handing for threads started by the bot in response to a summarization request.
var result *ai.TextStreamResult
originalThreadID, ok := threadData.Posts[0].GetProp(ThreadIDProp).(string)
if ok && originalThreadID != "" {
if ok && originalThreadID != "" && threadData.Posts[0].UserId == p.botid {
threadPost, err := p.pluginAPI.Post.GetPost(originalThreadID)
if err != nil {
return err
Expand Down

0 comments on commit e3223a5

Please sign in to comment.