Skip to content
This repository was archived by the owner on Nov 22, 2024. It is now read-only.

Commit 4a8c255

Browse files
committed
cleaner AI examples using find() call
1 parent 6f38180 commit 4a8c255

1 file changed

Lines changed: 28 additions & 5 deletions

File tree

README.md

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -989,7 +989,7 @@ $
989989

990990
### Zone file upload (i.e. import) Python calls (uses BIND format files)
991991

992-
Because `import` is a keyword (or reserved word) in Python we append a '_' (underscore) to the verb in order to use.
992+
Because `import` is a keyword (or reserved word) in Python we append a `_` (underscore) to the verb in order to use.
993993
The `cli4` command does not need this edit.
994994

995995
```python
@@ -1280,7 +1280,7 @@ along with https://developers.cloudflare.com/workers-ai/models/ for the nitty gr
12801280

12811281
There are three AI calls included within the example folder.
12821282

1283-
Image creation.
1283+
### Image creation.
12841284

12851285
```bash
12861286
$ python examples/example_ai_images.py A happy llama running through an orange cloud > /tmp/image.png
@@ -1290,15 +1290,16 @@ $ file /tmp/image.png
12901290
$
12911291
```
12921292

1293-
Translation.
1293+
### Translation.
12941294

12951295
```bash
12961296
$ python examples/example_ai_translate.py I\'ll have an order of the moule frites
12971297
Je vais avoir une commande des frites de moule
12981298
$
12991299
```
13001300

1301-
Speech Recognition with the openai/whisper model.
1301+
### Speech Recognition with the openai/whisper model.
1302+
13021303
The following downloads a speech as an mp3 file and passes it to the AI API.
13031304
It does a very good job transcribing; however, there's a good chance these mp3 files were use for training.
13041305
That said, the example code is here to show how the API works vs testing the AI/ML quality.
@@ -1343,7 +1344,29 @@ extras =
13431344
$
13441345
```
13451346

1346-
Along with a version of the library above `2.14.1`.
1347+
As the `@` (at) symbol and the `.` (dot) symbol aren't allowed in python variable names; you'll have the replace `@cf` with `at_cf` and `.` with `_`.
1348+
There's already notes above that state that `-` (dash) is replaced with `_` in the code.
1349+
That will be needed with some model names.
1350+
1351+
The `cli4` command does not need this edit. It is done on the fly!
1352+
1353+
For example, the following code is valid:
1354+
```python
1355+
r = cf.accounts.ai.run.at_cf.openai.whisper.post(account_id, data=audio_data)
1356+
r = cf.accounts.ai.run.at_cf.meta.m2m100_1_2b.post(account_id, data=translate_data)
1357+
r = cf.accounts.ai.run.at_cf.stabilityai.stable_diffusion_xl_base_1_0.post(account_id, data=image_create_data)
1358+
```
1359+
1360+
Or you can use the `find()` call can will do this conversion for you.
1361+
```python
1362+
translate_data = {'text':"I'll have an order of the moule frites", 'source_lang':'english', 'target_lang':'french'}
1363+
1364+
m = cf.find('/accounts/:id/ai/run/@cf/meta/m2m100-1.2b')
1365+
r = m.post(account_id, data=translate_data)
1366+
print(r['translated_text'])
1367+
```
1368+
1369+
You will also have to run with a version of the library above `2.18.2`.
13471370

13481371
## Implemented API calls
13491372

0 commit comments

Comments
 (0)