Skip to content

Commit df670f2

Browse files
fpagnybene2k1RoRoJ
authored
fix(genapi): update integrating-generative-apis-with-popular-tools (#4529)
* Update integrating-generative-apis-with-popular-tools.mdx Add snippets example to configure Langchain client using Typescript. * Apply suggestions from code review Co-authored-by: Rowena Jones <[email protected]> * feat(genapi): add steps * fix(genapi): fix wording * fix(genapi): fix wording * fix(genapi): fix content --------- Co-authored-by: Benedikt Rollik <[email protected]> Co-authored-by: Rowena Jones <[email protected]> Co-authored-by: Benedikt Rollik <[email protected]>
1 parent ffe991d commit df670f2

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

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

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,62 @@ 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.
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 the `"type": "module"` property:
85+
```json
86+
{
87+
"type": "module",
88+
"dependencies": {
89+
"@langchain/openai": "^0.4.4",
90+
"langchain": "^0.3.19"
91+
}
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+
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+
});
106+
107+
const response = await chat.invoke("Tell me a joke");
108+
console.log(response.content);
109+
```
110+
111+
<Message type="tip">
112+
Make sure to replace `<API secret key>` with your actual API secret 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+
```
123+
124+
Note that other Langchain objects from OpenAI client library are also compatible, such as `OpenAI` and `OpenAIEmbeddings`.
125+
74126
## Continue Dev (AI coding assistance)
75127
76128
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)