官方 LangChain 集成

FluentC LangChain 工具

用于将FluentC AI翻译API与LangChain集成的官方Python插件。 通过兼容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 工具

FluentC 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密钥,安装插件,并开始构建多语言自动化工作流程。