Skip to content

Conversation

@wojtekPi
Copy link

Description:

This PR adds support for specifying an environment field when creating prompts in the Braintrust SDK. This allows users to assign prompts to specific environments (e.g., "production", "staging") during creation.

Changes Made:

JavaScript/TypeScript:

  • Added environment?: string to BaseFnOpts in framework-types.ts and framework2.ts
  • Updated CodePrompt class to store and serialize environment data
  • Modified FunctionEvent interface to include environment in API payloads
  • Updated toFunctionDefinition() to include environment in API calls
  • Modified upload.ts to pass environment through the upload pipeline
  • Added comprehensive tests for environment support in framework.test.ts

Python:

  • Added environment: Optional[str] = None to CodePrompt dataclass
  • Updated PromptBuilder.create() method with environment parameter in all overloads
  • Modified to_function_definition() to include environment in serialization
  • Updated docstring to document the environment parameter

Usage Example:

const project = braintrust.projects.create({ name: 'my-project' });
project.prompts.create({
    slug: 'my-prompt',
    name: 'My Prompt',
    model: 'gpt-4o',
    messages: [...],
    environment: 'production',  // New parameter
    ifExists: "replace",
});

Testing:

  • All existing tests pass
  • New tests verify environment storage and serialization
  • Both JS and Python SDKs support the feature

This addresses issue #1051 by allowing users to set environment during prompt creation, similar to how metadata is currently supported.

- Add environment field to BaseFnOpts and CodePrompt
- Update serialization to include environment in API calls
- Add comprehensive tests for environment support
- Support environment in both JS and Python SDKs
@CLowbrow
Copy link
Contributor

This will pass the parameter, but were you able to push a prompt created like this and get it to show up in the UI with the correct environment when you pushed it? I don't think that functionality exists currently (but I could be wrong).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants