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

Track usage, add system prompt and timeout #388

Merged
merged 2 commits into from
Dec 6, 2023

Conversation

HerrIvan
Copy link
Contributor

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

outlines/models/openai.py Outdated Show resolved Hide resolved
outlines/models/openai.py Outdated Show resolved Hide resolved
@HerrIvan
Copy link
Contributor Author

HerrIvan commented Nov 24, 2023 via email

@HerrIvan
Copy link
Contributor Author

HerrIvan commented Nov 24, 2023 via email

@HerrIvan HerrIvan force-pushed the feature/openai_system_prompt branch 2 times, most recently from 1162c92 to 04c12cd Compare November 25, 2023 09:33
outlines/models/openai.py Outdated Show resolved Hide resolved
@HerrIvan HerrIvan force-pushed the feature/openai_system_prompt branch 2 times, most recently from 8b44cf4 to 27fcb19 Compare November 28, 2023 13:05
@rlouf rlouf linked an issue Dec 4, 2023 that may be closed by this pull request
@rlouf rlouf force-pushed the feature/openai_system_prompt branch from 9ce5092 to 4039550 Compare December 4, 2023 15:44
@HerrIvan
Copy link
Contributor Author

HerrIvan commented Dec 5, 2023

With the last version of this branch, the perscache serialization throws an error.

TypeError: Object of type CompletionUsage is not JSON serializable

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 rlouf changed the title openai: usage tracking, sytem prompt and timeout Track usage, add system prompt and timeout Dec 6, 2023
@rlouf rlouf force-pushed the feature/openai_system_prompt branch from 3356d52 to 251fe81 Compare December 6, 2023 12:41
@rlouf rlouf marked this pull request as ready for review December 6, 2023 12:50
@rlouf
Copy link
Member

rlouf commented Dec 6, 2023

I have updated the documentation and rebased the commits. Thank you for your contribution!

@rlouf rlouf merged commit fcfc48b into outlines-dev:main Dec 6, 2023
5 checks passed
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

Successfully merging this pull request may close these issues.

Return the number of prompt and generated tokens for API providers
2 participants