Skip to content

Commit

Permalink
Merge pull request #6 from tylerjthomas9/tyler-dev
Browse files Browse the repository at this point in the history
Prepare for registration
  • Loading branch information
tylerjthomas9 authored Mar 22, 2024
2 parents 8cb5615 + d0890e2 commit 6a5b5c8
Show file tree
Hide file tree
Showing 8 changed files with 303 additions and 63 deletions.
55 changes: 55 additions & 0 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: CI
on:
workflow_dispatch:
push:
branches:
- main
paths:
- '.github/workflows/CI.yml'
- 'test/**'
- 'src/**'
- 'Project.toml'
pull_request:
types: [opened, synchronize, reopened]
paths:
- '.github/workflows/CI.yml'
- 'test/**'
- 'src/**'
- 'Project.toml'
jobs:
test:
name: Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }} - ${{ github.event_name }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
version:
# - '1.6'
- '1'
# - 'nightly'
os:
- ubuntu-latest
arch:
- x64
include:
- os: windows-latest
version: '1'
arch: x64
- os: macos-latest
version: '1'
arch: x64
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: julia-actions/setup-julia@v1
with:
version: ${{ matrix.version }}
arch: ${{ matrix.arch }}
- uses: julia-actions/cache@v1 # https://github.com/julia-actions/cache
- uses: julia-actions/julia-buildpkg@v1
- uses: julia-actions/julia-runtest@v1
- uses: julia-actions/julia-processcoverage@v1
- uses: codecov/codecov-action@v3
with:
file: lcov.info
1 change: 0 additions & 1 deletion .github/workflows/Documenter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ on:
push:
branches:
- 'main'
- 'release-'
tags: '*'
pull_request:
release:
Expand Down
2 changes: 0 additions & 2 deletions .github/workflows/FormatCheck.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ on:
push:
branches:
- 'main'
- 'master'
- /^release-.*$/
tags: '*'
pull_request:
jobs:
Expand Down
15 changes: 15 additions & 0 deletions .github/workflows/TagBot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: TagBot
on:
issue_comment:
types:
- created
workflow_dispatch:
jobs:
TagBot:
if: github.event_name == 'workflow_dispatch' || github.actor == 'JuliaTagBot'
runs-on: ubuntu-latest
steps:
- uses: JuliaRegistries/TagBot@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
ssh: ${{ secrets.DOCUMENTER_KEY }}
17 changes: 16 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[![Aqua QA](https://raw.githubusercontent.com/JuliaTesting/Aqua.jl/master/badge.svg)](https://github.com/JuliaTesting/Aqua.jl)
[![CI](https://github.com/tylerjthomas9/GoogleGenAI.jl/actions/workflows/CI.yml/badge.svg)](https://github.com/tylerjthomas9/GoogleGenAI.jl/actions/workflows/CI.yml)
[![Code Style: Blue](https://img.shields.io/badge/code%20style-blue-4495d1.svg)](https://github.com/invenia/BlueStyle)
[![Docs](https://img.shields.io/badge/docs-dev-blue.svg)](https://tylerjthomas9.github.io/GoogleGenAI.jl)

Expand Down Expand Up @@ -108,14 +109,28 @@ outputs

```julia
using GoogleGenAI
embeddings = create_embeddings(ENV["GOOGLE_API_KEY"], "gemini-pro", "Hello")
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
Expand Down
128 changes: 127 additions & 1 deletion docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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)
```
Loading

0 comments on commit 6a5b5c8

Please sign in to comment.