Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/JuliaML/OpenAI.jl
OpenAI API wrapper for Julia
https://github.com/JuliaML/OpenAI.jl
api-wrapper julia openai-api wrapper
Last synced: about 1 month ago
JSON representation
OpenAI API wrapper for Julia
- Host: GitHub
- URL: https://github.com/JuliaML/OpenAI.jl
- Owner: JuliaML
- License: mit
- Created: 2022-04-21T22:22:15.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-01-02T22:41:02.000Z (11 months ago)
- Last Synced: 2024-07-10T02:29:25.895Z (5 months ago)
- Topics: api-wrapper, julia, openai-api, wrapper
- Language: Julia
- Homepage: https://juliaml.github.io/OpenAI.jl/dev/
- Size: 289 KB
- Stars: 90
- Watchers: 7
- Forks: 16
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
- awesome-generative-ai-meets-julia-language - OpenAI.jl - A community-maintained Julia wrapper to the OpenAI API. (API SDKs / Model Providers)
README
# OpenAI API wrapper for Julia (Unofficial)
[![Stable](https://img.shields.io/badge/docs-stable-blue.svg)](https://juliaml.github.io/OpenAI.jl/stable/)
[![In Development](https://img.shields.io/badge/docs-dev-blue.svg)](https://juliaml.github.io/OpenAI.jl/dev/)## Overview
Provides a community maintained Julia wrapper to the OpenAI API.
For API functionality see [reference documentation](https://platform.openai.com/docs/api-reference).
Autogenerated documentation can be found here: https://juliaml.github.io/OpenAI.jl/dev/## Usage
```julia
using Pkg; Pkg.add("OpenAI")
```## Quick Start
1. Create an [OpenAI account](https://chat.openai.com/auth/login), if you don't already have one
2. Create a [secret API key](https://platform.openai.com/account/api-keys)
3. Choose a [model](https://platform.openai.com/docs/models) to interact with
__⚠️ We strongly suggest setting up your API key as an ENV variable__.
```julia
secret_key = ENV["OPENAI_API_KEY"]
model = "gpt-3.5-turbo"
prompt = "Say \"this is a test\""r = create_chat(
secret_key,
model,
[Dict("role" => "user", "content"=> prompt)]
)
println(r.response[:choices][begin][:message][:content])
```
returns
```julia
"This is a test."
```### Overriding default parameters
If you have a non-standard setup, such as a local LLM or third-party service that
conforms to the OpenAI interface, you can override parameters using the `OpenAIProvider`
struct in your application like this:```julia
using OpenAI
provider = OpenAI.OpenAIProvider(
api_key=ENV["OPENAI_API_KEY"],
base_url=ENV["OPENAI_BASE_URL_OVERRIDE"]
)
response = create_chat(
provider,
"gpt-3.5-turbo",
[Dict("role" => "user", "content" => "Write some ancient Greek poetry")]
)
```For more use cases [see tests](https://github.com/JuliaML/OpenAI.jl/tree/main/test).
## Feature requests
Feel free to open a PR, or file an issue if that's out of reach!