Skip to content

Conversation

gustavocidornelas
Copy link
Contributor

…callback handler interface

Summary

  • Introduces the OpenlayerHandler, which implements the LangChain callback handler interface.
  • To use the callback handler, simply set the environment variables (OPENAI_API_KEY, OPENLAYER_API_KEY, OPENLAYER_INFERENCE_PIPELINE_ID) and:
import { HumanMessage } from '@langchain/core/messages';
import { ChatOpenAI } from '@langchain/openai';
import { OpenlayerHandler } from 'openlayer/integrations/langchainCallback';

async function main() {
  const handler = new OpenlayerHandler();

  const model = new ChatOpenAI({
    model: 'gpt-3.5-turbo',
    callbacks: [handler],
  });

  const response = await model.invoke([new HumanMessage({ content: "What's up?" })]);
  return response;
}

main().catch(console.error);

@gustavocidornelas gustavocidornelas merged commit 16af5f9 into main Sep 24, 2024
2 checks passed
@gustavocidornelas gustavocidornelas deleted the cid/langchain-callback-handler branch September 24, 2024 12:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants