Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow set token manually in conversation #442

Open
carbaj03 opened this issue Sep 21, 2023 · 3 comments
Open

Allow set token manually in conversation #442

carbaj03 opened this issue Sep 21, 2023 · 3 comments

Comments

@carbaj03
Copy link
Collaborator

carbaj03 commented Sep 21, 2023

OpenAI.conversation { }

When I use conversation block it always calls the env system, but I want to set the token manually.

OpenAI.conversation(here_token) { }

The problem:

@JvmField val FromEnvironment: OpenAI = OpenAI()

suspend fun <A> conversation(block: suspend Conversation.() -> A): A =
      block(conversation(LocalVectorStore(FromEnvironment.DEFAULT_EMBEDDING)))

This always ends up calling the environment because the token is set to null by default.

class OpenAI(internal var token: String? = null, internal var host: String? = null)

@javipacheco
Copy link
Contributor

For now, the token is part of the model not part of the Conversation. If you want to use a model with your own token you should do something like this:

OpenAI.conversation {
    val chat = OpenAI(token = "your_token").DEFAULT_CHAT
    val response = promptMessage("What is the meaning of life?, model = chat)
    println(response)
}

Does that make sense for you?

@carbaj03
Copy link
Collaborator Author

There is a problem because to create OpenAI.conversation {, you call OpenAI with the token null always by default.
The second call OpenAI(token = "your_token").DEFAULT_CHAT it's okay.
It would be interesting if only one OpenAi() were created for the entire block. With Context Receivers this will be easier in the future.

@javipacheco
Copy link
Contributor

Yes, this is a known error. FromEnvironment should be lazy... and I agree with you about the conversation block

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants