Skip to content

Commit c1e732c

Browse files
authored
Update integrating-generative-apis-with-popular-tools.mdx
Add snippets example to configure Langchain client using Typescript.
1 parent bf20d08 commit c1e732c

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

pages/generative-apis/reference-content/integrating-generative-apis-with-popular-tools.mdx

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,60 @@ print(response.choices[0].message.content)
6767

6868
LangChain is a popular library for building AI applications. Scaleway's Generative APIs support LangChain for both inference and embeddings.
6969

70+
### Python
7071
<Message type="tip">
7172
Refer to our dedicated documentation for [implementing Retrieval-Augmented Generation (RAG) with LangChain and Scaleway Generative APIs](/tutorials/how-to-implement-rag-generativeapis/)
7273
</Message>
7374

75+
### Javascript (Typescript)
76+
77+
To perform chat conversations with langchain, first install `langchain` and `@langchain/openai` packages using your node package manager. Here is the 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+
const chat = new ChatOpenAI({
98+
apiKey: "<API secret key>",
99+
model: "llama-3.1-8b-instruct",
100+
configuration: {
101+
baseURL: "https://api.scaleway.ai/v1",
102+
}
103+
});
104+
105+
const response = await chat.invoke("Tell me a joke");
106+
console.log(response.content);
107+
```
108+
109+
<Message type="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+
```
121+
122+
Note that other Langchain objects from OpenAI client library are also compatible, such as `OpenAI` and `OpenAIEmbeddings`.
123+
74124
## Continue Dev (AI coding assistance)
75125
76126
Continue Dev is a library that provides AI-powered coding assistance. Scaleway's Generative APIs support Continue Dev for code completion and more.

0 commit comments

Comments
 (0)