GithubHelp home page GithubHelp logo

Comments (5)

64bit avatar 64bit commented on May 26, 2024 2

Please use fork for personal branches and contributions

from async-openai.

ifsheldon avatar ifsheldon commented on May 26, 2024 2

@64bit Why did you want Config: Clone in the first place? I looked through the codebase, it seems config.clone is never used. So, after removing the trait bound Clone in Config, you can just use a box like

pub struct Client {
    ...
    config: Box<dyn Config>,
    ...
}

No need to propagate the generics everywhere

from async-openai.

deipkumar avatar deipkumar commented on May 26, 2024

Also, I can't push branches:

(base) ➜  async-openai git:(deip/common-config-trait) git push --set-upstream origin deip/common-config-trait
ERROR: Permission to 64bit/async-openai.git denied to deipkumar.
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

Do I need to be added as a contributor?

from async-openai.

64bit avatar 64bit commented on May 26, 2024

I do not recall :)

Your idea of Box-ing it is actually good. Not sure what the rippling effects would be but worth exploring.

from async-openai.

schneiderfelipe avatar schneiderfelipe commented on May 26, 2024

Having a trait with associated type would allow the idea to work using only generics (no need for dynamic dispatch):

// Only Config seems to be polymorphic here.
// In any case, one can always have client: impl GenericClient<Config=C> below (see my comment on #125 below)
fn use_client<C: GenericConfig>(client: Client<C>) {
    let models = client.models();
    // ...
}

fn main() {
    let openai_config = OpenAIConfig::default();
    let openai_client = Client::with_config(openai_config);
    // No need for dynamic dispatch: the types in your problem are known at compile time. No boxing means zero cost dispatch at run time.
    use_client(openai_client);

    let azure_config = AzureConfig::default();
    let azure_client = Client::with_config(azure_config);
    use_client(azure_client);
}

Related to a comment of mine (#125 (comment)).

Keep in mind that the suggestion in the comment does allow dynamic dispatch using a simple design widely used in the Rust world (Iterators use it). It's just that dynamic dispatch is not required for solving the present issue.

from async-openai.

Related Issues (20)

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.