Skip to content

Commit

Permalink
feat: add translator lib
Browse files Browse the repository at this point in the history
  • Loading branch information
snowyu committed Aug 22, 2024
1 parent 801d683 commit cb8d54f
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions lib/translator.ai.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
---
type: lib
version: 0.1.0
name: "Translator"
description: |-
translate the content to the target language.
tag:
- translate
- translator
- lib
# Below is the input/output configuration
input: # the input items
# Language of the content to be translated, default is "auto" for automatic detection
- lang
# Required, the content to be translated
- content: {required: true}
# Required, Target language
- target: {required: true}
output:
type: "object"
properties:
target_text:
type: "string"
source_text:
type: "string"
source_lang:
type: "string"
target_lang:
type: "string"
required: ["target_text", "source_text", "source_lang", "target_lang"]
# Set the default value for the content and target input
content: "I love my motherland and my hometown."
target: "Chinese"
completion_delimiter: "<|COMPLETE|>"
# Optional configuration
parameters:
# Using the parameters below will enforce JSON output format, ensuring the ai always outputs correct JSON format.
# response_format:
# type: "json"
# autoRunLLMIfPromptAvailable: false
---
# Below is the script content
- system: |-
You are the best translator in the world.
- $if: "this.content"
then:
# For API mode.
- user: |-
Output high-quality translation result before the completion delimiter "{{completion_delimiter}}".
Translate the following content {% if lang %}from {{lang}} {% endif %}to {{target}}.
---
{{content}}
- --- # First dialogue start and this will hide the above messages from output
- assistant: "[[trans]]" # Return the last instruction's result always. So no need to `$ret: "?=this.prompt.trans"`
else:
# For multi-turn conversation in interactive mode.
- ---
- assistant: "I am the best translator in the world, what can I help you?"

0 comments on commit cb8d54f

Please sign in to comment.