Skip to content

Commit

Permalink
move some of the globals into user_preferences
Browse files Browse the repository at this point in the history
  • Loading branch information
svilupp committed Aug 18, 2024
1 parent 09d071a commit 6ffc1dc
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 41 deletions.
1 change: 1 addition & 0 deletions src/loading.jl
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ function load_index!(
indices = RT.ChunkIndex[]
for pack in packs
artifact_path = @artifact_str("$(pack)__$(config_key)")
## Try `pack.hdf5` name, if not found, try any single hdf5 file
path = if isfile(joinpath(artifact_path, "pack.hdf5"))
joinpath(artifact_path, "pack.hdf5")
else
Expand Down
2 changes: 1 addition & 1 deletion src/macros.jl
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ macro aihelp_str(user_question, flags...)
model = isempty(flags) ? MODEL_CHAT : only(flags)
prompt = Meta.parse("\"$(escape_string(user_question))\"")
quote
result = aihelp($(esc(RAG_CONFIG[])), $(esc(MAIN_INDEX[])), $(esc(prompt));
result = aihelp($(esc(RAG_CONFIG)), $(esc(MAIN_INDEX)), $(esc(prompt));
model = $(esc(model)),
return_all = true)
conv = haskey(result.conversations, :final_answer) ?
Expand Down
39 changes: 0 additions & 39 deletions src/pipeline_defaults.jl
Original file line number Diff line number Diff line change
@@ -1,42 +1,3 @@
### Global for history, replies, etc
const CONV_HISTORY = Vector{Vector{PT.AbstractMessage}}()
const CONV_HISTORY_LOCK = ReentrantLock()
const MAX_HISTORY_LENGTH = 1
global LAST_RESULT::Union{Nothing, RT.AbstractRAGResult} = nothing
global MAIN_INDEX::Union{Nothing, RT.AbstractChunkIndex} = nothing
"""
ALLOWED PACKS
Currently available packs are:
- `:julia` - Julia documentation, standard library docstrings and a few extras (for Julia v1.10)
- `:juliadata` - JuliaData.jl organization documentation, eg, DataFrames.jl and similar packages
- `:plots` - Plots.jl organization documentation, eg, Plots.jl, StatsPlots.jl, etc
- `:makie` - Makie.jl organization documentation
- `:tidier` - Tidier.jl organization documentation
- `:sciml` - SciML organization documentation
These packs have been sourced and packaged with DocsScraper.jl.
"""
const ALLOWED_PACKS = [:julia, :juliadata, :tidier, :sciml, :plots, :makie]

"""
LOADED_PACKS
The knowledge packs that are currently loaded in the index.
"""
global LOADED_PACKS::Vector{Symbol} = @load_preference("LOADED_PACKS",
default=["julia"]) .|> Symbol

### Globals for configuration
# These serve as reference models to be injected in the absence of inputs,
# but the actual used for the query is primarily provided aihelpme directly or via the active RAG_KWARGS
global MODEL_CHAT::String = @load_preference("MODEL_CHAT",
default="gpt4t")
global MODEL_EMBEDDING::String = @load_preference("MODEL_EMBEDDING",
default="text-embedding-3-large")
global EMBEDDING_DIMENSION::Int = @load_preference("EMBEDDING_DIMENSION",
default=1024)

# Loaded up with `update_pipeline!` later once RAG CONFIGURATIONS is populated
global RAG_KWARGS::NamedTuple = NamedTuple()
global RAG_CONFIG::RT.AbstractRAGConfig = RAGConfig() # just initialize, it will be changed
Expand Down
44 changes: 43 additions & 1 deletion src/user_preferences.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,46 @@
# Defines the preference setting mechanism, but the actual values are loaded/set in `src/pipeline_defaults.jl`
# Defines the preference setting mechanism, some of the pipeline/config values are loaded/set in `src/pipeline_defaults.jl`

### Global variables
### Global for history, replies, etc
const CONV_HISTORY = Vector{Vector{PT.AbstractMessage}}()
const CONV_HISTORY_LOCK = ReentrantLock()
const MAX_HISTORY_LENGTH = 1
global LAST_RESULT::Union{Nothing, RT.AbstractRAGResult} = nothing
global MAIN_INDEX::Union{Nothing, RT.AbstractChunkIndex} = nothing

"""
ALLOWED PACKS
Currently available packs are:
- `:julia` - Julia documentation, standard library docstrings and a few extras (for Julia v1.10)
- `:juliadata` - JuliaData.jl organization documentation, eg, DataFrames.jl and similar packages
- `:plots` - Plots.jl organization documentation, eg, Plots.jl, StatsPlots.jl, etc
- `:makie` - Makie.jl organization documentation
- `:tidier` - Tidier.jl organization documentation
- `:sciml` - SciML organization documentation
These packs have been sourced and packaged with DocsScraper.jl.
"""
const ALLOWED_PACKS = [:julia, :juliadata, :tidier, :sciml, :plots, :makie]

"""
LOADED_PACKS
The knowledge packs that are currently loaded in the index.
"""
global LOADED_PACKS::Vector{Symbol} = @load_preference("LOADED_PACKS",
default=["julia"]) .|> Symbol

### Globals for configuration
# These serve as reference models to be injected in the absence of inputs,
# but the actual used for the query is primarily provided aihelpme directly or via the active RAG_KWARGS
global MODEL_CHAT::String = @load_preference("MODEL_CHAT",
default="gpt4t")
global MODEL_EMBEDDING::String = @load_preference("MODEL_EMBEDDING",
default="text-embedding-3-large")
global EMBEDDING_DIMENSION::Int = @load_preference("EMBEDDING_DIMENSION",
default=1024)
###

"""
PREFERENCES
Expand Down

0 comments on commit 6ffc1dc

Please sign in to comment.