Skip to content

Commit

Permalink
Resolve corner cases LLMFunctions
Browse files Browse the repository at this point in the history
  • Loading branch information
atharvas committed Sep 17, 2024
1 parent 5efac1b commit c8d3afa
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<!-- prettier-ignore-start -->
<div align="center">

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 |
| :---: | :---: |
Expand Down
11 changes: 8 additions & 3 deletions src/LLMFunctions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit c8d3afa

Please sign in to comment.