Skip to content

Commit

Permalink
up
Browse files Browse the repository at this point in the history
  • Loading branch information
svilupp committed Jun 26, 2024
1 parent e779f76 commit 7df6dd7
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 50 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed
- Fixed loading RAGResult when one of the candidate fields was `nothing`.
- Utility type checks like `isusermessage`, `issystemmessage`, `isdatamessage`, `isaimessage`, `istracermessage` do not throw errors when given any arbitrary input types (previously they only worked for `AbstractMessage` types). It's a `isa` check, so it should work for all input types.
- Changed preference loading to use typed `global` instead of `const`, to fix issues with API keys not being loaded properly on start.

## [0.33.0]

Expand Down
85 changes: 35 additions & 50 deletions src/user_preferences.jl
Original file line number Diff line number Diff line change
Expand Up @@ -124,80 +124,65 @@ function get_preferences(key::String)
end

## Load up GLOBALS
const MODEL_CHAT::String = @load_preference("MODEL_CHAT", default="gpt-3.5-turbo")
const MODEL_EMBEDDING::String = @load_preference("MODEL_EMBEDDING",
global MODEL_CHAT::String = @load_preference("MODEL_CHAT", default="gpt-3.5-turbo")
global MODEL_EMBEDDING::String = @load_preference("MODEL_EMBEDDING",
default="text-embedding-3-small")
const MODEL_IMAGE_GENERATION = @load_preference("MODEL_IMAGE_GENERATION",
global MODEL_IMAGE_GENERATION::String = @load_preference("MODEL_IMAGE_GENERATION",
default="dall-e-3")
# the prompt schema default is defined in llm_interace.jl !
# const PROMPT_SCHEMA = OpenAISchema()

# First, load from preferences, then from environment variables
# Note: We load first into a variable `temp_` to avoid inlining of the get(ENV...) call
_temp = get(ENV, "OPENAI_API_KEY", "")
const OPENAI_API_KEY::String = @load_preference("OPENAI_API_KEY",
default=_temp);
global OPENAI_API_KEY::String = @load_preference("OPENAI_API_KEY",
default=get(ENV, "OPENAI_API_KEY", ""));
# Note: Disable this warning by setting OPENAI_API_KEY to anything
isempty(OPENAI_API_KEY) &&
@warn "OPENAI_API_KEY variable not set! OpenAI models will not be available - set API key directly via `PromptingTools.OPENAI_API_KEY=<api-key>`!"

_temp = get(ENV, "MISTRALAI_API_KEY", "")
const MISTRALAI_API_KEY::String = @load_preference("MISTRALAI_API_KEY",
default=_temp);
global MISTRALAI_API_KEY::String = @load_preference("MISTRALAI_API_KEY",
default=get(ENV, "MISTRALAI_API_KEY", ""));

_temp = get(ENV, "COHERE_API_KEY", "")
const COHERE_API_KEY::String = @load_preference("COHERE_API_KEY",
default=_temp);
global COHERE_API_KEY::String = @load_preference("COHERE_API_KEY",
default=get(ENV, "COHERE_API_KEY", ""));

_temp = get(ENV, "DATABRICKS_API_KEY", "")
const DATABRICKS_API_KEY::String = @load_preference("DATABRICKS_API_KEY",
default=_temp);
global DATABRICKS_API_KEY::String = @load_preference("DATABRICKS_API_KEY",
default=get(ENV, "DATABRICKS_API_KEY", ""));

_temp = get(ENV, "DATABRICKS_HOST", "")
const DATABRICKS_HOST::String = @load_preference("DATABRICKS_HOST",
default=_temp);
global DATABRICKS_HOST::String = @load_preference("DATABRICKS_HOST",
default=get(ENV, "DATABRICKS_HOST", ""));

_temp = get(ENV, "TAVILY_API_KEY", "")
const TAVILY_API_KEY::String = @load_preference("TAVILY_API_KEY",
default=_temp);
global TAVILY_API_KEY::String = @load_preference("TAVILY_API_KEY",
default=get(ENV, "TAVILY_API_KEY", ""));

_temp = get(ENV, "GOOGLE_API_KEY", "")
const GOOGLE_API_KEY::String = @load_preference("GOOGLE_API_KEY",
default=_temp);
global GOOGLE_API_KEY::String = @load_preference("GOOGLE_API_KEY",
default=get(ENV, "GOOGLE_API_KEY", ""));

_temp = get(ENV, "TOGETHER_API_KEY", "")
const TOGETHER_API_KEY::String = @load_preference("TOGETHER_API_KEY",
default=_temp);
global TOGETHER_API_KEY::String = @load_preference("TOGETHER_API_KEY",
default=get(ENV, "TOGETHER_API_KEY", ""));

_temp = get(ENV, "FIREWORKS_API_KEY", "")
const FIREWORKS_API_KEY::String = @load_preference("FIREWORKS_API_KEY",
default=_temp);
global FIREWORKS_API_KEY::String = @load_preference("FIREWORKS_API_KEY",
default=get(ENV, "FIREWORKS_API_KEY", ""));

_temp = get(ENV, "ANTHROPIC_API_KEY", "")
const ANTHROPIC_API_KEY::String = @load_preference("ANTHROPIC_API_KEY",
default=_temp);
global ANTHROPIC_API_KEY::String = @load_preference("ANTHROPIC_API_KEY",
default=get(ENV, "ANTHROPIC_API_KEY", ""));

_temp = get(ENV, "VOYAGE_API_KEY", "")
const VOYAGE_API_KEY::String = @load_preference("VOYAGE_API_KEY",
default=_temp);
global VOYAGE_API_KEY::String = @load_preference("VOYAGE_API_KEY",
default=get(ENV, "VOYAGE_API_KEY", ""));

_temp = get(ENV, "GROQ_API_KEY", "")
const GROQ_API_KEY::String = @load_preference("GROQ_API_KEY",
default=_temp);
global GROQ_API_KEY::String = @load_preference("GROQ_API_KEY",
default=get(ENV, "GROQ_API_KEY", ""));

_temp = get(ENV, "DEEPSEEK_API_KEY", "")
const DEEPSEEK_API_KEY::String = @load_preference("DEEPSEEK_API_KEY",
default=_temp);
global DEEPSEEK_API_KEY::String = @load_preference("DEEPSEEK_API_KEY",
default=get(ENV, "DEEPSEEK_API_KEY", ""));

_temp = get(ENV, "LOCAL_SERVER", "http://localhost:10897/v1")
## Address of the local server
const LOCAL_SERVER::String = @load_preference("LOCAL_SERVER",
default=_temp);
global LOCAL_SERVER::String = @load_preference("LOCAL_SERVER",
default=get(ENV, "LOCAL_SERVER", "http://localhost:10897/v1"));

_temp = get(ENV, "LOG_DIR", joinpath(pwd(), "log"))
## Address of the local server
const LOG_DIR::String = @load_preference("LOG_DIR",
default=_temp);
global LOG_DIR::String = @load_preference("LOG_DIR",
default=get(ENV, "LOG_DIR", joinpath(pwd(), "log")));

## CONVERSATION HISTORY
"""
Expand All @@ -212,8 +197,8 @@ See also: `push_conversation!`, `resize_conversation!`
"""
const CONV_HISTORY = Vector{Vector{<:Any}}()
const CONV_HISTORY_LOCK = ReentrantLock()
const MAX_HISTORY_LENGTH = @load_preference("MAX_HISTORY_LENGTH",
default=5)::Union{Int, Nothing}
global MAX_HISTORY_LENGTH::Union{Int, Nothing} = @load_preference("MAX_HISTORY_LENGTH",
default=5)

## Model registry
# A dictionary of model names and their specs (ie, name, costs per token, etc.)
Expand Down

0 comments on commit 7df6dd7

Please sign in to comment.