Skip to content

Commit

Permalink
Add GoogleOpenAISchema with OpenAI compatibility mode
Browse files Browse the repository at this point in the history
- Add GoogleOpenAISchema struct with documentation
- Implement create_chat method with Google API base URL
- Implement create_embedding method with Google API base URL
- Use GOOGLE_API_KEY for authentication
  • Loading branch information
devin-ai-integration[bot] committed Nov 12, 2024
1 parent eeb0dfc commit 4ba85dc
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
19 changes: 18 additions & 1 deletion src/llm_interface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,23 @@ Requires one environment variable to be set:
"""
struct XAIOpenAISchema <: AbstractOpenAISchema end

"""
GoogleOpenAISchema
Schema to call the Google's Gemini API using OpenAI compatibility mode. [API Reference](https://ai.google.dev/gemini-api/docs/openai#rest)
Links:
- [Get your API key](https://aistudio.google.com/apikey)
- [API Reference](https://ai.google.dev/gemini-api/docs/openai#rest)
- [Available models](https://ai.google.dev/models/gemini)
Requires one environment variable to be set:
- `GOOGLE_API_KEY`: Your API key
The base URL for the API is "https://generativelanguage.googleapis.com/v1beta"
"""
struct GoogleOpenAISchema <: AbstractOpenAISchema end

abstract type AbstractOllamaSchema <: AbstractPromptSchema end

"""
Expand Down Expand Up @@ -517,4 +534,4 @@ end
abstract type AbstractExtractedData end
Base.show(io::IO, x::AbstractExtractedData) = dump(io, x; maxdepth = 1)
"Check if the object is an instance of `AbstractExtractedData`"
isextracted(x) = x isa AbstractExtractedData
isextracted(x) = x isa AbstractExtractedData
22 changes: 21 additions & 1 deletion src/llm_openai_schema_defs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,15 @@ 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
function OpenAI.create_chat(schema::GoogleOpenAISchema,

Check warning on line 217 in src/llm_openai_schema_defs.jl

View check run for this annotation

Codecov / codecov/patch

src/llm_openai_schema_defs.jl#L217

Added line #L217 was not covered by tests
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...)

Check warning on line 224 in src/llm_openai_schema_defs.jl

View check run for this annotation

Codecov / codecov/patch

src/llm_openai_schema_defs.jl#L223-L224

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

Check warning on line 396 in src/llm_openai_schema_defs.jl

View check run for this annotation

Codecov / codecov/patch

src/llm_openai_schema_defs.jl#L396

Added line #L396 was not covered by tests
api_key::AbstractString,
docs,
model::AbstractString;
url::String = "https://generativelanguage.googleapis.com/v1beta",
kwargs...)
provider = CustomProvider(;

Check warning on line 402 in src/llm_openai_schema_defs.jl

View check run for this annotation

Codecov / codecov/patch

src/llm_openai_schema_defs.jl#L402

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

Check warning on line 405 in src/llm_openai_schema_defs.jl

View check run for this annotation

Codecov / codecov/patch

src/llm_openai_schema_defs.jl#L405

Added line #L405 was not covered by tests
end
function OpenAI.create_embeddings(schema::AzureOpenAISchema,
api_key::AbstractString,
docs,
Expand Down Expand Up @@ -441,4 +461,4 @@ function OpenAI.create_images(schema::TestEchoOpenAISchema,
schema.model_id = get(kwargs, :model, "")
schema.inputs = prompt
return schema
end
end

0 comments on commit 4ba85dc

Please sign in to comment.