langchain_openai 0.4.0+1 copy "langchain_openai: ^0.4.0+1" to clipboard
langchain_openai: ^0.4.0+1 copied to clipboard

LangChain.dart integration module for OpenAI (GPT-3, GPT-4, Functions, etc.).

example/langchain_openai_example.dart

// ignore_for_file: avoid_print, unused_element
import 'dart:io';

import 'package:langchain/langchain.dart';
import 'package:langchain_openai/langchain_openai.dart';

void main() async {
  // Uncomment the example you want to run:
  await _example1();
  // await _example2();
}

/// The most basic building block of LangChain is calling an LLM on some input.
Future<void> _example1() async {
  final openaiApiKey = Platform.environment['OPENAI_API_KEY'];
  final openai = OpenAI(
    apiKey: openaiApiKey,
    defaultOptions: const OpenAIOptions(temperature: 0.9),
  );
  final result = await openai('Tell me a joke');
  print(result);
}

/// The most frequent use case is to create a chat-bot.
/// This is the most basic one.
Future<void> _example2() async {
  final openaiApiKey = Platform.environment['OPENAI_API_KEY'];
  final chat = ChatOpenAI(
    apiKey: openaiApiKey,
    defaultOptions: const ChatOpenAIOptions(
      temperature: 0,
    ),
  );

  while (true) {
    stdout.write('> ');
    final usrMsg = ChatMessage.humanText(stdin.readLineSync() ?? '');
    final aiMsg = await chat([usrMsg]);
    print(aiMsg.content);
  }
}
20
likes
0
pub points
91%
popularity

Publisher

verified publisherlangchaindart.dev

LangChain.dart integration module for OpenAI (GPT-3, GPT-4, Functions, etc.).

Homepage
Repository (GitHub)
View/report issues

Topics

#ai #nlp #llms #langchain #gpt

Documentation

Documentation

License

unknown (license)

Dependencies

collection, http, langchain, langchain_tiktoken, meta, openai_dart, uuid

More

Packages that depend on langchain_openai