From c0e1b2df61473e2db70b77f8d65b4a95a19cafe6 Mon Sep 17 00:00:00 2001 From: navyblueglove Date: Wed, 30 Apr 2025 18:58:37 +0200 Subject: [PATCH 1/8] docs(genapi): add a function calling's langchain integration and add precision in the bolt.diy integration using GenAPIs --- ...ing-generative-apis-with-popular-tools.mdx | 72 ++++++++++++++++++- 1 file changed, 69 insertions(+), 3 deletions(-) diff --git a/pages/generative-apis/reference-content/integrating-generative-apis-with-popular-tools.mdx b/pages/generative-apis/reference-content/integrating-generative-apis-with-popular-tools.mdx index fad22b3f8f..e33596d98b 100644 --- a/pages/generative-apis/reference-content/integrating-generative-apis-with-popular-tools.mdx +++ b/pages/generative-apis/reference-content/integrating-generative-apis-with-popular-tools.mdx @@ -71,13 +71,75 @@ print(response.choices[0].message.content) LangChain is a popular library for building AI applications. Scaleway's Generative APIs support LangChain for both inference and embeddings. ### Python + +#### Function calling + +1. Install LangChain and his dependencies. + ```bash + pip install 'langchain>=0.3.24' + pip install 'langchain-core>=0.3.55' + pip install 'langchain-openai>=0.3.14' + pip install 'langchain-text-splitters>=0.3.8' + ``` +2. Create a file `tools.py` and add the following code to it to import and create the tools examples: + ```Python + from langchain_core.messages import HumanMessage + from langchain.chat_models import init_chat_model + from langchain_core.tools import tool + + + @tool + def add(a: int, b: int) -> int: + """Adds a and b.""" + return a + b + + + @tool + def multiply(a: int, b: int) -> int: + """Multiplies a and b.""" + return a * b + + + tools = [add, multiply] + ``` +3. You can configure the `init_chat_model` function to use Scaleway's Generative APIs. + ```Python + llm = init_chat_model("mistral-small-3.1-24b-instruct-2503", model_provider="openai", base_url="https://api.scaleway.ai/v1") + ``` +4. Everything is now set up, you can use the `llm` object and the `tools` list to generate a response to a query with the following code: + ```python + query = "What is 3 * 12?" + # You can also try the following query: + # query = "What is 42 + 4?" + + messages = [HumanMessage(query)] # We initialize the messages list with the user's query. + + ai_msg = llm_with_tools.invoke(messages) # We generate a response to the query. + messages.append(ai_msg) # We append the response to the messages list. + + for tool_call in ai_msg.tool_calls: + selected_tool = {"add": add, "multiply": multiply}[tool_call["name"].lower()] # Depending on the tool name, we select the appropriate tool. + tool_msg = selected_tool.invoke(tool_call) # We invoke the selected tool with the tool call. + messages.append(tool_msg) # We append the tool's response to the messages list. + + print(llm_with_tools.invoke(messages).content) # We print the content of the final response. + ``` +5. Finally, run the `tools.py`: + ```bash + python tools.py + ``` + The response should display the result of the calculation: + ```bash + The result of 3 * 12 is 36. + ``` + Refer to our dedicated documentation for [implementing Retrieval-Augmented Generation (RAG) with LangChain and Scaleway Generative APIs](/tutorials/how-to-implement-rag-generativeapis/) ## LlamaIndex (advanced RAG applications) -LlamaIndex is an open-source framework for building Large Language Models (LLMs) based applications, especially optimizing RAG (Retrieval Augmented Generation) pipelines. +LlamaIndex is an open-source framework for building Large Language Models (LLMs) based applications, especially optimizing RAG (Retrieval Augmented Generation) pipelines. 1. Install the required dependencies to use the LlamaIndex framework with Scaleway's Generative APIs: ```bash pip install llama-index-llms-openai-like @@ -197,7 +259,7 @@ Chatbox AI is a powerful AI client and smart assistant, compatible with Scaleway ## Bolt.diy (code generation) -Bolt.diy is a software enabling users to create web applications from the prompt. +Bolt.diy is a software enabling users to create web applications from the prompt. 1. Install and launch Bolt.diy locally. Follow the setup instructions provided in the [Bolt.diy GitHub repository](https://github.com/stackblitz-labs/bolt.diy?tab=readme-ov-file#setup). 2. Once Bolt.diy is running, open the interface in your web browser. @@ -206,9 +268,13 @@ Bolt.diy is a software enabling users to create web applications from the prompt 5. Click **Local Providers** to add a new external provider configuration. 6. Toggle the switch next to **OpenAILike** to enable it. Then, enter the Scaleway API endpoint: `https://api.scaleway.ai/v1` as the base URL. 7. In Bolt's main menu, select `OpenAILike` and input your **Scaleway Secret Key** as the `OpenAILike API Key`. -8. Select one of the supported models from Scaleway Generative APIs. For best results with Bolt.diy, which requires a significant amount of output tokens (8000 by default), start with the `llama-3.1-8b-instruct` model. +8. Select one of the supported models from Scaleway Generative APIs. For best results with Bolt.diy, which requires a significant amount of output tokens (8000 by default), start with the `gemma-3-27b-it` model. 9. Enter your prompt in the Bolt.diy interface to see your application being generated. + + Only models that have a maximum output token of at least 8000 tokens are supported. You can found the list of Generative APIs models [here](https://www.scaleway.com/en/docs/generative-apis/reference-content/supported-models/#chat-models). + + Alternatively, you can also setup your Scaleway Secret Key by renaming `.env.example` to `.env`, adding corresponding environment variables values and restarting Bolt.diy: ```bash OPENAI_LIKE_API_BASE_URL=https://api.scaleway.ai/v1 From 808311f3587c48dba65af7cc6f0cdb5da75aadf2 Mon Sep 17 00:00:00 2001 From: navyblueglove <47873609+reda-maizate@users.noreply.github.com> Date: Mon, 5 May 2025 10:06:08 +0200 Subject: [PATCH 2/8] Update pages/generative-apis/reference-content/integrating-generative-apis-with-popular-tools.mdx MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Néda <87707325+nerda-codes@users.noreply.github.com> --- .../integrating-generative-apis-with-popular-tools.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pages/generative-apis/reference-content/integrating-generative-apis-with-popular-tools.mdx b/pages/generative-apis/reference-content/integrating-generative-apis-with-popular-tools.mdx index e33596d98b..1228b0d8a8 100644 --- a/pages/generative-apis/reference-content/integrating-generative-apis-with-popular-tools.mdx +++ b/pages/generative-apis/reference-content/integrating-generative-apis-with-popular-tools.mdx @@ -272,7 +272,7 @@ Bolt.diy is a software enabling users to create web applications from the prompt 9. Enter your prompt in the Bolt.diy interface to see your application being generated. - Only models that have a maximum output token of at least 8000 tokens are supported. You can found the list of Generative APIs models [here](https://www.scaleway.com/en/docs/generative-apis/reference-content/supported-models/#chat-models). + Only models that have a maximum output token of at least 8000 tokens are supported. Refer to the [list of Generative APIs models](/generative-apis/reference-content/supported-models/#chat-models) for more information. Alternatively, you can also setup your Scaleway Secret Key by renaming `.env.example` to `.env`, adding corresponding environment variables values and restarting Bolt.diy: From 489428a581aaa2fe3243bfe621d6dcc831e79a27 Mon Sep 17 00:00:00 2001 From: navyblueglove <47873609+reda-maizate@users.noreply.github.com> Date: Mon, 5 May 2025 10:06:28 +0200 Subject: [PATCH 3/8] Update pages/generative-apis/reference-content/integrating-generative-apis-with-popular-tools.mdx MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Néda <87707325+nerda-codes@users.noreply.github.com> --- .../integrating-generative-apis-with-popular-tools.mdx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pages/generative-apis/reference-content/integrating-generative-apis-with-popular-tools.mdx b/pages/generative-apis/reference-content/integrating-generative-apis-with-popular-tools.mdx index 1228b0d8a8..9d19a85f09 100644 --- a/pages/generative-apis/reference-content/integrating-generative-apis-with-popular-tools.mdx +++ b/pages/generative-apis/reference-content/integrating-generative-apis-with-popular-tools.mdx @@ -74,14 +74,14 @@ LangChain is a popular library for building AI applications. Scaleway's Generati #### Function calling -1. Install LangChain and his dependencies. +1. Run the following commands to install LangChain and its dependencies: ```bash pip install 'langchain>=0.3.24' pip install 'langchain-core>=0.3.55' pip install 'langchain-openai>=0.3.14' pip install 'langchain-text-splitters>=0.3.8' ``` -2. Create a file `tools.py` and add the following code to it to import and create the tools examples: +2. Create a file named `tools.py` and paste the code below into it to import and create the tools examples: ```Python from langchain_core.messages import HumanMessage from langchain.chat_models import init_chat_model From cdf6f107e640a780892132aba01f6bdb8ff30057 Mon Sep 17 00:00:00 2001 From: navyblueglove <47873609+reda-maizate@users.noreply.github.com> Date: Mon, 5 May 2025 10:06:38 +0200 Subject: [PATCH 4/8] Update pages/generative-apis/reference-content/integrating-generative-apis-with-popular-tools.mdx MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Néda <87707325+nerda-codes@users.noreply.github.com> --- .../integrating-generative-apis-with-popular-tools.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pages/generative-apis/reference-content/integrating-generative-apis-with-popular-tools.mdx b/pages/generative-apis/reference-content/integrating-generative-apis-with-popular-tools.mdx index 9d19a85f09..bae8a9570a 100644 --- a/pages/generative-apis/reference-content/integrating-generative-apis-with-popular-tools.mdx +++ b/pages/generative-apis/reference-content/integrating-generative-apis-with-popular-tools.mdx @@ -102,7 +102,7 @@ LangChain is a popular library for building AI applications. Scaleway's Generati tools = [add, multiply] ``` -3. You can configure the `init_chat_model` function to use Scaleway's Generative APIs. +3. Configure the `init_chat_model` function to use Scaleway's Generative APIs. ```Python llm = init_chat_model("mistral-small-3.1-24b-instruct-2503", model_provider="openai", base_url="https://api.scaleway.ai/v1") ``` From b2722e36ef54f08b95db9a87599ddacaef74b57b Mon Sep 17 00:00:00 2001 From: navyblueglove <47873609+reda-maizate@users.noreply.github.com> Date: Mon, 5 May 2025 10:06:54 +0200 Subject: [PATCH 5/8] Update pages/generative-apis/reference-content/integrating-generative-apis-with-popular-tools.mdx MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Néda <87707325+nerda-codes@users.noreply.github.com> --- .../integrating-generative-apis-with-popular-tools.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pages/generative-apis/reference-content/integrating-generative-apis-with-popular-tools.mdx b/pages/generative-apis/reference-content/integrating-generative-apis-with-popular-tools.mdx index bae8a9570a..ab9467ba1b 100644 --- a/pages/generative-apis/reference-content/integrating-generative-apis-with-popular-tools.mdx +++ b/pages/generative-apis/reference-content/integrating-generative-apis-with-popular-tools.mdx @@ -106,7 +106,7 @@ LangChain is a popular library for building AI applications. Scaleway's Generati ```Python llm = init_chat_model("mistral-small-3.1-24b-instruct-2503", model_provider="openai", base_url="https://api.scaleway.ai/v1") ``` -4. Everything is now set up, you can use the `llm` object and the `tools` list to generate a response to a query with the following code: +4. Use the `llm` object and the `tools` list to generate a response to your query with the following code: ```python query = "What is 3 * 12?" # You can also try the following query: From 2e490703dd4decc221fa2db3f3bea52276cbdd86 Mon Sep 17 00:00:00 2001 From: navyblueglove <47873609+reda-maizate@users.noreply.github.com> Date: Mon, 5 May 2025 10:07:25 +0200 Subject: [PATCH 6/8] Update pages/generative-apis/reference-content/integrating-generative-apis-with-popular-tools.mdx MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Néda <87707325+nerda-codes@users.noreply.github.com> --- .../integrating-generative-apis-with-popular-tools.mdx | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/pages/generative-apis/reference-content/integrating-generative-apis-with-popular-tools.mdx b/pages/generative-apis/reference-content/integrating-generative-apis-with-popular-tools.mdx index ab9467ba1b..bd077021d9 100644 --- a/pages/generative-apis/reference-content/integrating-generative-apis-with-popular-tools.mdx +++ b/pages/generative-apis/reference-content/integrating-generative-apis-with-popular-tools.mdx @@ -124,11 +124,9 @@ LangChain is a popular library for building AI applications. Scaleway's Generati print(llm_with_tools.invoke(messages).content) # We print the content of the final response. ``` -5. Finally, run the `tools.py`: +5. Run `tools.py`: ```bash python tools.py - ``` - The response should display the result of the calculation: ```bash The result of 3 * 12 is 36. ``` From d4214092be797b0c74bdb0cc79ad89a4205a57c1 Mon Sep 17 00:00:00 2001 From: navyblueglove Date: Mon, 5 May 2025 14:20:22 +0200 Subject: [PATCH 7/8] fix: add indentations for code example --- ...ing-generative-apis-with-popular-tools.mdx | 70 +++++++++---------- 1 file changed, 35 insertions(+), 35 deletions(-) diff --git a/pages/generative-apis/reference-content/integrating-generative-apis-with-popular-tools.mdx b/pages/generative-apis/reference-content/integrating-generative-apis-with-popular-tools.mdx index bd077021d9..b55329fad4 100644 --- a/pages/generative-apis/reference-content/integrating-generative-apis-with-popular-tools.mdx +++ b/pages/generative-apis/reference-content/integrating-generative-apis-with-popular-tools.mdx @@ -82,54 +82,54 @@ LangChain is a popular library for building AI applications. Scaleway's Generati pip install 'langchain-text-splitters>=0.3.8' ``` 2. Create a file named `tools.py` and paste the code below into it to import and create the tools examples: - ```Python - from langchain_core.messages import HumanMessage - from langchain.chat_models import init_chat_model - from langchain_core.tools import tool + ```Python + from langchain_core.messages import HumanMessage + from langchain.chat_models import init_chat_model + from langchain_core.tools import tool - @tool - def add(a: int, b: int) -> int: - """Adds a and b.""" - return a + b + @tool + def add(a: int, b: int) -> int: + """Adds a and b.""" + return a + b - @tool - def multiply(a: int, b: int) -> int: - """Multiplies a and b.""" - return a * b + @tool + def multiply(a: int, b: int) -> int: + """Multiplies a and b.""" + return a * b - tools = [add, multiply] - ``` + tools = [add, multiply] + ``` 3. Configure the `init_chat_model` function to use Scaleway's Generative APIs. - ```Python - llm = init_chat_model("mistral-small-3.1-24b-instruct-2503", model_provider="openai", base_url="https://api.scaleway.ai/v1") - ``` + ```Python + llm = init_chat_model("mistral-small-3.1-24b-instruct-2503", model_provider="openai", base_url="https://api.scaleway.ai/v1") + ``` 4. Use the `llm` object and the `tools` list to generate a response to your query with the following code: - ```python - query = "What is 3 * 12?" - # You can also try the following query: - # query = "What is 42 + 4?" + ```python + query = "What is 3 * 12?" + # You can also try the following query: + # query = "What is 42 + 4?" - messages = [HumanMessage(query)] # We initialize the messages list with the user's query. + messages = [HumanMessage(query)] # We initialize the messages list with the user's query. - ai_msg = llm_with_tools.invoke(messages) # We generate a response to the query. - messages.append(ai_msg) # We append the response to the messages list. + ai_msg = llm_with_tools.invoke(messages) # We generate a response to the query. + messages.append(ai_msg) # We append the response to the messages list. - for tool_call in ai_msg.tool_calls: - selected_tool = {"add": add, "multiply": multiply}[tool_call["name"].lower()] # Depending on the tool name, we select the appropriate tool. - tool_msg = selected_tool.invoke(tool_call) # We invoke the selected tool with the tool call. - messages.append(tool_msg) # We append the tool's response to the messages list. + for tool_call in ai_msg.tool_calls: + selected_tool = {"add": add, "multiply": multiply}[tool_call["name"].lower()] # Depending on the tool name, we select the appropriate tool. + tool_msg = selected_tool.invoke(tool_call) # We invoke the selected tool with the tool call. + messages.append(tool_msg) # We append the tool's response to the messages list. - print(llm_with_tools.invoke(messages).content) # We print the content of the final response. - ``` + print(llm_with_tools.invoke(messages).content) # We print the content of the final response. + ``` 5. Run `tools.py`: - ```bash - python tools.py - ```bash - The result of 3 * 12 is 36. - ``` + ```bash + python tools.py + ```bash + The result of 3 * 12 is 36. + ``` Refer to our dedicated documentation for [implementing Retrieval-Augmented Generation (RAG) with LangChain and Scaleway Generative APIs](/tutorials/how-to-implement-rag-generativeapis/) From 7a9fd826534c8ad31159760ab8e7da7ea4db3a75 Mon Sep 17 00:00:00 2001 From: navyblueglove Date: Tue, 6 May 2025 10:29:43 +0200 Subject: [PATCH 8/8] fix: added $ for bash commands --- ...integrating-generative-apis-with-popular-tools.mdx | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/pages/generative-apis/reference-content/integrating-generative-apis-with-popular-tools.mdx b/pages/generative-apis/reference-content/integrating-generative-apis-with-popular-tools.mdx index b55329fad4..b4a887b40c 100644 --- a/pages/generative-apis/reference-content/integrating-generative-apis-with-popular-tools.mdx +++ b/pages/generative-apis/reference-content/integrating-generative-apis-with-popular-tools.mdx @@ -76,10 +76,10 @@ LangChain is a popular library for building AI applications. Scaleway's Generati 1. Run the following commands to install LangChain and its dependencies: ```bash - pip install 'langchain>=0.3.24' - pip install 'langchain-core>=0.3.55' - pip install 'langchain-openai>=0.3.14' - pip install 'langchain-text-splitters>=0.3.8' + $ pip install 'langchain>=0.3.24' + $ pip install 'langchain-core>=0.3.55' + $ pip install 'langchain-openai>=0.3.14' + $ pip install 'langchain-text-splitters>=0.3.8' ``` 2. Create a file named `tools.py` and paste the code below into it to import and create the tools examples: ```Python @@ -126,8 +126,7 @@ LangChain is a popular library for building AI applications. Scaleway's Generati ``` 5. Run `tools.py`: ```bash - python tools.py - ```bash + $ python tools.py The result of 3 * 12 is 36. ```