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

Add detector type to config #205

Closed
wants to merge 9 commits into from

Conversation

mdevino
Copy link
Collaborator

@mdevino mdevino commented Sep 20, 2024

This addresses #165.

I'm opening this as I'd like to get some feedback on what I've done so far.

Missing tasks:

  • Add ADR
  • Either use generics or create a helper function for text_contents(), text_generation()andtext_context_doc()` - as faux has a limitation when dealing with generics, I've rolled back this change and will work on it in a different PR.

@@ -129,16 +129,31 @@ impl From<tonic::Status> for Error {
pub struct HttpClient {
base_url: Url,
client: reqwest::Client,
detector_type: DetectorType,
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this okay, or should we have a "subclass" for detector clients?

Comment on lines +148 to +177
pub fn endpoint(&self) -> String {
let path = match self.detector_type {
DetectorType::Content => "/api/v1/text/contents",
DetectorType::Generated => "/api/v1/text/generation",
DetectorType::Chat => "/api/v1/text/context/chat",
DetectorType::Context => "/api/v1/text/context/doc",
};
self.base_url.join(path).unwrap().to_string()
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be better to return String, &'static str or &Url here?

#[cfg_attr(test, derive(PartialEq))]
#[serde(rename_all = "lowercase")]
pub enum DetectorType {
#[default]
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: even though this is set as default, "type" is mandatory on the YAML.

Signed-off-by: Mateus Devino <[email protected]>
Signed-off-by: Mateus Devino <[email protected]>
Signed-off-by: Mateus Devino <[email protected]>
Signed-off-by: Mateus Devino <[email protected]>
This reverts commit 96c5098.

Signed-off-by: Mateus Devino <[email protected]>
Signed-off-by: Mateus Devino <[email protected]>
Signed-off-by: Mateus Devino <[email protected]>
Copy link
Collaborator

@declark1 declark1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should not add detector concepts, e.g. detector_type and endpoint with detector-specific endpoints to HttpClient. This is meant to be a reusable abstraction for any HTTP API, e.g. we will be using it for the upcoming OpenAI chat & chat completions implementation.

@mdevino
Copy link
Collaborator Author

mdevino commented Sep 24, 2024

We should not add detector concepts, e.g. detector_type and endpoint with detector-specific endpoints to HttpClient. This is meant to be a reusable abstraction for any HTTP API, e.g. we will be using it for the upcoming OpenAI chat & chat completions implementation.

@declark1 Agreed, but not quite sure on how to go about this in a Rusty way. Should I move these out to a trait, or create a whole new struct?

@declark1
Copy link
Collaborator

declark1 commented Oct 3, 2024

Closing this as we are consolidating client-related changes into #220

@declark1 declark1 closed this Oct 3, 2024
@mdevino mdevino deleted the detector-type branch October 4, 2024 19:57
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.

2 participants