@@ -77,49 +77,49 @@ LangChain is a popular library for building AI applications. Scaleway's Generati
7777To perform chat conversations with Langchain, first install ` langchain ` and ` @langchain/openai ` packages using your node package manager.
7878
79791 . Use the following command to install Langchain using ` npm ` (` yarn ` and ` pnpm ` are also available):
80- ``` bash
81- npm install langchain @langchain/openai
82- ```
80+ ``` bash
81+ npm install langchain @langchain/openai
82+ ```
8383
84842 . Edit your ` package.json ` file to ensure it has the ` "type": "module" ` property:
85- ``` json
86- {
87- "type" : " module" ,
88- "dependencies" : {
89- "@langchain/openai" : " ^0.4.4" ,
90- "langchain" : " ^0.3.19"
85+ ``` json
86+ {
87+ "type" : " module" ,
88+ "dependencies" : {
89+ "@langchain/openai" : " ^0.4.4" ,
90+ "langchain" : " ^0.3.19"
91+ }
9192 }
92- }
93- ```
93+ ```
9494
95953 . Create a ` main.js ` file and add the following content to it:
96- ``` js
97- import { ChatOpenAI } from " @langchain/openai" ;
98-
99- const chat = new ChatOpenAI ({
100- apiKey: " <API secret key>" ,
101- model: " llama-3.1-8b-instruct" ,
102- configuration: {
103- baseURL: " https://api.scaleway.ai/v1" ,
104- }
105- });
96+ ``` js
97+ import { ChatOpenAI } from " @langchain/openai" ;
98+
99+ const chat = new ChatOpenAI ({
100+ apiKey: " <API secret key>" ,
101+ model: " llama-3.1-8b-instruct" ,
102+ configuration: {
103+ baseURL: " https://api.scaleway.ai/v1" ,
104+ }
105+ });
106106
107- const response = await chat .invoke (" Tell me a joke" );
108- console .log (response .content );
109- ```
107+ const response = await chat .invoke (" Tell me a joke" );
108+ console .log (response .content );
109+ ```
110110
111- <Message type = " tip" >
112- Make sure to replace ` <API secret key> ` with your actual API secret key.
113- </Message >
111+ <Message type = " tip" >
112+ Make sure to replace ` <API secret key> ` with your actual API secret key.
113+ </Message >
114114
1151154 . Run ` main.js ` :
116- ``` bash
117- node main.js
118- ```
119- The model answer should display:
120- ``` bash
121- Why couldn' t the bicycle stand up by itself? Because it was two-tired.
122- ```
116+ ``` bash
117+ node main.js
118+ ```
119+ The model answer should display:
120+ ``` bash
121+ Why couldn' t the bicycle stand up by itself? Because it was two-tired.
122+ ```
123123
124124Note that other Langchain objects from OpenAI client library are also compatible, such as `OpenAI` and `OpenAIEmbeddings`.
125125
0 commit comments