Skip to content

Commit

Permalink
+llm shortcut example
Browse files Browse the repository at this point in the history
  • Loading branch information
nmaguiar authored Aug 11, 2024
1 parent 1588b1f commit 1445efb
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 1 deletion.
2 changes: 1 addition & 1 deletion docs/guides/medium/checking-digests.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ grand_parent: Guides

# Checking hash digests

(OpenAF >= 20221216)
(OpenAF version >= 20221216)

There are several hash algorithms. OpenAF through Java has functions for the most common algorithms:

Expand Down
88 changes: 88 additions & 0 deletions docs/guides/ojob/llm-shortcut.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
---
layout: default
title: Example of using the LLM oJob shortcut
parent: oJob
grand_parent: Guides
---

# Example of using the LLM oJob shortcut

(OpenAF version >= 20240501)

Using the oJob's LLM shortcut it's possible to build oJobs that use external LLM models to provide results over gathered input data.

In this example we will prepare a of list the files, in a specific path. That list will then be sent, as context, to a LLM model to classify which files look like photos by their corresponding file extensions:

```yaml
todo:
- List files
- Analyze files for photos

jobs:
# ----------------
- name: List files
to :
# Arguments for io.listFiles
- (pass ):
aFilePath: .

# Executing io.listFiles
- (fn ): io.listFiles

# from the io.listFiles results query and transform to a filename list
- (query ): "sort_by(files[?isFile==`true`], &filename) | [].{ filename: filename } | { files: [] }"
((type )): path
((key )): res
((toKey)): fileList

# output the prepared list of files
- (output ): fileList

# ------------------------------
- name: Analyze files for photos
to :
# Give the prepared list of files to a LLM model for analysis
# (assuming an OAFP_MODEL environment is set (e.g. "(type: ollama, model: '...', url: '...', temperature: 0, timeout: 900000)" ))
- (llm ): From the provided list of files add an extra booelan 'isImage' field to indicate which files, given their extension, are photos.
((context)): list of files
((inKey )): fileList
((inPath )): files
((outPath)): result
((env )): OAFP_MODEL
((debug )): false

# Display the LLM model result as a table
- (output ): args
((path )): result.files
((format )): ctable

```
Executing this oJob you should be able to see a similar result to:
```bash
$ ojob example.yaml

filename │isImage
─────────────────────┼───────
.0.png │true
Dockerfile │false
LICENSE │false
Media 2.jpeg │true
Media.jpeg │true
README.md │false
a.class │false
a.csv │false
a.html │false
a.js │false
a.json │false
a.md │false
a.toml │false
a.xml │false
a.yaml │false
birthday.png │true
test.txt │false
test0.png │true
update.sh │false
[#19 rows]
```

0 comments on commit 1445efb

Please sign in to comment.