Skip to content

Commit

Permalink
feat: Refactor AddLLMStormTask to use string payload and add GetLLMSt…
Browse files Browse the repository at this point in the history
…ormTaskResult function
  • Loading branch information
Laisky committed Feb 5, 2025
1 parent 127a22b commit 35f1aa5
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions library/db/redis/tasks.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,30 @@ func (db *DB) AddLLMStormTask(ctx context.Context,
apiKey string,
) (taskID string, err error) {
task := NewLLMStormTask(prompt, apiKey)
if err = db.db.RPush(ctx, KeyTaskLLMStormPending, task); err != nil {
return taskID, errors.Wrap(err, "rpush")
payload, err := task.ToString()
if err != nil {
return taskID, errors.Wrap(err, "task.ToString")
}

if err = db.db.RPush(ctx, KeyTaskLLMStormPending, payload); err != nil {
return taskID, errors.Wrapf(err, "push task to key `%s`", KeyTaskLLMStormPending)
}

return taskID, nil
}

// GetLLMStormTaskResult gets the result of a LLMStormTask by taskID
func (db *DB) GetLLMStormTaskResult(ctx context.Context, taskID string) (task *LLMStormTask, err error) {
key := KeyPrefixTaskLLMStormResult + taskID
_, val, err := db.db.LPopKeysBlocking(ctx, key)
if err != nil {
return nil, errors.Wrapf(err, "get task result by key `%s`", key)
}

task, err = NewLLMStormTaskFromString(val)
if err != nil {
return nil, errors.Wrapf(err, "parse task `%s` result from string", taskID)
}

return task, nil
}

0 comments on commit 35f1aa5

Please sign in to comment.