From c8d3afabda9a36c93f7464be0e2776040ed9ebb2 Mon Sep 17 00:00:00 2001 From: Atharva Sehgal Date: Tue, 17 Sep 2024 00:54:18 +0000 Subject: [PATCH] Resolve corner cases LLMFunctions --- README.md | 4 ++-- src/LLMFunctions.jl | 11 ++++++++--- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index dec25e78..59c95222 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,11 @@
-LibraryAugmentedSymbolicRegression.jl accelerates the search for symbolic expressions using library learning. +LibraryAugmentedSymbolicRegression.jl (LaSR.jl) accelerates the search for symbolic expressions using library learning. | Latest release | Website | Forums | Paper | | :---: | :---: | :---: | :---: | -| [![version](https://juliahub.com/docs/LaSR/version.svg)](https://juliahub.com/ui/Packages/LaSR/X2eIS) | [![Dev](https://img.shields.io/badge/docs-dev-blue.svg)](https://trishullab.github.io/lasr-web/) | [![Discussions](https://img.shields.io/badge/discussions-github-informational)](https://github.com/trishullab/LibraryAugmentedSymbolicRegression.jl/discussions) | [![Paper](https://img.shields.io/badge/arXiv-????.?????-b31b1b)](https://atharvas.net/static/lasr.pdf) | +| [![version](https://juliahub.com/docs/LibraryAugmentedSymbolicRegression/version.svg)](https://juliahub.com/ui/Packages/LibraryAugmentedSymbolicRegression/X2eIS) | [![Dev](https://img.shields.io/badge/docs-dev-blue.svg)](https://trishullab.github.io/lasr-web/) | [![Discussions](https://img.shields.io/badge/discussions-github-informational)](https://github.com/trishullab/LibraryAugmentedSymbolicRegression.jl/discussions) | [![Paper](https://img.shields.io/badge/arXiv-????.?????-b31b1b)](https://atharvas.net/static/lasr.pdf) | | Build status | Coverage | | :---: | :---: | diff --git a/src/LLMFunctions.jl b/src/LLMFunctions.jl index c5bc5b5f..2557af19 100644 --- a/src/LLMFunctions.jl +++ b/src/LLMFunctions.jl @@ -21,7 +21,7 @@ using DynamicExpressions: AbstractOperatorEnum using Compat: Returns, @inline using ..CoreModule: Options, DATA_TYPE, binopmap, unaopmap, LLMOptions -using ..MutationFunctionsModule: gen_random_tree_fixed_size +using ..MutationFunctionsModule: gen_random_tree_fixed_size, random_node_and_parent using PromptingTools: SystemMessage, @@ -58,12 +58,13 @@ function convertDict(d)::NamedTuple end function get_vars(options::Options)::String - variable_names = ["x", "y", "z", "k", "j", "l", "m", "n", "p", "a", "b"] - if !isnothing(options.llm_options.var_order) + if !isnothing(options.llm_options) && !isnothing(options.llm_options.var_order) variable_names = [ options.llm_options.var_order[key] for key in sort(collect(keys(options.llm_options.var_order))) ] + else + variable_names = ["x", "y", "z", "k", "j", "l", "m", "n", "p", "a", "b"] end return join(variable_names, ", ") end @@ -105,6 +106,7 @@ function construct_prompt( # if n_occurrences is less than |element_list|, add the missing elements after the last occurrence if n_occurrences < length(element_list) last_occurrence = findlast(x -> occursin(pattern, x), lines) + @assert last_occurrence !== nothing "No occurrences of the element_id_tag found in the user prompt." for i in reverse((n_occurrences + 1):length(element_list)) new_line = replace(lines[last_occurrence], string(n_occurrences) => string(i)) insert!(lines, last_occurrence + 1, new_line) @@ -544,6 +546,9 @@ function parse_msg_content(msg_content) try out = parse(content) # json parse + if out === nothing + return [] + end if out isa Dict return [out[key] for key in keys(out)] end