Skip to content

Commit 43d57c0

Browse files
committed
feat: Return report data in quote call
1 parent 5e0f7cd commit 43d57c0

File tree

2 files changed

+26
-7
lines changed

2 files changed

+26
-7
lines changed

pkg/agent/agent.go

+15-5
Original file line numberDiff line numberDiff line change
@@ -583,21 +583,31 @@ func (a *Agent) consumePrompt(ctx context.Context, agentAddress *felt.Felt, prom
583583
return txHash, nil
584584
}
585585

586-
func (a *Agent) quote(ctx context.Context) (string, error) {
586+
type QuoteData struct {
587+
Quote string
588+
ReportData *quote.ReportData
589+
}
590+
591+
func (a *Agent) quote(ctx context.Context) (*QuoteData, error) {
587592
slog.Info("requesting quote")
588593

589-
quote, err := a.quoter.Quote(ctx, &quote.ReportData{
594+
reportData := &quote.ReportData{
590595
Address: a.account.Address(),
591596
ContractAddress: a.agentRegistryAddress,
592597
TwitterUsername: a.twitterClientConfig.Username,
593-
})
598+
}
599+
600+
quote, err := a.quoter.Quote(ctx, reportData)
594601
if err != nil {
595-
return "", fmt.Errorf("failed to get quote: %v", err)
602+
return nil, fmt.Errorf("failed to get quote: %v", err)
596603
}
597604

598605
slog.Info("quote generated successfully")
599606

600-
return quote, nil
607+
return &QuoteData{
608+
Quote: quote,
609+
ReportData: reportData,
610+
}, nil
601611
}
602612

603613
func (a *Agent) validateTweetText(tweetText, agentName, promptText string) error {

pkg/agent/api.go

+11-2
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,22 @@ func (a *Agent) StartServer(ctx context.Context) error {
4545
})
4646

4747
router.GET("/quote", func(c *gin.Context) {
48-
quote, err := a.quote(c.Request.Context())
48+
quoteData, err := a.quote(c.Request.Context())
4949
if err != nil {
5050
c.String(http.StatusInternalServerError, err.Error())
5151
return
5252
}
5353

54-
c.JSON(http.StatusOK, quote)
54+
resp := gin.H{
55+
"report_data": gin.H{
56+
"address": quoteData.ReportData.Address.String(),
57+
"contract_address": quoteData.ReportData.ContractAddress.String(),
58+
"twitter_username": quoteData.ReportData.TwitterUsername,
59+
},
60+
"quote": quoteData.Quote,
61+
}
62+
63+
c.JSON(http.StatusOK, resp)
5564
})
5665

5766
server := &http.Server{

0 commit comments

Comments
 (0)