Skip to content

Conversation

@esuljic
Copy link
Contributor

@esuljic esuljic commented Apr 27, 2025

Add Custom Prompt Support for OpenAI and TypeChat Services

Overview

This PR adds support for a custom prompt parameter (--prompt) that allows users to provide specific instructions to the translation services. This feature is particularly useful for maintaining consistency in technical terminology and ensuring proper translation of domain-specific content.

Changes

  • Added prompt parameter to TServiceArgs interface
  • Implemented prompt support in OpenAI and TypeChat services
  • Added warning when prompt is used with unsupported services
  • Updated documentation with examples and usage instructions

Key Features

  1. Custom Instructions: Users can now provide specific translation instructions through the --prompt parameter
  2. Technical Term Preservation: Ability to specify which terms should remain untranslated
  3. Domain-Specific Context: Provide context about the application domain to improve translation quality
  4. Tone and Style Control: Specify desired tone and style for translations

Usage Examples

# Basic usage with OpenAI
attranslate --srcFile=en.json --srcLng=English --targetFile=es.json --targetLng=Spanish --service=openai --prompt="Keep technical terms like 'API', 'backend', 'frontend' in English"

# Using TypeChat with specific instructions
attranslate --srcFile=en.json --srcLng=English --targetFile=de.json --targetLng=German --service=typechat --prompt="This is a medical app. Keep terms like 'EKG', 'MRI', 'CT scan' in English. Use formal medical terminology."

Implementation Details

  • The prompt is integrated into the translation request for both OpenAI and TypeChat services
  • For OpenAI, the prompt is added as additional context in the translation request
  • For TypeChat, the prompt is included in the schema generation and translation process
  • A warning is shown when the prompt parameter is used with unsupported services

Benefits

  1. Improved Translation Quality: Better control over how technical terms and domain-specific content are handled
  2. Consistency: Ensures consistent translation of technical terms across the application
  3. Flexibility: Allows for different translation strategies based on the content type
  4. User Control: Gives users more control over the translation process

Documentation

  • Updated README.md with prompt parameter documentation
  • Added examples showing different use cases
  • Included Spanish translation of the documentation (README-es.md)

Testing

  • Verified prompt functionality with both OpenAI and TypeChat services
  • Tested warning behavior with unsupported services
  • Validated documentation examples

Notes

  • The prompt parameter is currently only supported by OpenAI and TypeChat services
  • Other services will ignore the prompt parameter and show a warning
  • The prompt should be used to provide clear, specific instructions for better results

This feature enhances the flexibility and control users have over the translation process, particularly for applications with technical or domain-specific content.

I didn't test the TypeChat implementation, only OpenAI (I am using it a lot with my projects). Please someone do a test.

@fkirc fkirc changed the title Ai prompt feat: Ai prompt Apr 28, 2025
@fkirc
Copy link
Owner

fkirc commented Apr 28, 2025

I think it is an important feature to be able to customize the prompt, thank you for the contribution!

@fkirc fkirc merged commit 4fa115b into fkirc:master Apr 28, 2025
9 checks passed
@fkirc
Copy link
Owner

fkirc commented Apr 28, 2025

I published version 2.2.0 on npm: https://www.npmjs.com/package/attranslate
I do not have time to test it right now, but please upgrade to 2.2.0 and let me know in case if there are any problems with the OpenAI-implementation.

@esuljic
Copy link
Contributor Author

esuljic commented Apr 28, 2025

Tested, works. Thanks for merging - would be great to give me a credit if possible :D

@fkirc
Copy link
Owner

fkirc commented Apr 28, 2025

Thank you, but I am not sure what kind of credits are you talking, something like mentionung your name in the Readme? 🤔

@esuljic
Copy link
Contributor Author

esuljic commented Apr 28, 2025 via email

@fkirc
Copy link
Owner

fkirc commented Apr 28, 2025

Please make a PR for this, to make it more clear what is meaned

@esuljic
Copy link
Contributor Author

esuljic commented Apr 29, 2025

#278 here it is, feel free to edit it. I made it as short as possible, you will probably have more contributors

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