-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.R
51 lines (39 loc) · 1.79 KB
/
test.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
library(ollamar)
library(readr)
library(mall) # https://mlverse.github.io/mall/#get-started
# Start Ollama (you'll need to have it installed on your PC)
# Test connection to Ollama server
test_connection()
# Check for installed models on your machine
list_models()
# Download/pull a model if needed
# pull("llama3.2")
# Read dataset
jobs <- read_csv("data/puestos.csv")
# Testing some mall functions (it can take a while to run each one depending on your RAM/CPUs)
## Summary
jobs_summary <- jobs[1:5,] |>
llm_summarize(alcance,
max_words = 4,
additional_prompt = "please provide output in spanish")
## Classification
jobs_classification <- jobs[1:5,] |>
llm_classify(alcance,
additional_prompt = "For this taks, take into account that both the original variable and your output categories are in spanish",
c("Atención al ciudadano", "Tareas administrativas o de apoyo", "Otras tareas"), # You should provide comprehensive options or it'll give NAs back
pred_name = "classification"
)
## Custom prompt
my_prompt <- paste(
"Classify text.",
"Return only the answer, no explanation",
"Acceptable categories are 'Atención al público', 'Tareas administrativas', 'Otras tareas'",
"'Atención al público' will be used when you think the job description involves helping or providing direct support to the citizen",
"'Tareas administrativas' will be used when the job description relates to tasks that don't involve facing the citizen",
"'Otras tareas' will be used when you can't fit the job in any ot the other categories",
"Classify this job post descriptions 'alcance' (in spanish):"
)
jobs_custom <- jobs |>
llm_custom(alcance, my_prompt)
# Write csv with resulting classification
write_csv(jobs_custom, "data/classification.csv")