File size: 421 Bytes
136f9cf
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import { ChatOpenAI } from "@langchain/openai";

export const ChatHFInference = ({
  modelName,
  apiKey
}: {
  modelName: string;
  apiKey: string;
}) => {
  if (!apiKey) {
    throw new Error("Hugging Face API token is required");
  }
  
  return new ChatOpenAI(
    {
      model: modelName,
      apiKey: apiKey,
      configuration: {
        baseURL: "https://api-inference.huggingface.co/v1/"
      }
    },
  );
}