diff --git a/docs/src/index.md b/docs/src/index.md index 13b4859..423e40f 100644 --- a/docs/src/index.md +++ b/docs/src/index.md @@ -20,6 +20,9 @@ Pkg> add https://github.com/tylerjthomas9/GoogleGenAI.jl/ Create a [secret API key in Google AI Studio](https://makersuite.google.com/) + +### Generate Content + ```julia using GoogleGenAI @@ -29,7 +32,130 @@ prompt = "Hello" response = generate_content(secret_key, model, prompt) println(response.text) ``` -returns +outputs ```julia "Hello there! How may I assist you today? Feel free to ask me any questions you may have or give me a command. I'm here to help! 😊" ``` + +```julia +response = generate_content(secret_key, model, prompt; max_output_tokens=10) +println(response.text) +``` +outputs +```julia +"Hello! How can I assist you today?" +``` + +```julia +using GoogleGenAI + +secret_key = ENV["GOOGLE_API_KEY"] +model = "gemini-pro-vision" +prompt = "What is this image?" +image_path = "test/example.jpg" +response = generate_content(secret_key, model, prompt, image_path) +println(response.text) +``` +outputs +```julia +"The logo for the Julia programming language." +``` + +### Multi-turn conversations + +```julia +# Define the provider with your API key (placeholder here) +provider = GoogleProvider(api_key=ENV["GOOGLE_API_KEY"]) +model_name = "gemini-pro" +conversation = [ + Dict(:role => "user", :parts => [Dict(:text => "When was Julia 1.0 released?")]) +] + +response = generate_content(provider, model_name, conversation) +push!(conversation, Dict(:role => "model", :parts => [Dict(:text => response.text)])) +println("Model: ", response.text) + +push!(conversation, Dict(:role => "user", :parts => [Dict(:text => "Who created the language?")])) +response = generate_content(provider, model_name, conversation, max_output_tokens=100) +println("Model: ", response.text) +``` +outputs +```julia +"Model: August 8, 2018" + +"Model: Jeff Bezanson, Alan Edelman, Viral B. Shah, Stefan Karpinski, and Keno Fischer + +Julia Computing, Inc. is the company that provides commercial support for Julia." +``` + +### Count Tokens +```julia +using GoogleGenAI +n_tokens = count_tokens(ENV["GOOGLE_API_KEY"], "gemini-pro", "Hello") +println(n_tokens) +``` +outputs +```julia +1 +``` + +### Create Embeddings + +```julia +using GoogleGenAI +embeddings = embed_content(ENV["GOOGLE_API_KEY"], "embedding-001", "Hello") +println(size(embeddings.values)) +``` +outputs +```julia +(768,) +``` + +```julia +using GoogleGenAI +embeddings = embed_content(ENV["GOOGLE_API_KEY"], "embedding-001", ["Hello", "world"]) +println(embeddings.response_status) +println(size(embeddings.values[1])) +println(size(embeddings.values[2])) +``` +outputs +```julia +200 +(768,) +(768,) +``` + +### List Models + +```julia +using GoogleGenAI +models = list_models(ENV["GOOGLE_API_KEY"]) +for m in models + if "generateContent" in m[:supported_generation_methods] + println(m[:name]) + end +end +``` +outputs +```julia +gemini-pro +gemini-pro-vision +``` + +### Safety Settings + +More information about the safety settings can be found [here](https://ai.google.dev/docs/safety_setting_gemini). + +```julia +using GoogleGenAI +secret_key = ENV["GOOGLE_API_KEY"] +safety_settings = [ + Dict("category" => "HARM_CATEGORY_HATE_SPEECH", "threshold" => "HARM_BLOCK_THRESHOLD_UNSPECIFIED"), + Dict("category" => "HARM_CATEGORY_SEXUALLY_EXPLICIT", "threshold" => "BLOCK_ONLY_HIGH"), + Dict("category" => "HARM_CATEGORY_HARASSMENT", "threshold" => "BLOCK_MEDIUM_AND_ABOVE"), + Dict("category" => "HARM_CATEGORY_DANGEROUS_CONTENT", "threshold" => "BLOCK_LOW_AND_ABOVE") +] +model = "gemini-pro" +prompt = "Hello" +response = generate_content(secret_key, model, prompt; safety_settings=safety_settings) +```