Skip to content

Commit e2535dd

Browse files
authored
Update integrating-generative-apis-with-popular-tools.mdx
update OpenAI python library code examples
1 parent 3e3829a commit e2535dd

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

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

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,26 @@ Scaleway Generative APIs follow OpenAI's API structure, making integration strai
3636

3737
### Configuration
3838

39-
To use the OpenAI client library with Scaleway's Generative APIs, you'll need to set the API key and base URL in your OpenAI-compatible client:
39+
To use the OpenAI client library with Scaleway's Generative APIs, you'll need to install the required dependencies:
40+
```bash
41+
pip install openai
42+
```
43+
44+
Then you'll need to set the API key and base URL in your OpenAI-compatible client:
4045
```python
41-
import openai
42-
openai.api_key = "<API secret key>"
43-
openai.api_base = "https://api.scaleway.ai/v1"
44-
response = openai.ChatCompletion.create(
46+
from openai import OpenAI
47+
48+
client = OpenAI(
49+
base_url="https://api.scaleway.ai/v1",
50+
api_key="<API secret key>"
51+
)
52+
53+
response = client.chat.completions.create(
4554
model="llama-3.1-8b-instruct",
4655
messages=[{"role": "user", "content": "Tell me a joke about AI"}]
4756
)
48-
print(response["choices"][0]["message"]["content"])
57+
58+
print(response.choices[0].message.content)
4959
```
5060
<Message type="tip">
5161
Make sure to replace `<API secret key>` with your actual API key.

0 commit comments

Comments
 (0)