Skip to content

Commit

Permalink
feat(translator): add source language detected automatically if no la…
Browse files Browse the repository at this point in the history
…ng provided
  • Loading branch information
snowyu committed Aug 24, 2024
1 parent e4216f6 commit cfcc24c
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion lib/translator.ai.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,15 @@ type: lib
version: 0.1.0
name: "Translator"
description: |-
translate the content to the target language.
Translate the content or a file to the target language.
It can be used in prompt. eg, `Translate: @translator(file='document.md', target='English')`
Or, run it directly:
```bash
# `no-chats` means do not save this into chat history
$ai run --no-chats -f translator "{content:'我爱我的祖国和故乡.', target: 'English'}"
````
tag:
- translate
- translator
Expand Down Expand Up @@ -52,6 +60,10 @@ parameters:
- $if: "this.content"
then:
# For API mode.
- $if: "!this.lang || this.lang === 'auto'"
then:
$set:
lang: "?=this.$detectLang(content.slice(0, 120))"
- user: |-
Output high-quality translation result before the completion delimiter "{{completion_delimiter}}".
{%- if content.length > 50 -%}
Expand Down

0 comments on commit cfcc24c

Please sign in to comment.