Animus’s text generation capabilities let you create human-like text for a wide range of applications. This guide covers the fundamentals of generating text with our REST API.

Quickstart

To generate text with Animus, you’ll make a request to our chat completions endpoint. Here’s a basic example using direct API calls:

// Using fetch API
const response = await fetch('https://api.animusai.co/v2/chat/completions', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'Authorization': `Bearer ${process.env.ANIMUS_API_KEY}`
  },
  body: JSON.stringify({
    model: "vivian-llama3.1-70b-1.0-fp8",
    messages: [
      { role: "user", content: "What are the key features of deep learning?" }
    ]
  })
});

const data = await response.json();
console.log(data.choices[0].message.content);

Advanced Usage

Message Roles and Names

When sending messages to the chat completions API, you can use different roles to structure your conversation:

  • system: Provides guidance to the model on how to behave
  • user: Represents user inputs in the conversation
  • assistant: Represents previous responses from the model

Additionally, you can use the name parameter to give a specific identity to user or assistant messages. This is useful for multi-agent simulations or distinguishing between different participants in a conversation:

{
  "model": "vivian-llama3.1-70b-1.0-fp8",
  "messages": [
    {
      "role": "system",
      "content": "You are participating in a group discussion with users Alice and Bob."
    },
    {
      "role": "user",
      "name": "Alice",
      "content": "I think we should focus on improving user experience first."
    },
    {
      "role": "user",
      "name": "Bob",
      "content": "I disagree, I believe performance optimizations should be our priority."
    }
  ]
}

The name parameter must be a string that adheres to the following regex pattern: ^[a-zA-Z0-9_-]{1,64}$. That means it can contain alphanumeric characters, underscores, and hyphens, with a maximum length of 64 characters.

Controlling Response Format

You can control the format of the responses by providing specific instructions in the system or user messages:

{
  "model": "vivian-llama3.1-70b-1.0-fp8",
  "messages": [
    {
      "role": "system",
      "content": "You are a helpful assistant that responds in JSON format."
    },
    {
      "role": "user",
      "content": "Provide information about planets in our solar system."
    }
  ]
}

Temperature and Top P

Control the randomness and creativity of responses with these parameters:

{
  "model": "vivian-llama3.1-70b-1.0-fp8",
  "messages": [
    { "role": "user", "content": "Write a short poem about AI." }
  ],
  "temperature": 0.7,
  "top_p": 0.9
}
  • temperature: (0-2) Lower values make output more deterministic; higher values make output more random
  • top_p: (0-1) Controls diversity via nucleus sampling

Maximum Tokens

Limit the length of the response by setting a maximum token count:

{
  "model": "vivian-llama3.1-70b-1.0-fp8",
  "messages": [
    { "role": "user", "content": "Explain how neural networks work." }
  ],
  "max_tokens": 150
}

Streaming Responses

For a more interactive experience, you can stream responses as they’re generated:

const response = await fetch('https://api.animusai.co/v2/chat/completions', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'Authorization': `Bearer ${process.env.ANIMUS_API_KEY}`
  },
  body: JSON.stringify({
    model: "vivian-llama3.1-70b-1.0-fp8",
    messages: [
      { role: "user", content: "Tell me a story about a space explorer." }
    ],
    stream: true
  })
});

// Handle the stream
const reader = response.body.getReader();
const decoder = new TextDecoder("utf-8");

while (true) {
  const { done, value } = await reader.read();
  if (done) break;
  
  // Process the received chunk
  const chunk = decoder.decode(value);
  console.log(chunk);
}

Prompt Engineering Best Practices

For better results:

  1. Be specific: Provide clear instructions with examples
  2. Use system messages: Set the tone and behavior of the model
  3. Structure your prompts: Break complex tasks into smaller steps
  4. Context matters: Provide relevant background information
  5. Iterate and refine: Test different prompts and learn what works best

Common Use Cases

Animus’s text generation can be used for:

  • Content Creation: Generate articles, blog posts, or marketing copy
  • Conversational AI: Build chatbots and virtual assistants
  • Code Generation: Get help with programming tasks
  • Summarization: Condense long texts into concise summaries
  • Translation: Convert text between languages
  • Creative Writing: Generate stories, poems, or scripts

Error Handling

Implement robust error handling in your applications:

try {
  const response = await fetch('https://api.animusai.co/v2/chat/completions', {
    // request configuration
  });
  
  if (!response.ok) {
    const error = await response.json();
    console.error('API Error:', error);
    // Handle specific error types
  } else {
    const data = await response.json();
    // Process successful response
  }
} catch (error) {
  console.error('Network or parsing error:', error);
  // Handle connection or parsing issues
}

Next Steps