-
Notifications
You must be signed in to change notification settings - Fork 533
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
Track usage, add system prompt and timeout #388
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
rlouf
reviewed
Nov 24, 2023
rlouf
reviewed
Nov 24, 2023
It may be that one is connected to different models (GPT-3, GPT-4, …) in a
same application. Therefore better keep the counts separate. I don’t know
if that answers the question or is it something different?
El El vie, 24 nov 2023 a las 15:41, Rémi Louf ***@***.***>
escribió:
… ***@***.**** commented on this pull request.
------------------------------
In outlines/models/openai.py
<#388 (comment)>
:
> + def generate_chat(
+ self, prompt: Union[str, List[str]], config: OpenAIConfig
+ ) -> np.ndarray:
+ """Call the async function to generate a chat response and keeps track of usage data.
+
+ Parameters
+ ----------
+ prompt
+ A string used to prompt the model as user message
+ config
+ An instance of `OpenAIConfig`.
+
+ """
+ results, usage = generate_chat(prompt, self.system_prompt, self.client, config)
+
+ self.last_usage = OpenAIUsage(**usage)
I thought the idea of attaching the counts to the model class was good. Is
there any reason why you changed your mind?
—
Reply to this email directly, view it on GitHub
<#388 (review)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/A6ZVXMGZPGMVVM5C2U3A6YTYGCWY5AVCNFSM6AAAAAA7ZEZZ4WVHI2DSMVQWIX3LMV43YUDVNRWFEZLROVSXG5CSMV3GSZLXHMYTONBYGA3DCNZUGM>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
I’ve created a new method because the “cachable” function was called from
two different places, and that would’ve mean duplicating the code that
keeps track of the token consumption. (I am afc right now)
That being said, I am sure the solution can be improved :)
El El vie, 24 nov 2023 a las 15:40, Rémi Louf ***@***.***>
escribió:
… ***@***.**** commented on this pull request.
------------------------------
In outlines/models/openai.py
<#388 (comment)>
:
> @@ -158,7 +182,7 @@ def __call__(
)
)
if "gpt-" in self.config.model:
- return generate_chat(prompt, self.client, config)
+ return self.generate_chat(prompt, config)
What I would do instead is move the response + token count extraction here
instead of creating a new method.
—
Reply to this email directly, view it on GitHub
<#388 (review)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/A6ZVXMELHAP7DC76BA3RRY3YGCWWFAVCNFSM6AAAAAA7ZEZZ4WVHI2DSMVQWIX3LMV43YUDVNRWFEZLROVSXG5CSMV3GSZLXHMYTONBYGA3DANRUG4>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
HerrIvan
force-pushed
the
feature/openai_system_prompt
branch
2 times, most recently
from
November 25, 2023 09:33
1162c92
to
04c12cd
Compare
rlouf
reviewed
Nov 25, 2023
HerrIvan
force-pushed
the
feature/openai_system_prompt
branch
2 times, most recently
from
November 28, 2023 13:05
8b44cf4
to
27fcb19
Compare
HerrIvan
force-pushed
the
feature/openai_system_prompt
branch
from
December 4, 2023 14:33
27fcb19
to
ab09bb3
Compare
rlouf
force-pushed
the
feature/openai_system_prompt
branch
from
December 4, 2023 15:44
9ce5092
to
4039550
Compare
With the last version of this branch, the perscache serialization throws an error.
I haven't found any better solution that converting the usage object to a dict before returning it. Afaik, other solutions would imply modifying the serializer. In any case, thanks for the work you are putting in this PR. |
rlouf
changed the title
openai: usage tracking, sytem prompt and timeout
Track usage, add system prompt and timeout
Dec 6, 2023
rlouf
force-pushed
the
feature/openai_system_prompt
branch
from
December 6, 2023 12:41
3356d52
to
251fe81
Compare
I have updated the documentation and rebased the commits. Thank you for your contribution! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
A few improvements to the openai client.
Added a function to wrap the call to async generate_chat, s.t. it can process the usage data and add an additional parameter (the system prompt).
Added the system_prompt parameter: not groundbreaking, but just required a small change. It may reduce the need to do prompt composition. There was issue about this was closed as not planned. there no 'system' role in the gpt-3.5 when build prompt? #246
Added a timeout parameter: Without it sometimes the script was waiting for minutes and minutes for a 1-token response.
Added the processing of usage: Accumulated usage is stored within each instance of the client. Return the number of prompt and generated tokens for API providers #387