官方 LangChain 集成

流利C LangChain 工具

官方 Python 插件,用于将 FluentC AI 翻译 API 与 LangChain 集成。 啟用即時同批次翻譯、語言偵測同工作輪詢,透過兼容LangChain嘅工具。

LangChain 整合功能

实时同批翻译

喺大內容量嘅情況下,揀即時翻譯定係批次處理。

語言偵測

自動偵測輸入內容嘅語言,並提供信心評分。

動態語言選擇

下拉菜單填充了你API密鑰啟用的語言。

格式支援

无缝处理纯文本同埋HTML内容。

錯誤處理

全面錯誤處理,支援繼續失敗。

工作流程整合

无缝集成到任何N8N自动化工作流程中。

需要FluentC API密钥

要使用 FluentC LangChain 工具,您需要一個有效的 FluentC API 密钥並且擁有有效的訂閱。 API 密钥提供对超过140种语言和实时翻译功能的访问。

立即注册

安装 设置

包裹安装

安装 FluentC LangChain 包:
# Install via pip
pip install fluentc-langchain-tool

# Or with requirements.txt
echo "fluentc-langchain-tool" >> requirements.txt
pip install -r requirements.txt
需要 Python 3.7 及以上版本同 LangChain 框架。

認證設置

配置你的 FluentC API 密钥:

from fluentc_langchain_tool import
FluentCTranslationTool

# Initialize with API key
tool = FluentCTranslationTool( api_key="your-fluentc-api-key")

可用 LangChain 工具

流利C LangChain 工具类

工具类别

目的

FluentCTranslationTool

实时或批量翻译提交

FluentCLanguageDetectorTool

检测输入的源语言

FluentCTranslationStatusTool

检查批量翻译任务的状态

FluentCResultsTool

批次作业翻译结果的投票

FluentCBatchTranslationTool

一次性批量提交 + 轮询

用法 例子

  • 实时翻译
  • 批次翻译
  • 狀態檢查
  • LangChain 代理
使用 FluentC LangChain 工具进行实时翻译
				
					from fluentc_langchain_tool import FluentCTranslationTool

# Initialize the translation tool
tool = FluentCTranslationTool(api_key="your-api-key")

# Perform real-time translation
response = tool.run({
    "text": "Hello, world!",
    "target_language": "fr",
    "source_language": "en",
    "mode": "realtime"
})

print(response)  # Output: "Bonjour, le monde !"

# Translation with auto-detection
response = tool.run({
    "text": "¿Cómo estás?",
    "target_language": "en",
    "mode": "realtime"
})

print(response)  # Output: "How are you?"
print("Detected source language:", response.get('detected_language', 'Unknown'))
				
			
处理大量内容的批量翻译与自动轮询
				
					from fluentc_langchain_tool import FluentCBatchTranslationTool

# Initialize batch translation tool
tool = FluentCBatchTranslationTool(api_key="your-api-key")

# Translate large HTML content
large_html = """
<html>
<head><title>Welcome</title></head>
<body data-rsssl=1>
    <h1>Hello, batch world!</h1>
    <p>This is a large document that needs translation.</p>
    <p>It contains multiple paragraphs and HTML structure.</p>
</body>
</html>
"""

# Submit and automatically poll for results
result = tool.run({
    "text": large_html,
    "target_language": "de",
    "source_language": "en"
})

print("Translated HTML:")
print(result)  # Final translated output after polling

# The tool automatically:
# 1. Submits the batch job
# 2. Polls for completion using estimated_wait_seconds
# 3. Returns the final translation result
				
			
查查批量翻译任务的状态:
				
					from fluentc_langchain_tool import (
    FluentCTranslationTool, 
    FluentCTranslationStatusTool
)

# Initialize tools
translation_tool = FluentCTranslationTool(api_key="your-api-key")
status_tool = FluentCTranslationStatusTool(api_key="your-api-key")

# Submit a batch translation job
job_response = translation_tool.run({
    "text": "Large document for batch processing...",
    "target_language": "es",
    "mode": "batch"
})

job_id = job_response.get('job_id')
print(f"Batch job submitted: {job_id}")

# Check job status
status_response = status_tool.run({
    "job_id": job_id
})

print(f"Job status: {status_response}")

# Status responses include:
# - "processing": Job is still running
# - "complete": Translation finished
# - "failed": Job encountered an error
# - estimated_wait_seconds: Recommended polling interval
				
			
将 FluentC 工具与 LangChain 代理集成以实现复杂工作流程:
				
					from langchain.agents import initialize_agent, Tool
from langchain.llms import OpenAI
from fluentc_langchain_tool import (
    FluentCTranslationTool,
    FluentCBatchTranslationTool,
    FluentCLanguageDetectorTool,
    FluentCTranslationStatusTool
)

# Initialize FluentC tools
api_key = "your-fluentc-api-key"
translation_tool = FluentCTranslationTool(api_key)
batch_tool = FluentCBatchTranslationTool(api_key)
detector_tool = FluentCLanguageDetectorTool(api_key)
status_tool = FluentCTranslationStatusTool(api_key)

# Create LangChain agent with FluentC tools
agent = initialize_agent(
    tools=[
        Tool.from_function(
            func=translation_tool.run,
            name="FluentC_Translation",
            description="Translate text in real-time or batch mode"
        ),
        Tool.from_function(
            func=batch_tool.run,
            name="FluentC_Batch_Translation",
            description="Translate large content with auto-polling"
        ),
        Tool.from_function(
            func=detector_tool.run,
            name="FluentC_Language_Detection",
            description="Detect language of input text"
        ),
        Tool.from_function(
            func=status_tool.run,
            name="FluentC_Status_Check",
            description="Check batch translation job status"
        )
    ],
    llm=OpenAI(temperature=0),
    agent="zero-shot-react-description",
    verbose=True
)

# Example agent interactions
responses = [
    "Translate 'Hello world' from English to German using FluentC.",
    "Detect the language of 'Bonjour tout le monde' and translate it to Spanish.",
    "Translate this large HTML document to French using batch processing."
]

for query in responses:
    print(f"\nQuery: {query}")
    result = agent.run(query)
    print(f"Result: {result}")
				
			

准备将翻译添加到您的N8N工作流程中吗?

今日就开始使用FluentC的N8N集成。 创建你的API密钥,安装插件,并开始构建多语言自动化工作流程。