Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Haiku 3.5 and Grok2 Beta #229

Merged
merged 1 commit into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Fixed

## [0.62.0]

### Added
- Added a new Claude 3.5 Haiku model (`claude-3-5-haiku-latest`) and updated the alias `claudeh` with it.
- Added support for XAI's Grok 2 beta model (`grok-beta`) and updated the alias `grok` with it. Set your ENV api key `XAI_API_KEY` to use it.

## [0.61.0]

### Added
Expand Down
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "PromptingTools"
uuid = "670122d1-24a8-4d70-bfce-740807c42192"
authors = ["J S @svilupp and contributors"]
version = "0.61.0"
version = "0.62.0"

[deps]
AbstractTrees = "1520ce14-60c1-5f80-bbc7-55ef81b5835c"
Expand Down
12 changes: 12 additions & 0 deletions src/llm_interface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,18 @@ Requires one environment variable to be set:
"""
struct SambaNovaOpenAISchema <: AbstractOpenAISchema end

"""
XAIOpenAISchema

Schema to call the XAI API. It follows OpenAI API conventions.

Get your API key from [here](https://console.x.ai/).

Requires one environment variable to be set:
- `XAI_API_KEY`: Your API key
"""
struct XAIOpenAISchema <: AbstractOpenAISchema end

abstract type AbstractOllamaSchema <: AbstractPromptSchema end

"""
Expand Down
20 changes: 20 additions & 0 deletions src/llm_openai_schema_defs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,15 @@
api_key = isempty(SAMBANOVA_API_KEY) ? api_key : SAMBANOVA_API_KEY
OpenAI.create_chat(CustomOpenAISchema(), api_key, model, conversation; url, kwargs...)
end
function OpenAI.create_chat(schema::XAIOpenAISchema,

Check warning on line 208 in src/llm_openai_schema_defs.jl

View check run for this annotation

Codecov / codecov/patch

src/llm_openai_schema_defs.jl#L208

Added line #L208 was not covered by tests
api_key::AbstractString,
model::AbstractString,
conversation;
url::String = "https://api.x.ai/v1",
kwargs...)
api_key = isempty(XAI_API_KEY) ? api_key : XAI_API_KEY
OpenAI.create_chat(CustomOpenAISchema(), api_key, model, conversation; url, kwargs...)

Check warning on line 215 in src/llm_openai_schema_defs.jl

View check run for this annotation

Codecov / codecov/patch

src/llm_openai_schema_defs.jl#L214-L215

Added lines #L214 - L215 were not covered by tests
end
function OpenAI.create_chat(schema::DatabricksOpenAISchema,
api_key::AbstractString,
model::AbstractString,
Expand Down Expand Up @@ -364,6 +373,17 @@
base_url = url)
OpenAI.create_embeddings(provider, docs, model; kwargs...)
end
function OpenAI.create_embeddings(schema::XAIOpenAISchema,

Check warning on line 376 in src/llm_openai_schema_defs.jl

View check run for this annotation

Codecov / codecov/patch

src/llm_openai_schema_defs.jl#L376

Added line #L376 was not covered by tests
api_key::AbstractString,
docs,
model::AbstractString;
url::String = "https://api.x.ai/v1",
kwargs...)
provider = CustomProvider(;

Check warning on line 382 in src/llm_openai_schema_defs.jl

View check run for this annotation

Codecov / codecov/patch

src/llm_openai_schema_defs.jl#L382

Added line #L382 was not covered by tests
api_key = isempty(XAI_API_KEY) ? api_key : XAI_API_KEY,
base_url = url)
OpenAI.create_embeddings(provider, docs, model; kwargs...)

Check warning on line 385 in src/llm_openai_schema_defs.jl

View check run for this annotation

Codecov / codecov/patch

src/llm_openai_schema_defs.jl#L385

Added line #L385 was not covered by tests
end
function OpenAI.create_embeddings(schema::AzureOpenAISchema,
api_key::AbstractString,
docs,
Expand Down
33 changes: 26 additions & 7 deletions src/user_preferences.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Check your preferences by calling `get_preferences(key::String)`.
- `OPENROUTER_API_KEY`: The API key for the OpenRouter API. Get yours from [here](https://openrouter.ai/keys).
- `CEREBRAS_API_KEY`: The API key for the Cerebras API. Get yours from [here](https://cloud.cerebras.ai/).
- `SAMBANOVA_API_KEY`: The API key for the Sambanova API. Get yours from [here](https://cloud.sambanova.ai/apis).
- `XAI_API_KEY`: The API key for the XAI API. Get your key from [here](https://console.x.ai/).
- `MODEL_CHAT`: The default model to use for aigenerate and most ai* calls. See `MODEL_REGISTRY` for a list of available models or define your own.
- `MODEL_EMBEDDING`: The default model to use for aiembed (embedding documents). See `MODEL_REGISTRY` for a list of available models or define your own.
- `PROMPT_SCHEMA`: The default prompt schema to use for aigenerate and most ai* calls (if not specified in `MODEL_REGISTRY`). Set as a string, eg, `"OpenAISchema"`.
Expand Down Expand Up @@ -60,6 +61,7 @@ Define your `register_model!()` calls in your `startup.jl` file to make them ava
- `CEREBRAS_API_KEY`: The API key for the Cerebras API.
- `SAMBANOVA_API_KEY`: The API key for the Sambanova API.
- `LOG_DIR`: The directory to save the logs to, eg, when using `SaverSchema <: AbstractTracerSchema`. Defaults to `joinpath(pwd(), "log")`. Refer to `?SaverSchema` for more information on how it works and examples.
- `XAI_API_KEY`: The API key for the XAI API. Get your key from [here](https://console.x.ai/).

Preferences.jl takes priority over ENV variables, so if you set a preference, it will take precedence over the ENV variable.

Expand All @@ -84,6 +86,7 @@ const ALLOWED_PREFERENCES = ["MISTRALAI_API_KEY",
"OPENROUTER_API_KEY", # Added OPENROUTER_API_KEY
"CEREBRAS_API_KEY",
"SAMBANOVA_API_KEY",
"XAI_API_KEY", # Added XAI_API_KEY
"MODEL_CHAT",
"MODEL_EMBEDDING",
"MODEL_ALIASES",
Expand Down Expand Up @@ -169,6 +172,7 @@ global CEREBRAS_API_KEY::String = ""
global SAMBANOVA_API_KEY::String = ""
global LOCAL_SERVER::String = ""
global LOG_DIR::String = ""
global XAI_API_KEY::String = ""

# Load them on init
"Loads API keys from environment variables and preferences"
Expand Down Expand Up @@ -236,6 +240,9 @@ function load_api_keys!()
global LOG_DIR
LOG_DIR = @load_preference("LOG_DIR",
default=get(ENV, "LOG_DIR", joinpath(pwd(), "log")))
global XAI_API_KEY
XAI_API_KEY = @load_preference("XAI_API_KEY",
default=get(ENV, "XAI_API_KEY", ""))

return nothing
end
Expand Down Expand Up @@ -415,7 +422,7 @@ aliases = merge(
"claude" => "claude-3-5-sonnet-latest",
"claudeo" => "claude-3-opus-20240229",
"claudes" => "claude-3-5-sonnet-latest",
"claudeh" => "claude-3-haiku-20240307",
"claudeh" => "claude-3-5-haiku-latest",
## Groq
"gllama3" => "llama-3.1-8b-instant",
"gl3" => "llama-3.1-8b-instant",
Expand Down Expand Up @@ -454,6 +461,8 @@ aliases = merge(
"sls" => "Meta-Llama-3.1-8B-Instruct", # s for small
"slm" => "Meta-Llama-3.1-70B-Instruct", # m for medium
"sll" => "Meta-Llama-3.1-405B-Instruct", # l for large
## XAI's Grok
"grok" => "grok-beta",
## DeepSeek
"dschat" => "deepseek-chat",
"dscode" => "deepseek-coder",
Expand Down Expand Up @@ -888,11 +897,16 @@ registry = Dict{String, ModelSpec}(
3e-6,
1.5e-5,
"Anthropic's middle model Claude 3 Sonnet. Max output 4096 tokens, 200K context. See details [here](https://docs.anthropic.com/claude/docs/models-overview)"),
# "claude-3-5-haiku-latest" => ModelSpec("claude-3-5-haiku-latest",
# AnthropicSchema(),
# 2.5e-7,
# 1.25e-6,
# "Anthropic's smallest and faster model Claude 3 Haiku. Latest version, 200K context. See details [here](https://docs.anthropic.com/claude/docs/models-overview)"),
"claude-3-5-haiku-latest" => ModelSpec("claude-3-5-haiku-latest",
AnthropicSchema(),
1e-6,
5e-6,
"Anthropic's smallest and faster model Claude 3 Haiku. Latest version, 200K context. See details [here](https://docs.anthropic.com/claude/docs/models-overview)"),
"claude-3-5-haiku-20241022" => ModelSpec("claude-3-5-haiku-20241022",
AnthropicSchema(),
1e-6,
5e-6,
"Anthropic's smallest and faster model Claude 3 Haiku. Version 2024-10-22, 200K context. See details [here](https://docs.anthropic.com/claude/docs/models-overview)"),
"claude-3-haiku-20240307" => ModelSpec("claude-3-haiku-20240307",
AnthropicSchema(),
2.5e-7,
Expand Down Expand Up @@ -1058,7 +1072,12 @@ registry = Dict{String, ModelSpec}(
SambaNovaOpenAISchema(),
5e-6,
1e-7,
"Meta's Llama3.1 405b, hosted by SambaNova.ai. Max 64K context.")
"Meta's Llama3.1 405b, hosted by SambaNova.ai. Max 64K context."),
"grok-beta" => ModelSpec("grok-beta",
XAIOpenAISchema(),
5e-6,
15e-6,
"XAI's Grok 2 beta model. Max 128K context.")
)

"""
Expand Down
Loading