Skip to content

Commit 27d4bcf

Browse files
committed
feat(genapi): add content
1 parent a4bf831 commit 27d4bcf

File tree

2 files changed

+162
-88
lines changed

2 files changed

+162
-88
lines changed

pages/generative-apis/how-to/query-code-models.mdx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,15 @@ Code models are AI-powered tools that can understand, generate, and fix code. Wi
100100
3. Restart your IDE after you have modified and saved the configuration file.
101101
4. Open the Command Palette in VS Code by pressing `Ctrl+Shift+P` (Windows/Linux) or `Cmd+Shift+P` (Mac) and type "Continue" to access the extension's features.
102102

103+
<Message type="tip">
104+
Refer our dedicated documentations for
105+
- [Integrating Continue Dev with Visual Studio Code](/generative-apis/reference-content/adding-ai-to-vscode-using-continue/)
106+
- [Integrating Continue Dev with IntelliJ IDEA](/generative-apis/reference-content/adding-ai-to-intellij-using-continue/)
107+
for detailed information how to integrate Continue in your favourite IDE.
108+
</Message>
109+
110+
111+
103112
### Using Continue with your IDE
104113
Continue can be used with VS Code to automate tasks, generate code, and enhance your coding experience. Here are some examples of how to use Continue with VS Code:
105114

Lines changed: 153 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -1,104 +1,159 @@
11
---
22
meta:
33
title: Integrating Scaleway Generative APIs with popular AI tools
4-
description: Learn how to integrate Scaleway's Generative APIs with popular AI tools.
4+
description: Learn how to integrate Scaleway's Generative APIs with popular AI tools to unlock the full potential of your applications.
55
content:
66
h1: Integrating Scaleway Generative APIs with popular AI tools
7-
paragraph: Learn how to integrate Scaleway's Generative APIs with popular AI tools.
7+
paragraph: Scaleway's Generative APIs provide a powerful way to integrate AI capabilities into your applications. By leveraging our APIs, you can tap into the latest advancements in natural language processing, computer vision, and more. In this guide, we'll show you how to integrate Scaleway's Generative APIs with popular AI tools like LangChain, LlamaIndex, and OpenAI.
88
tags: generative-apis, ai, language-models
9-
validation_date: 2025-02-18
10-
posted_date: 2025-02-18
9+
dates:
10+
validation: 2024-09-19
11+
posted: 2024-09-19
1112
---
1213

13-
Scaleway’s Generative APIs provide easy integration with various AI frameworks and tools. This guide outlines the configuration steps needed to integrate Scaleway's models into different environments.
14+
Scaleway's Generative APIs are designed to provide easy access to the latest AI models and techniques. Our APIs are built on top of a robust infrastructure that ensures scalability, reliability, and security. With our APIs, you can integrate AI capabilities into your applications, such as text generation, image classification, and more.
15+
16+
## Comparison of AI tools and libraries
17+
18+
The following table compares AI tools and libraries supported by Scaleway's Generative APIs:
19+
20+
| Tool/Library | Description | Use cases | Integration effort |
21+
| --- | --- | --- | --- |
22+
| [OpenAI](#openai-compatible-libraries) | Popular AI library for natural language processing | Text generation, language translation, text summarization | Low |
23+
| [LangChain](#langchain-rag-and-llm-applications) | Library for building AI applications | Inference, embeddings, document indexing and retrieval | Medium |
24+
| [LlamaIndex](#llamaindex-document-indexing-and-retrieval) | Library for indexing and retrieving documents using AI models | Document indexing and retrieval, question answering | Medium |
25+
| [Continue Dev](#continue-dev-ai-coding-assistance) | Library for AI-powered coding assistance | Code completion, code review | Low |
26+
| [Transformers (Hugging Face)](#transformers-hugging-face-integration) | Library for pre-trained models for natural language processing | Text generation, language translation, text summarization | Medium |
27+
| [cURL/Python](#api-clients-and-custom-integrations) | Direct API clients for custom integrations | Custom applications, data processing | High |
28+
29+
<Message type="note">
30+
The integration effort is subjective and may vary depending on the specific use case and requirements.
31+
</Message>
1432

1533
## OpenAI-Compatible libraries
16-
Scaleway Generative APIs follow OpenAI’s API structure, making integration straightforward.
34+
35+
Scaleway Generative APIs follow OpenAI's API structure, making integration straightforward. To get started, you'll need to install the OpenAI library and set up your API key.
1736

1837
### Configuration
19-
Set the API key and base URL in your OpenAI-compatible client:
2038

39+
To use the OpenAI library with Scaleway's Generative APIs, you'll need to set the API key and base URL in your OpenAI-compatible client:
2140
```python
2241
import openai
23-
2442
openai.api_key = "<API secret key>"
2543
openai.api_base = "https://api.scaleway.ai/v1"
26-
2744
response = openai.ChatCompletion.create(
2845
model="llama-3.1-8b-instruct",
2946
messages=[{"role": "user", "content": "Tell me a joke about AI"}]
3047
)
31-
3248
print(response["choices"][0]["message"]["content"])
3349
```
50+
<Message type="tip">
51+
Make sure to replace `<API secret key>` with your actual API key.
52+
</Message>
3453

54+
### Using OpenAI for text generation
55+
56+
To use OpenAI for text generation, you can create a `ChatCompletion` object and call the `create` method:
57+
```python
58+
response = openai.ChatCompletion.create(
59+
model="llama-3.1-8b-instruct",
60+
messages=[{"role": "user", "content": "Tell me a joke about AI"}]
61+
)
62+
print(response["choices"][0]["message"]["content"])
63+
```
3564

3665
## LangChain (RAG & LLM applications)
3766

38-
LangChain supports Scaleway models for both inference and embeddings.
67+
LangChain is a popular library for building AI applications. Scaleway's Generative APIs support LangChain for both inference and embeddings.
3968

4069
### Configuration
41-
1. Install required dependencies:
42-
```bash
43-
pip install langchain langchain_openai langchain_postgres psycopg2
44-
```
45-
2. Set up the API connection:
46-
```python
47-
from langchain_openai import OpenAIEmbeddings, ChatOpenAI
48-
import os
49-
50-
os.environ["OPENAI_API_KEY"] = "<API secret key>"
51-
os.environ["OPENAI_API_BASE"] = "https://api.scaleway.ai/v1"
52-
53-
llm = ChatOpenAI(model="llama-3.1-8b-instruct")
54-
embeddings = OpenAIEmbeddings(model="bge-multilingual-gemma2")
55-
```
56-
3. Use a vector store for retrieval:
57-
```python
58-
from langchain_postgres import PGVector
59-
60-
connection_string = "postgresql+psycopg2://user:password@host:port/dbname"
61-
vector_store = PGVector(connection=connection_string, embeddings=embeddings)
62-
```
6370

71+
To use LangChain with Scaleway's Generative APIs, you'll need to install the required dependencies:
72+
```bash
73+
pip install langchain langchain_openai langchain_postgres psycopg2
74+
```
75+
Next, set up the API connection:
76+
```python
77+
from langchain_openai import OpenAIEmbeddings, ChatOpenAI
78+
import os
79+
os.environ["OPENAI_API_KEY"] = "<API secret key>"
80+
os.environ["OPENAI_API_BASE"] = "https://api.scaleway.ai/v1"
81+
llm = ChatOpenAI(model="llama-3.1-8b-instruct")
82+
embeddings = OpenAIEmbeddings(model="bge-multilingual-gemma2")
83+
```
84+
<Message type="tip">
85+
Make sure to replace `<API secret key>` with your actual API key.
86+
</Message>
87+
88+
### Using LangChain for Inference
89+
90+
To use LangChain for inference, you can create a `ChatOpenAI` object and call the `ask` method:
91+
```python
92+
response = llm.ask("What is the capital of France?")
93+
print(response)
94+
```
95+
### Using LangChain for Embeddings
96+
97+
To use LangChain for embeddings, you can create an `OpenAIEmbeddings` object and call the `compute_embeddings` method:
98+
```python
99+
embeddings = OpenAIEmbeddings(model="bge-multilingual-gemma2")
100+
text = "This is an example sentence."
101+
embedding = embeddings.compute_embeddings(text)
102+
print(embedding)
103+
```
64104
## LlamaIndex (document indexing & retrieval)
65105

66-
LlamaIndex enables easy document retrieval using Scaleway’s models.
106+
LlamaIndex is a library for indexing and retrieving documents using AI models. Scaleway's Generative APIs support LlamaIndex for document indexing and retrieval.
67107

68108
### Configuration
69-
1. Install dependencies:
70-
```bash
71-
pip install llama-index
72-
```
73-
2. Set up the embedding model:
74-
```python
75-
from llama_index.embeddings.openai import OpenAIEmbedding
76-
77-
embed_model = OpenAIEmbedding(
78-
api_key="<API secret key>",
79-
api_base="https://api.scaleway.ai/v1",
80-
model="bge-multilingual-gemma2"
81-
)
82-
```
83-
3. Index and query documents:
84-
```python
85-
from llama_index import VectorStoreIndex, SimpleDirectoryReader
86-
87-
documents = SimpleDirectoryReader("data").load_data()
88-
index = VectorStoreIndex.from_documents(documents, embed_model=embed_model)
89-
query_engine = index.as_query_engine()
90-
91-
response = query_engine.query("Summarize this document")
92-
print(response)
93-
```
109+
110+
To use LlamaIndex with Scaleway's Generative APIs, you'll need to install the required dependencies:
111+
```bash
112+
pip install llama-index
113+
```
114+
Next, set up the embedding model:
115+
```python
116+
from llama_index.embeddings.openai import OpenAIEmbedding
117+
embed_model = OpenAIEmbedding(
118+
api_key="<API secret key>",
119+
api_base="https://api.scaleway.ai/v1",
120+
model="bge-multilingual-gemma2"
121+
)
122+
```
123+
<Message type="tip">
124+
Make sure to replace `<API secret key>` with your actual API key.
125+
</Message>
126+
127+
### Indexing documents
128+
129+
To index documents using LlamaIndex, you'll need to create a `VectorStoreIndex` object and call the `add_documents` method:
130+
```python
131+
from llama_index import VectorStoreIndex, SimpleDirectoryReader
132+
documents = SimpleDirectoryReader("data").load_data()
133+
index = VectorStoreIndex.from_documents(documents, embed_model=embed_model)
134+
```
135+
### Retrieving documents
136+
137+
To retrieve documents using LlamaIndex, you can call the `query` method on the `VectorStoreIndex` object:
138+
```python
139+
query_engine = index.as_query_engine()
140+
response = query_engine.query("Summarize this document")
141+
print(response)
142+
```
94143

95144
## Continue Dev (AI coding assistance)
96145

97-
Continue Dev allows configuring Scaleway models for code completion.
146+
Continue Dev is a library that provides AI-powered coding assistance. Scaleway's Generative APIs support Continue Dev for code completion and more.
147+
148+
<Message type="tip">
149+
Refer our dedicated documentations for
150+
- [Integrating Continue Dev with Visual Studio Code](/generative-apis/reference-content/adding-ai-to-vscode-using-continue/)
151+
- [Integrating Continue Dev with IntelliJ IDEA](/generative-apis/reference-content/adding-ai-to-intellij-using-continue/)
152+
</Message>
98153

99154
### Configuration
100-
Modify `continue.json` to add Scaleway’s API:
101155

156+
To use Continue Dev with Scaleway's Generative APIs, you'll need to modify the `continue.json` file to add Scaleway's API:
102157
```json
103158
{
104159
"models": [
@@ -116,39 +171,44 @@ Modify `continue.json` to add Scaleway’s API:
116171
}
117172
}
118173
```
119-
120-
---
174+
<Message type="tip">
175+
Make sure to replace `<API secret key>` with your actual API key.
176+
</Message>
121177

122178
## Transformers (Hugging Face integration)
123179

124-
Hugging Faces `transformers` library can send requests to Scaleway-hosted models.
180+
Hugging Face's `transformers` library provides a range of pre-trained models for natural language processing. Scaleway's Generative APIs support Hugging Face integration for text generation and more.
125181

126182
### Configuration
127-
1. Install dependencies:
128-
```bash
129-
pip install transformers requests
130-
```
131-
2. Use a custom API endpoint:
132-
```python
133-
from transformers import pipeline
134-
135-
generator = pipeline(
136-
"text-generation",
137-
model="llama-3.1-8b-instruct",
138-
tokenizer="meta-llama/Llama-3-8b",
139-
api_base="https://api.scaleway.ai/v1",
140-
api_key="<API secret key>"
141-
)
142-
143-
print(generator("Write a short poem about the ocean"))
144-
```
145183

146-
---
184+
To use Hugging Face with Scaleway's Generative APIs, you'll need to install the `transformers` library and set up your API key:
185+
```python
186+
from transformers import pipeline
187+
generator = pipeline(
188+
"text-generation",
189+
model="llama-3.1-8b-instruct",
190+
tokenizer="meta-llama/Llama-3-8b",
191+
api_base="https://api.scaleway.ai/v1",
192+
api_key="<API secret key>"
193+
)
194+
```
195+
<Message type="tip">
196+
Make sure to replace `<API secret key>` with your actual API key.
197+
</Message>
198+
199+
### Using Hugging Face for text generation
147200

201+
To use Hugging Face for text generation, you can call the `generator` function:
202+
```python
203+
print(generator("Write a short poem about the ocean"))
204+
```
148205
## API clients & custom integrations
149-
You can interact with Scaleway’s Generative APIs directly using any HTTP client.
206+
207+
You can interact with Scaleway's Generative APIs directly using any HTTP client.
150208

151209
### cURL example
210+
211+
To use cURL with Scaleway's Generative APIs, you can use the following command:
152212
```bash
153213
curl https://api.scaleway.ai/v1/chat/completions \
154214
-H "Authorization: Bearer <API secret key>" \
@@ -158,21 +218,26 @@ curl https://api.scaleway.ai/v1/chat/completions \
158218
"messages": [{"role": "user", "content": "What is quantum computing?"}]
159219
}'
160220
```
221+
<Message type="tip">
222+
Make sure to replace `<API secret key>` with your actual API key.
223+
</Message>
161224

162225
### Python example
163-
```python
164-
import requestsMe
165226

227+
To use Python with Scaleway's Generative APIs, you can use the following code:
228+
```python
229+
import requests
166230
headers = {
167231
"Authorization": "Bearer <API secret key>",
168232
"Content-Type": "application/json"
169233
}
170-
171234
data = {
172235
"model": "llama-3.1-8b-instruct",
173236
"messages": [{"role": "user", "content": "Explain black holes"}]
174237
}
175-
176238
response = requests.post("https://api.scaleway.ai/v1/chat/completions", json=data, headers=headers)
177239
print(response.json()["choices"][0]["message"]["content"])
178240
```
241+
<Message type="tip">
242+
Make sure to replace `<API secret key>` with your actual API key.
243+
</Message>

0 commit comments

Comments
 (0)