-
Notifications
You must be signed in to change notification settings - Fork 1
VPC Chat completions API #74
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
Conversation
res = requests.post( | ||
f"{BASE_URL}/score", | ||
json={ | ||
"tlm_options": self._tlm_options, | ||
"completion": completion.model_dump(), | ||
**openai_kwargs, | ||
}, | ||
timeout=self._timeout, | ||
) | ||
|
||
res_json = res.json() | ||
|
||
return {"trustworthiness_score": res_json["tlm_metadata"]["score"]} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
couldn't our public implementation of score() be something like this instead?
response_text = completion.get_string_response()
messages = get_messages_list(openai_kwargs)
tlm_prompt = form_prompt_string(messages)
return tlm.get_trustworthiness_score(tlm_prompt, response_text)
or is there a specific reason to use a special backend API?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess with this ^ we'd ideally want to try and extract logprobs from the response
if they are available.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Backend API would allow for users to do scoring in VPC - otherwise tim.get_trustworthiness_score()
would be calling our SaaS TLM right?
Also this would allow better scoring for stuff like tool calls / structure outputs /other formats in the future I think if we retain the full completions object?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sounds good to me. If it helps you code better/faster, I think it's fine to have two different modules: One for SaaS, one for VPC
I vote our tutorial for this looks something like this: Easiest way to use TLM if you're using the Chat Completions API
UPDATE: IGNORE THIS, We will use openAI client package in this section and just point its URL at Cleanlab backend instead.
Notes from meActually I think the optimal way to offer workflow 2 above is a bit different, but my python skills / free time are lacking. I think the optimal way is: User decorates their call to: client.chat.completions.create() with a decorator that then appends the trust score as a key in this dict. The functionality would be equivalent to what is shown for workflow 2, but the developer experience would be cleaner (zero change of existing code, just add a decorator). Challenge is the decorator has to be associated with an already-instantiated TLMChatCompletion object. Ie something like:
|
|
||
res_json = res.json() | ||
|
||
return {"trustworthiness_score": res_json["tlm_metadata"]["trustworthiness_score"]} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wait why is this hardcoded like this? It should return everything that TLM.get_trustworthiness_score() returns.
Maybe I am confused about whether this PR is for VPC-TLM or SaaS-TLM.
If this PR is for VPC-TLM only, then all the code should be in a separate VPC module, so SaaS users are not confused by it.
I'd prefer to only review the SaaS-TLM version, and you can try to make the VPC-TLM API closely match that.
@@ -0,0 +1,67 @@ | |||
import os |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TODO: Confirm this VPC version matches our SaaS API as closely as we are easily able to. The analogous SaaS API is defined here:
for the decorator idea, a decorator factory should work
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
all that matters is the tutorial runs well, let's not focus on reviewing this
Note: very draft PR, mostly skeleton structure
Sample usage for
score
: