Code Monkey home page Code Monkey logo

openai's Introduction

openai

crates.io Rust workflow

An unofficial Rust library for the OpenAI API.

Warning

There may be breaking changes between versions while in alpha. See Implementation Progress.

Core Principles

  • Modularity
  • Library, not a wrapper
  • Idiomatic Rust
  • Environmental variables should be the prioritized method of authentication, but not the only way to do things

Examples

Examples can be found in the examples directory.

As the package is still a work in progress and there may be breaking changes, examples are not available for all the crate's functionality.

Currently, there are examples for the completions module and the chat module. For other modules, refer to the tests submodules for some reference.

Implementation Progress

██████████ Models

████████░░ Completions (Function calling is supported)

████████░░ Chat

██████████ Edits

░░░░░░░░░░ Images

█████████░ Embeddings

░░░░░░░░░░ Audio

███████░░░ Files

░░░░░░░░░░ Fine-tunes

██████████ Moderations

Contributing

All contributions are welcome. Unit tests are encouraged.

Fork Notice

This package was initially developed by Valentine Briese. As the original repo was archived, this is a fork and continuation of the project.

openai's People

Contributors

albertmarashi avatar antonio-hickey avatar ashleygwilliams avatar beyera avatar dependabot[bot] avatar kcberg avatar n8behavior avatar netr avatar notdanilo avatar rellfy avatar rukolahasser avatar scottbot95 avatar valentinegb avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

openai's Issues

openai::completions::CompletionBuilder::presence_penalty requests i8 but docs request a float between -2.0 and 2.0

Bug Description

https://docs.rs/openai/1.0.0-alpha.9/openai/completions/struct.CompletionBuilder.html#method.presence_penalty

presence penalty and frequency penalty are i8 but the API requests a float between -2.0 and 2.0.

I have a slight suspicion that it might be applying some scaling (i.e. dividing by 10.0 before sending) but I can't find any proof on the code of this.

Anyway, whatever it is, it needs to be either corrected or clarified. If it's really sending an integer, the problem is that the only options here are -2,-1,0,1,2; if it's actually sending a fractional number, the documentation doesn't explain.

There might be other methods affected by this issue in this repo. I'd recommend checking if it applies. For example frequency_penalty in this struct seems to have the same problem. It's possible this also is on other APIs too.

Terminal Output

No response

Reproduction Steps

https://docs.rs/openai/1.0.0-alpha.9/openai/completions/struct.CompletionBuilder.html#method.presence_penalty

Try to send an API request with presence penalty of 0.32. Won't compile..

Expected Behavior

https://docs.rs/openai/1.0.0-alpha.9/openai/completions/struct.CompletionBuilder.html#method.presence_penalty

API accepting a float, fixed number or docs updated to explain how decimal numbers can be sent to the API.

Workaround

No response

Library Version

1.0.0-alpha.9

rustc Version

rustc 1.68.2 (9eb3afe9e 2023-03-27)

cargo Version

cargo 1.68.2 (6feb7c9cf 2023-03-26)

Platform

Linux

Make BASE_URL customizable

Problem

I prefer not using OpenAI's official API endpoint https://api.openai.com/v1/, but some mirror site like chatanywhere/GPT_API_free.

Solution

Seems that this feature is easy to implement, just make BASE_URL in lib.rs customizable -- export a function like set_key; for example set_base_url.

Alternatives

No response

derive core functionality in structs

Problem

ive been using this api for a while and one of the most infuriating things is that i cant copy or partialeq some structs/enums.
as an example, the ChatCompletionBuilder doesnt derive Clone, and the enum ChatCompletionMessageRole doesnt derive partialeq.

Solution

add core derives to all structs/enums

Alternatives

No response

Parallel function calling.

Problem

OpenAI allows a single ChatCompletionMessage to contain multiple function calls, as is presented here:
https://platform.openai.com/docs/guides/function-calling/parallel-function-calling.
However, the current implementation only allows for a single Function Call to be present per response.

from source:

pub function_call: Option<ChatCompletionFunctionCall>

(https://github.com/rellfy/openai/blob/master/src/chat.rs#L60)

Solution

Given my lack of knowledge about the API in use, changing

pub function_call: Option<ChatCompletionFunctionCall>

to

pub function_call: Vec<ChatCompletionFunctionCall>

should resolve the problem, though I am not familiar with the function calling API enough to be sure that that would work

Alternatives

No response

Missing variant ChatCompletionMessageRole::Function needed to complete function calls in chats

In the OpenAI docs, they describe the function call flow here
https://platform.openai.com/docs/guides/gpt/function-calling

TL;DR is that after the model tells you a function to call, and you call it, then you add a message to the chain with the role of function with the name and result of the function.

So basically need to be able to create this

ChatCompletionMessage {
    role: ChatCompletionMessageRole::Function,
    name: Some("update_ability_score".into()),
    content: Some("Your constitution has dropped by 2 points".into()),
    function_call: None, //docs say use None, but this seems odd
});

I'm able to use the rest of the function calling, works great! Seem like the role just never got added here

pub enum ChatCompletionMessageRole {

Is there a better way to do this that I'm missing or should I put up a PR to add this?

Implement Assistants & Threads API

Problem

Implement new assistants API released by OpenAI

Solution

Implement new assistants API released by OpenAI

Alternatives

No response

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.