Skip to content

Conversation

@GeLi2001
Copy link
Contributor

@GeLi2001 GeLi2001 commented Jun 17, 2025

Screenshot 2025-06-17 at 10 28 45 AM

Summary by Sourcery

Implement prompt template abstraction and variable substitution in playground instances, update span details UI to leverage the new formatter, and add corresponding tests.

New Features:

  • Apply prompt template variables to playground chat messages using Mustache formatting utilities.

Enhancements:

  • Introduce formatPromptTemplate helper for consistent prompt template display in span details UI.
  • Refactor conditional rendering in LLMMessage for improved clarity.

Tests:

  • Add unit tests for prompt template variable application in transformSpanAttributesToPlaygroundInstance.

Summary by Sourcery

Implement prompt template abstraction to support variable substitution in playground instances and update span details UI to leverage the new formatter

New Features:

  • Apply prompt template variables to playground chat messages using Mustache formatting utilities

Enhancements:

  • Introduce formatPromptTemplate helper for consistent prompt template display in span details UI
  • Refactor conditional rendering in LLMMessage for improved clarity and consistency

Tests:

  • Add unit tests for prompt template variable application in transformSpanAttributesToPlaygroundInstance

@GeLi2001 GeLi2001 requested a review from a team as a code owner June 17, 2025 20:04
@github-project-automation github-project-automation bot moved this to 📘 Todo in phoenix Jun 17, 2025
@dosubot dosubot bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Jun 17, 2025
Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @GeLi2001 - I've reviewed your changes and they look great!

Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments

### Comment 1
<location> `app/src/pages/playground/playgroundUtils.ts:672` </location>
<code_context>
+      if (message.content && typeof message.content === "string") {
+        return {
+          ...message,
+          content: utils.format({
+            text: message.content,
+            variables: variables as Record<
+              string,
+              string | number | boolean | undefined
+            >,
+          }),
+        };
+      }
</code_context>

<issue_to_address>
No error handling for template formatting failures.

Wrap the 'utils.format' call in a try/catch block to handle possible formatting errors and prevent the function from failing unexpectedly.
</issue_to_address>

<suggested_fix>
<<<<<<< SEARCH
      if (message.content && typeof message.content === "string") {
        return {
          ...message,
          content: utils.format({
            text: message.content,
            variables: variables as Record<
              string,
              string | number | boolean | undefined
            >,
          }),
        };
      }
=======
      if (message.content && typeof message.content === "string") {
        try {
          return {
            ...message,
            content: utils.format({
              text: message.content,
              variables: variables as Record<
                string,
                string | number | boolean | undefined
              >,
            }),
          };
        } catch (error) {
          // Optionally log the error, e.g. console.error("Template formatting error:", error);
          return {
            ...message,
            // Fallback: return original content if formatting fails
            content: message.content,
            formattingError: true,
          };
        }
      }
>>>>>>> REPLACE

</suggested_fix>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@GeLi2001 GeLi2001 changed the title fix:playground-prompt-template fix: playground-prompt-template Jun 17, 2025
@GeLi2001 GeLi2001 marked this pull request as draft June 18, 2025 00:05
@GeLi2001 GeLi2001 marked this pull request as draft June 18, 2025 00:05
@GeLi2001 GeLi2001 marked this pull request as draft June 18, 2025 00:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:L This PR changes 100-499 lines, ignoring generated files.

Projects

Status: 📘 Todo

Development

Successfully merging this pull request may close these issues.

2 participants