Home Arrow Icon Knowledge base Arrow Icon Global Arrow Icon Can you provide some example code for Claude multilingual functions
    Claude API multilingual tasks Python text translation English to Spanish Spanish to English API examples


Can you provide some example code for Claude multilingual functions


Here are some examples of how to use the Claude API for multilingual tasks in Python:

```python
import os
import anthropic

# Set your API key
os.environ["ANTHROPIC_API_KEY"] = "your_api_key_here"

# Create a Claude client
client = anthropic.Anthropic()

# Translate text from English to Spanish
response = client.completions.create(
model="claude-2.1",
prompt=f"{anthropic.HUMAN_PROMPT} Please translate this text to Spanish: Hello, how are you today? {anthropic.AI_PROMPT}",
max_tokens_to_sample=200,
temperature=0.7
)
spanish_translation = response.completion
print(spanish_translation)

# Translate text from Spanish to English
response = client.completions.create(
model="claude-2.1",
prompt=f"{anthropic.HUMAN_PROMPT} Please translate this Spanish text to English: Hola,