openai-client.ts 356 B

12345678910111213141516171819
  1. import { OpenAI } from 'langchain/llms';
  2. if (!process.env.OPENAI_API_KEY) {
  3. throw new Error('Missing OpenAI Credentials');
  4. }
  5. export const openai = new OpenAI({
  6. temperature: 0,
  7. });
  8. export const openaiStream = new OpenAI({
  9. temperature: 0,
  10. streaming: true,
  11. callbackManager: {
  12. handleNewToken(token) {
  13. console.log(token);
  14. },
  15. },
  16. });