Comments (12)
I sent #29 which POCs this on just the Completions
API, but while working on this I discovered OpenAI publishes an OpenAPI spec and fell into an existential crisis.
So I didn't complete the work for the rest of the APIs. Instead, I am now playing with @aj-foster's fantastic OpenAPI SDK generator to see if we can generate this automatically.
from openai.ex.
Ha, I came here to request this.
I'm "maintaining" a multi-tentant fork here: https://github.com/Miserlou/openai.ex/tree/mt but I wouldn't expect anybody else to use it, but suits me in the immediate term. Would really, really prefer to use the proper repo.
So yeah, +1
from openai.ex.
wow, awesome @feynmanliang! I'll take a look at the PR and try to extend it ASAP (next week I think..). Great idea to generate the client directly from the API schema, it would help a lot to stay in synchronisation with the official specifications. 👀
btw really nice project @aj-foster 🥇
from openai.ex.
@mgallo This seems to break the default api key behavior. I just updated and my code that previously worked now crashes, complaining that I did not provide an API key.
from openai.ex.
Hey! That would be a very interesting feature, I will try to implement it in one of the next releases.. . Unfortunately I'm a bit busy these days and it may take some time. @Miserlou I'll have a look at your repo to see if I can steal something 🔥, btw if you already have something ready (or pseudoready), feel free to open a PR!
from openai.ex.
Nice! My branch is hot trash, I just needed something immediately and did the first thing that came to mind, totally breaking the API. Ideally, the API will support both use cases and not break anything for anybody. It should be pretty easy other than the finickiness of how Elixir handles default arguments, I'm just a little busy with the thing I'm actually using the library for. But it shouldn't take @feynmanliang more than an hour, I'm sure. 😛
from openai.ex.
You overestimate my abilities... but I desperately need this, so let me see what I can do.
from openai.ex.
@feynmanliang That's great news! Happy to hear your feedback and figure out ways the library can be applicable to more use-cases. If you need anything, I'm always available in discussions.
from openai.ex.
hey! I finally found some time to work on this request, and it's live in v0.5.0!
You can find some documentation on how to use it here: https://github.com/mgallo/openai.ex#configuration-override
I preferred to create a struct for the config, that can be passed to the library's functions, so you can do:
config_override = %OpenAI.Config{ api_key: "test-api-key" } # this will return a config struct with "test-api-key" as api_key, and all the other config values taken from config.exs, so you don't need to set the defaults manually
# chat_completion with overriden config
OpenAI.chat_completion([
model: "gpt-3.5-turbo",
messages: [
%{role: "system", content: "You are a helpful assistant."},
%{role: "user", content: "Who won the world series in 2020?"},
%{role: "assistant", content: "The Los Angeles Dodgers won the World Series in 2020."},
%{role: "user", content: "Where was it played?"}
]
],
config_override # <--- pass the overriden configuration as last argument of the function
)
@feynmanliang thanks for your PR, it was helpful in developing the final feature! I preferred to pass a complete config object in order to be more flexible and improve the way http_options can be overwritten, but your code was very helpful.
Let me know your feedbacks. 🔥
from openai.ex.
Example:
iex(2)> OpenAI.Config.api_key()
"sk-E7LIV37888888888888888888888G7Q8N1gF4iGTal"
iex(3)> OpenAI.Config.org_key()
"org-BmAHS88888888888QqOV25j"
iex(4)> OpenAI.chat_completion(model: "gpt-3.5-turbo", temperature: 0.2, max_tokens: 2000, messages: [%{role: "user", content: "Hello. Tell me about yourself."}])
{:error,
%{
"error" => %{
"code" => nil,
"message" => "You didn't provide an API key. You need to provide your API key in an Authorization header using Bearer auth (i.e. Authorization: Bearer YOUR_KEY), or as the password field (with blank username) if you're accessing the API from your browser and are prompted for a username and password. You can obtain an API key from https://platform.openai.com/account/api-keys.",
"param" => nil,
"type" => "invalid_request_error"
}
}}
from openai.ex.
@jwilger thanks for reporting the issue, it's a silly bug with how I initialise the struct, which is valued at compile time 😓 . if you do a mix compile
it should take the right values of your config. I will release a fix shortly, sorry for the inconvenience
from openai.ex.
@jwilger solved in https://hex.pm/packages/openai/0.5.1
from openai.ex.
Related Issues (20)
- Chat Support HOT 5
- Update documentation version
- `mix-test-watch` dependency running in all environments
- Audio Transcription API support HOT 3
- Make URL target a config option to allow for easier local testing and mocking HOT 2
- Add compatibility with Azure's OpenAI API Endpoints HOT 1
- Handle nginx Error HOT 1
- What about replace Hackney with Tesla? HOT 4
- Library doesn't seem to load default config with Phoenix HOT 1
- add api_url param in init function
- Streaming example from docs doesnt work HOT 2
- Streaming example does not work in the shell HOT 4
- OpenAI Agents Behaviour
- API key error on prod: You didn't provide an API key. You need to provide your API key in an Authorization header HOT 3
- HTTPoison error cases aren't handled in Stream.new/1
- Bug: http_options configuration is not used HOT 2
- Feature: Atomize string keys in stream responses
- Intermittent Jason.DecodeError while streaming output HOT 6
- Remove applications key from MixProject.application/0
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from openai.ex.