|
1 | 1 | --- |
2 | 2 | meta: |
3 | | - title: How to query text models |
4 | | - description: Learn how to interact with powerful text models using Scaleway's Generative APIs service. |
| 3 | + title: How to query language models |
| 4 | + description: Learn how to interact with powerful language models using Scaleway's Generative APIs service. |
5 | 5 | content: |
6 | | - h1: How to query text models |
7 | | - paragraph: Learn how to interact with powerful text models using Scaleway's Generative APIs service. |
8 | | -tags: generative-apis ai-data text-models |
| 6 | + h1: How to query language models |
| 7 | + paragraph: Learn how to interact with powerful language models using Scaleway's Generative APIs service. |
| 8 | +tags: generative-apis ai-data language-models chat-completions-api |
9 | 9 | dates: |
10 | | - validation: 2024-08-28 |
| 10 | + validation: 2024-10-30 |
11 | 11 | posted: 2024-08-28 |
12 | 12 | --- |
13 | 13 |
|
14 | | -Scaleway's Generative APIs service allows users to interact with powerful text models hosted on the platform. |
| 14 | +Scaleway's Generative APIs service allows users to interact with powerful language models hosted on the platform. |
15 | 15 |
|
16 | | -There are several ways to interact with text models: |
17 | | -- The Scaleway [console](https://console.scaleway.com) will soon provide a complete [playground](/ai-data/generative-apis/how-to/query-text-models/#accessing-the-playground), aiming to test models, adapt parameters, and observe how these changes affect the output in real-time. |
18 | | -- Via the [Chat API](/ai-data/generative-apis/how-to/query-text-models/#querying-text-models-via-api) |
| 16 | +There are several ways to interact with language models: |
| 17 | +- The Scaleway [console](https://console.scaleway.com) provides complete [playground](/ai-data/generative-apis/how-to/query-language-models/#accessing-the-playground), aiming to test models, adapt parameters, and observe how these changes affect the output in real-time. |
| 18 | +- Via the [Chat API](/ai-data/generative-apis/how-to/query-language-models/#querying-language-models-via-api) |
19 | 19 |
|
20 | 20 | <Macro id="requirements" /> |
21 | 21 |
|
22 | | -- Access to this service is restricted while in beta. You can request access to the product by filling out a form on Scaleway's [betas page](https://www.scaleway.com/en/betas/#generative-apis). |
23 | 22 | - A Scaleway account logged into the [console](https://console.scaleway.com) |
24 | 23 | - [Owner](/identity-and-access-management/iam/concepts/#owner) status or [IAM permissions](/identity-and-access-management/iam/concepts/#permission) allowing you to perform actions in the intended Organization |
25 | 24 | - A valid [API key](/identity-and-access-management/iam/how-to/create-api-keys/) for API authentication |
26 | 25 | - Python 3.7+ installed on your system |
27 | 26 |
|
28 | 27 | ## Accessing the Playground |
29 | 28 |
|
30 | | -Scaleway's Playground is in development, stay tuned! |
| 29 | +Scaleway provides a web playground for instruct-based models hosted on Generative APIs. |
31 | 30 |
|
32 | | -## Querying text models via API |
| 31 | +1. Navigate to **Generative APIs** under the **AI** section of the [Scaleway console](https://console.scaleway.com/) side menu. The list of models you can query displays. |
| 32 | +2. Click the name of the chat model you want to try. Alternatively, click <Icon name="more" /> next to the chat model, and click **Try model** in the menu. |
| 33 | + |
| 34 | +The web playground displays. |
| 35 | + |
| 36 | +## Using the playground |
| 37 | +1. Enter a prompt at the bottom of the page, or use one of the suggested prompts in the conversation area. |
| 38 | +2. Edit the hyperparameters listed on the right column, for example the default temperature for more or less randomness on the outputs. |
| 39 | +3. Switch models at the top of the page, to observe the capabilities of chat models offered via Generative APIs. |
| 40 | +4. Click **View code** to get code snippets configured according to your settings in the playground. |
| 41 | + |
| 42 | +## Querying language models via API |
33 | 43 |
|
34 | 44 | The [Chat API](/ai-data/generative-apis/api-cli/using-chat-api/) is an OpenAI-compatible REST API for generating and manipulating conversations. |
35 | 45 |
|
@@ -129,7 +139,7 @@ response = client.chat.completions.create( |
129 | 139 | ) |
130 | 140 |
|
131 | 141 | for chunk in response: |
132 | | - if chunk.choices[0].delta.content: |
| 142 | + if chunk.choices and chunk.choices[0].delta.content: |
133 | 143 | print(chunk.choices[0].delta.content, end="") |
134 | 144 | ``` |
135 | 145 |
|
@@ -157,7 +167,8 @@ async def main(): |
157 | 167 | stream=True, |
158 | 168 | ) |
159 | 169 | async for chunk in stream: |
160 | | - print(chunk.choices[0].delta.content, end="") |
| 170 | + if chunk.choices and chunk.choices[0].delta.content: |
| 171 | + print(chunk.choices[0].delta.content, end="") |
161 | 172 |
|
162 | 173 | asyncio.run(main()) |
163 | 174 | ``` |
0 commit comments