Skip to content

Commit

Permalink
feat(promptcall): add variables info when prompt debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
AnnatarHe committed Oct 1, 2023
1 parent 1a4d400 commit fba4c01
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions ent/schema/promptcall.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ func (PromptCall) Fields() []ent.Field {
field.Int64("duration"),
// 0: success, 1: fail
field.Int("result"),
field.JSON("payload", map[string]string{}).Optional(),
// only available when prompt.debug is true
field.String("message").Optional().Nillable(),
}
Expand Down
3 changes: 3 additions & 0 deletions routes/prompt.api.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,9 @@ func apiRunPrompt(c *gin.Context) {
SetDuration(endTime.Sub(startTime).Milliseconds()).
SetProjectID(pj.ID)

if prompt.Debug {
stat.SetPayload(payload.Variables)
}
if prompt.Debug && len(res.Choices) > 0 {
stat.SetMessage(res.Choices[0].Message.Content)
}
Expand Down
14 changes: 14 additions & 0 deletions schema/call.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ package schema

import (
"context"
"encoding/json"
"net/http"
"time"

"github.com/PromptPal/PromptPal/ent"
"github.com/PromptPal/PromptPal/ent/prompt"
"github.com/PromptPal/PromptPal/ent/promptcall"
"github.com/PromptPal/PromptPal/service"
"github.com/sirupsen/logrus"
)

// calls(promptId: Int!, pagination: PaginationInput!): PromptCallList!
Expand Down Expand Up @@ -85,6 +87,18 @@ func (p promptCallResponse) Result() string {
}
return "fail"
}
func (p promptCallResponse) Payload() string {
if p.pc.Payload == nil {
return "{}"
}
result, err := json.Marshal(p.pc.Payload)
if err != nil {
logrus.Warnln("promptCall.payload", err)
return "{}"
}
return string(result)
}

func (p promptCallResponse) Message() *string {
return p.pc.Message
}
Expand Down
1 change: 1 addition & 0 deletions schema/types/call.gql
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ type PromptCall {
totalToken: Int!
duration: Int!
result: PromptCallResult!
payload: String!
message: String
createdAt: String!
}
Expand Down

0 comments on commit fba4c01

Please sign in to comment.