You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: pages/generative-apis/reference-content/integrating-generative-apis-with-popular-tools.mdx
+45-43Lines changed: 45 additions & 43 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -74,50 +74,52 @@ LangChain is a popular library for building AI applications. Scaleway's Generati
74
74
75
75
### Javascript (Typescript)
76
76
77
-
To perform chat conversations with Langchain, first install `langchain` and `@langchain/openai` packages using your node package manager. Here is an example with `npm` (`yarn` and `pnpm` are also available):
78
-
```bash
79
-
npm install langchain @langchain/openai
80
-
```
81
-
82
-
Then, edit your `package.json` file to ensure it has `"type": "module"` property:
83
-
```json
84
-
{
85
-
"type": "module",
86
-
"dependencies": {
87
-
"@langchain/openai": "^0.4.4",
88
-
"langchain": "^0.3.19"
89
-
}
90
-
}
91
-
```
92
-
93
-
Create a `main.js` file and add the following content to it:
94
-
```js
95
-
import { ChatOpenAI } from"@langchain/openai";
96
-
97
-
constchat=newChatOpenAI({
98
-
apiKey:"<API secret key>",
99
-
model:"llama-3.1-8b-instruct",
100
-
configuration: {
101
-
baseURL:"https://api.scaleway.ai/v1",
77
+
To perform chat conversations with Langchain, first install `langchain` and `@langchain/openai` packages using your node package manager.
78
+
79
+
1. Use the following command to install Langchain using `npm` (`yarn` and `pnpm` are also available):
80
+
```bash
81
+
npm install langchain @langchain/openai
82
+
```
83
+
84
+
2. Edit your `package.json` file to ensure it has `"type": "module"` property:
85
+
```json
86
+
{
87
+
"type": "module",
88
+
"dependencies": {
89
+
"@langchain/openai": "^0.4.4",
90
+
"langchain": "^0.3.19"
102
91
}
103
-
});
104
-
105
-
constresponse=awaitchat.invoke("Tell me a joke");
106
-
console.log(response.content);
107
-
```
108
-
109
-
<Messagetype="tip">
110
-
Make sure to replace `<API secret key>` with your actual API key.
111
-
</Message>
112
-
113
-
Run `main.js`:
114
-
```bash
115
-
node main.js
116
-
```
117
-
The model answer should display:
118
-
```bash
119
-
Why couldn't the bicycle stand up by itself? Because it was two-tired.
120
-
```
92
+
}
93
+
```
94
+
95
+
3. Create a `main.js` file and add the following content to it:
96
+
```js
97
+
import { ChatOpenAI } from"@langchain/openai";
98
+
99
+
constchat=newChatOpenAI({
100
+
apiKey:"<API secret key>",
101
+
model:"llama-3.1-8b-instruct",
102
+
configuration: {
103
+
baseURL:"https://api.scaleway.ai/v1",
104
+
}
105
+
});
106
+
107
+
constresponse=awaitchat.invoke("Tell me a joke");
108
+
console.log(response.content);
109
+
```
110
+
111
+
<Messagetype="tip">
112
+
Make sure to replace `<API secret key>` with your actual API key.
113
+
</Message>
114
+
115
+
4. 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
+
```
121
123
122
124
Note that other Langchain objects from OpenAI client library are also compatible, such as `OpenAI` and `OpenAIEmbeddings`.
0 commit comments