Skip to content

Instantly share code, notes, and snippets.

@pigri
Created October 30, 2024 14:26
Show Gist options
  • Save pigri/66ce0876d620503488db2f6c9828031e to your computer and use it in GitHub Desktop.
Save pigri/66ce0876d620503488db2f6c9828031e to your computer and use it in GitHub Desktop.
MockAI Readme

MockAI service

This is a mock service for multiple AI services.

Documentation

Documentation

OpenAI API

Supported endpoints:

Example code

import OpenAI from 'openai';

const openAIClient = new OpenAI({
  baseURL: 'https://mockai.openshield.ai/openai/v1',
  apiKey: '',
});

async function main() {
  // @ts-ignore
  const completion = await openShiedClient.chat.completions.create({
    stream: true,
    streamDelay: 5000,
    model: 'gpt-4',
    messages: [
      { role: 'system', content: 'You are a helpful assistant.' },
      { role: 'user', content: 'What is the meaning of life?' },
    ],
  });
  console.log(JSON.stringify(completion, null, 2));

  for await (const part of completion) {
    process.stdout.write(part.choices[0]?.delta?.content || '');
  }
}

main().then(() => console.log('done'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment