Together AI Integration
Learn how to use Together AI's powerful models with Airtrain.
Basic Chat
Here's how to use Together AI's chat models:
from airtrain.integrations.together.skills import TogetherAIChatSkill, TogetherAIInput
# Initialize the skill
skill = TogetherAIChatSkill()
# Create input
input_data = TogetherAIInput(
user_input="Explain quantum computing in simple terms.",
system_prompt="You are a helpful teacher who explains complex topics simply.",
model="togethercomputer/llama-2-70b",
temperature=0.7,
max_tokens=1024
)
# Get response
result = skill.process(input_data)
print(result.response)
print(f"Model Used: {result.used_model}")
print(f"Usage Statistics: {result.usage}")
Reranking Documents
Together AI provides powerful reranking capabilities. Here's how to use them:
from airtrain.integrations.together.rerank_skill import TogetherAIRerankSkill, TogetherAIRerankInput
# Initialize the rerank skill
skill = TogetherAIRerankSkill()
# Example documents
query = "What are the health benefits of exercise?"
documents = [
"Regular exercise improves cardiovascular health and reduces heart disease risk.",
"A balanced diet is essential for maintaining good health.",
"Exercise helps maintain mental health and reduce stress.",
"Getting enough sleep is crucial for overall well-being."
]
# Create input
rerank_input = TogetherAIRerankInput(
query=query,
documents=documents,
top_n=2
)
# Get ranked results
result = skill.process(rerank_input)
for doc in result.results:
print(f"Score: {doc.relevance_score:.4f}")
print(f"Document: {doc.document}")
print("-" * 50)