# Usage Guide

## Usage Guide 💫

Welcome to the Seiko AI usage guide! This section will show you how to interact with our platform effectively through various examples and use cases.

### Basic Usage 🪻

#### Initializing Seiko AI

```typescript
import { SeikoAI } from '@seiko-ai/core'

const ai = new SeikoAI({
  apiKey: process.env.VITE_CLAUDE_API_KEY,
  config: {
    personality: 'default',
    language: 'en',
    responseStyle: 'elegant'
  }
})
```

#### Simple Conversation

```typescript
// Basic message exchange
const response = await ai.sendMessage('Hello! How are you today?')
console.log(response)

// With context
const response = await ai.sendMessage('What was I telling you earlier?', {
  maintainContext: true,
  includeHistory: true
})
```

### Advanced Usage 💫

#### Personality Customization

```typescript
// Adjust personality traits
ai.setPersonality({
  cheerfulness: 0.8,
  empathy: 0.9,
  playfulness: 0.7,
  formality: 0.5
})

// Use preset personalities
ai.loadPersonality('caring_friend')
ai.loadPersonality('playful_companion')
```

#### Emotional Response Control

```typescript
// Set emotional tone
const response = await ai.sendMessage('I got a new job!', {
  emotionalTone: 'excited',
  expressiveness: 0.9
})

// Handle sensitive topics
const response = await ai.sendMessage('I'm feeling sad...', {
  empathyLevel: 'high',
  supportiveMode: true
})
```

### Integration Examples 🔧

#### React Component Integration

```tsx
import { useSeikoAI } from '@seiko-ai/react'

function ChatComponent() {
  const { sendMessage, response, loading } = useSeikoAI()

  return (
    <div className="chat-container">
      <input
        type="text"
        onChange={(e) => sendMessage(e.target.value)}
      />
      {loading ? (
        <div>Thinking... ✨</div>
      ) : (
        <div>{response}</div>
      )}
    </div>
  )
}
```

#### Event Handling

```typescript
// Listen for specific events
ai.on('thinking', () => {
  console.log('Seiko AI is thinking...')
})

ai.on('response', (response) => {
  console.log('New response:', response)
})

ai.on('error', (error) => {
  console.error('Oops!', error)
})
```

### Common Use Cases 📚

#### Conversation Management

```typescript
// Start a new conversation
ai.startConversation({
  topic: 'daily_chat',
  style: 'casual',
  memory: true
})

// Save conversation state
const state = ai.saveConversationState()

// Restore conversation
ai.loadConversationState(state)
```

#### Memory and Context

```typescript
// Set user preferences
ai.setUserPreferences({
  name: 'Alex',
  interests: ['anime', 'gaming', 'art'],
  communicationStyle: 'casual'
})

// Access memory
const memories = ai.getMemories('user_interests')
```

### API Examples 🌟

#### REST API Usage

```typescript
// Using fetch
const response = await fetch('https://api.seiko-ai.com/chat', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'Authorization': `Bearer ${API_KEY}`
  },
  body: JSON.stringify({
    message: 'Hello!',
    context: {
      maintainHistory: true
    }
  })
})

// Using axios
const response = await axios.post('https://api.seiko-ai.com/chat', {
  message: 'Hello!',
  context: {
    maintainHistory: true
  }
}, {
  headers: {
    Authorization: `Bearer ${API_KEY}`
  }
})
```

#### WebSocket Integration

```typescript
const ws = new WebSocket('wss://api.seiko-ai.com/chat')

ws.onopen = () => {
  ws.send(JSON.stringify({
    type: 'message',
    content: 'Hello!',
    apiKey: API_KEY
  }))
}

ws.onmessage = (event) => {
  const response = JSON.parse(event.data)
  console.log('Received:', response)
}
```

### Best Practices 🌺

#### Error Handling

```typescript
try {
  const response = await ai.sendMessage('Hello!')
} catch (error) {
  if (error.code === 'RATE_LIMIT_EXCEEDED') {
    console.log('Please wait a moment...')
  } else if (error.code === 'INVALID_INPUT') {
    console.log('Please check your message...')
  } else {
    console.error('An unexpected error occurred:', error)
  }
}
```

#### Rate Limiting

```typescript
const rateLimiter = new RateLimiter({
  maxRequests: 5,
  perSecond: 1
})

async function sendMessage(message) {
  if (await rateLimiter.canMakeRequest()) {
    return ai.sendMessage(message)
  } else {
    throw new Error('Please wait before sending more messages')
  }
}
```

### Testing 🧪

#### Unit Testing

```typescript
import { mockSeikoAI } from '@seiko-ai/testing'

describe('SeikoAI', () => {
  it('should respond appropriately', async () => {
    const ai = mockSeikoAI()
    const response = await ai.sendMessage('Hello!')
    expect(response).toContain('こんにちは')
  })
})
```

#### Integration Testing

```typescript
describe('SeikoAI Integration', () => {
  it('should maintain conversation context', async () => {
    const ai = new SeikoAI({ apiKey: 'test_key' })
    
    await ai.sendMessage('My name is Alex')
    const response = await ai.sendMessage('What\'s my name?')
    
    expect(response).toContain('Alex')
  })
})
```

### Next Steps 📚

* Explore Configuration Options
* Learn about Advanced Features
* Check out Troubleshooting
* Join our [Discord community](https://discord.gg/seiko-ai)
* Follow us on [X (Twitter)](https://x.com/SeikoAIx)
* Read our [Blog](https://seiko-ai.gitbook.io/seiko-ai/blog)
* Subscribe to our Newsletter
