Skip to content

Commit

Permalink
feat: Add GoogleProvider with proper Bearer token auth and update Goo…
Browse files Browse the repository at this point in the history
…gleOpenAISchema methods

- Add GoogleProvider struct with proper Bearer token authentication
- Update create_chat to use GoogleProvider and openai_request
- Update create_embeddings to use GoogleProvider and openai_request
- Maintain consistent URL handling up to /v1beta
  • Loading branch information
devin-ai-integration[bot] committed Nov 12, 2024
1 parent 43f4d6d commit bc03b35
Showing 1 changed file with 28 additions and 5 deletions.
33 changes: 28 additions & 5 deletions src/llm_openai_schema_defs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -214,14 +214,33 @@ function OpenAI.create_chat(schema::XAIOpenAISchema,
api_key = isempty(XAI_API_KEY) ? api_key : XAI_API_KEY
OpenAI.create_chat(CustomOpenAISchema(), api_key, model, conversation; url, kwargs...)
end

# Add GoogleProvider implementation
Base.@kwdef struct GoogleProvider <: AbstractCustomProvider
api_key::String = ""
base_url::String = "https://generativelanguage.googleapis.com/v1beta"
api_version::String = ""
end

function OpenAI.auth_header(provider::GoogleProvider, api_key::AbstractString)
Dict("Authorization" => "Bearer $(api_key)")
end

function OpenAI.create_chat(schema::GoogleOpenAISchema,
api_key::AbstractString,
model::AbstractString,
conversation;
url::String = "https://generativelanguage.googleapis.com/v1beta",
kwargs...)
api_key = isempty(GOOGLE_API_KEY) ? api_key : GOOGLE_API_KEY
OpenAI.create_chat(CustomOpenAISchema(), api_key, model, conversation; url, kwargs...)
# Use GoogleProvider instead of CustomProvider
provider = GoogleProvider(; api_key, base_url = url)
OpenAI.openai_request("chat/completions",
provider;
method = "POST",
messages = conversation,
model = model,
kwargs...)
end
function OpenAI.create_chat(schema::DatabricksOpenAISchema,
api_key::AbstractString,
Expand Down Expand Up @@ -399,10 +418,14 @@ function OpenAI.create_embeddings(schema::GoogleOpenAISchema,
model::AbstractString;
url::String = "https://generativelanguage.googleapis.com/v1beta",
kwargs...)
provider = CustomProvider(;
api_key = isempty(GOOGLE_API_KEY) ? api_key : GOOGLE_API_KEY,
base_url = url)
OpenAI.create_embeddings(provider, docs, model; kwargs...)
api_key = isempty(GOOGLE_API_KEY) ? api_key : GOOGLE_API_KEY
provider = GoogleProvider(; api_key, base_url = url)
OpenAI.openai_request("embeddings",
provider;
method = "POST",
input = docs,
model = model,
kwargs...)
end
function OpenAI.create_embeddings(schema::AzureOpenAISchema,
api_key::AbstractString,
Expand Down

0 comments on commit bc03b35

Please sign in to comment.