Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@langchain/openai

Package Overview
Dependencies
Maintainers
11
Versions
70
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@langchain/openai

OpenAI integrations for LangChain.js

  • 0.3.9
  • Source
  • npm
  • Socket score

Version published
Maintainers
11
Created

What is @langchain/openai?

@langchain/openai is an npm package that provides tools and utilities for integrating OpenAI's language models into your applications. It allows you to easily interact with OpenAI's API, enabling functionalities such as text generation, conversation handling, and more.

What are @langchain/openai's main functionalities?

Text Generation

This feature allows you to generate text based on a given prompt using OpenAI's language models. The code sample demonstrates how to use the `generate` method to create text.

const { OpenAI } = require('@langchain/openai');

const openai = new OpenAI('your-api-key');

async function generateText(prompt) {
  const response = await openai.generate({
    model: 'text-davinci-003',
    prompt: prompt,
    max_tokens: 100
  });
  console.log(response.data.choices[0].text);
}

generateText('Once upon a time');

Conversation Handling

This feature allows you to handle conversations by sending a series of messages to OpenAI's conversational models. The code sample demonstrates how to use the `converse` method to manage a conversation.

const { OpenAI } = require('@langchain/openai');

const openai = new OpenAI('your-api-key');

async function handleConversation(messages) {
  const response = await openai.converse({
    model: 'gpt-3.5-turbo',
    messages: messages
  });
  console.log(response.data.choices[0].message.content);
}

const messages = [
  { role: 'system', content: 'You are a helpful assistant.' },
  { role: 'user', content: 'What is the weather like today?' }
];

handleConversation(messages);

Custom Fine-Tuning

This feature allows you to fine-tune OpenAI's models with custom training data. The code sample demonstrates how to use the `fineTune` method to train a model with specific data.

const { OpenAI } = require('@langchain/openai');

const openai = new OpenAI('your-api-key');

async function fineTuneModel(trainingData) {
  const response = await openai.fineTune({
    model: 'text-davinci-003',
    training_data: trainingData
  });
  console.log(response.data);
}

const trainingData = [
  { prompt: 'Translate the following English text to French: "Hello, world!"', completion: 'Bonjour, le monde!' }
];

fineTuneModel(trainingData);

Other packages similar to @langchain/openai

Keywords

FAQs

Package last updated on 17 Oct 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc