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

Prompt service v2 refactor #1149

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
Open

Conversation

Deepak-Kesavan
Copy link
Contributor

@Deepak-Kesavan Deepak-Kesavan commented Feb 24, 2025

What

  • Prompt service v2 refactor

Why

  • To organize code and make it easier to develop and maintain.

How

Can this PR break any existing features. If yes, please list possible items. If no, please explain why. (PS: Admins do not merge the PR without this section filled)

Database Migrations

Env Config

Relevant Docs

Related Issues or PRs

Dependencies Versions

Notes on Testing

Screenshots

Checklist

I have read and understood the Contribution Guidelines.

@Deepak-Kesavan Deepak-Kesavan marked this pull request as ready for review February 25, 2025 02:14
@Deepak-Kesavan Deepak-Kesavan changed the title Prompt service v2 initial changes Prompt service v2 refactor Feb 25, 2025
Comment on lines +37 to +43
log_level = env.get("LOG_LEVEL", LogLevel.WARN.value)
if log_level == LogLevel.DEBUG.value:
app.logger.setLevel(logging.DEBUG)
elif log_level == LogLevel.INFO.value:
app.logger.setLevel(logging.INFO)
else:
app.logger.setLevel(logging.WARNING)
Copy link
Contributor

Choose a reason for hiding this comment

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

NIT: We could pass the log level and handle it with a simple conversion in the dictConfig call itself


@health_bp.route("/health", methods=["GET"])
def health_check() -> str:
return "OK"
Copy link
Contributor

Choose a reason for hiding this comment

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

NIT: Do you know where we use this API? Should we ensure that the responses are all of the same format as a JSON?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure if it is used anywhere. Just added it because it was there in the existing code.

Copy link
Contributor

Choose a reason for hiding this comment

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

NIT: You could use this file to execute code once

  • create an instance of the app
  • creating a db instance maybe
  • configure logging
  • loading plugins .etc.

"""Get the plugin metadata by name."""
return self.plugins.get(name, {})

def initialize_plugin_endpoints(self) -> None:
Copy link
Contributor

Choose a reason for hiding this comment

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

@Deepak-Kesavan over here we expose all the plugins used. Do you think this logic can be moved into the cloud repo? Similar to how we load the plugins can we pass self.app into the plugin?
cc: @hari-kuriakose

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@chandrasekharan-zipstack It is fine because name of the plugins will be exposed anyway where it is used and it can't be avoided.

Also I am planning to handle endpoint init using blueprints for plugins in a separate PR.

@app.before_request
def log_request_info():
"""Log request details."""
app.logger.info(f"Request Path: {request.path} | Method: {request.method}")
Copy link
Contributor

Choose a reason for hiding this comment

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

NIT: @Deepak-Kesavan it might help to log the request payload as well maybe (as long as it doesn't contain anything sensitive)


load_dotenv()

dictConfig(
Copy link
Contributor

Choose a reason for hiding this comment

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

Would be useful if we can log a requestID as well with a filter. Check this. Ideally we should obtain the requestID from backend / tool - but for the time being if its not there let's create one to help correlate logs within this service

PSKeys.METRICS: metrics,
}
return response
except APIError as api_error:
Copy link
Contributor

Choose a reason for hiding this comment

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

NIT: @Deepak-Kesavan can we move such exception handling into the function being called itself rather than nesting the code further here?

metadata[PSKeys.CONTEXT][output[PSKeys.NAME]] = (
AnswerPromptService.get_cleaned_context(context)
)
else:
Copy link
Contributor

Choose a reason for hiding this comment

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

NIT: Add a comment to indicate this is for chunking based calls

f"Processing prompt type: {output[PSKeys.TYPE]}",
)

if output[PSKeys.TYPE] == PSKeys.NUMBER:
Copy link
Contributor

Choose a reason for hiding this comment

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

NIT: We could move this handling based on cell type into a separate function to reduce cyclomatic complexity

Copy link
Contributor

filepath function $$\textcolor{#23d18b}{\tt{passed}}$$ SUBTOTAL
$$\textcolor{#23d18b}{\tt{runner/src/unstract/runner/clients/test\_docker.py}}$$ $$\textcolor{#23d18b}{\tt{test\_logs}}$$ $$\textcolor{#23d18b}{\tt{1}}$$ $$\textcolor{#23d18b}{\tt{1}}$$
$$\textcolor{#23d18b}{\tt{runner/src/unstract/runner/clients/test\_docker.py}}$$ $$\textcolor{#23d18b}{\tt{test\_cleanup}}$$ $$\textcolor{#23d18b}{\tt{1}}$$ $$\textcolor{#23d18b}{\tt{1}}$$
$$\textcolor{#23d18b}{\tt{runner/src/unstract/runner/clients/test\_docker.py}}$$ $$\textcolor{#23d18b}{\tt{test\_cleanup\_skip}}$$ $$\textcolor{#23d18b}{\tt{1}}$$ $$\textcolor{#23d18b}{\tt{1}}$$
$$\textcolor{#23d18b}{\tt{runner/src/unstract/runner/clients/test\_docker.py}}$$ $$\textcolor{#23d18b}{\tt{test\_client\_init}}$$ $$\textcolor{#23d18b}{\tt{1}}$$ $$\textcolor{#23d18b}{\tt{1}}$$
$$\textcolor{#23d18b}{\tt{runner/src/unstract/runner/clients/test\_docker.py}}$$ $$\textcolor{#23d18b}{\tt{test\_get\_image\_exists}}$$ $$\textcolor{#23d18b}{\tt{1}}$$ $$\textcolor{#23d18b}{\tt{1}}$$
$$\textcolor{#23d18b}{\tt{runner/src/unstract/runner/clients/test\_docker.py}}$$ $$\textcolor{#23d18b}{\tt{test\_get\_image}}$$ $$\textcolor{#23d18b}{\tt{1}}$$ $$\textcolor{#23d18b}{\tt{1}}$$
$$\textcolor{#23d18b}{\tt{runner/src/unstract/runner/clients/test\_docker.py}}$$ $$\textcolor{#23d18b}{\tt{test\_get\_container\_run\_config}}$$ $$\textcolor{#23d18b}{\tt{1}}$$ $$\textcolor{#23d18b}{\tt{1}}$$
$$\textcolor{#23d18b}{\tt{runner/src/unstract/runner/clients/test\_docker.py}}$$ $$\textcolor{#23d18b}{\tt{test\_get\_container\_run\_config\_without\_mount}}$$ $$\textcolor{#23d18b}{\tt{1}}$$ $$\textcolor{#23d18b}{\tt{1}}$$
$$\textcolor{#23d18b}{\tt{runner/src/unstract/runner/clients/test\_docker.py}}$$ $$\textcolor{#23d18b}{\tt{test\_run\_container}}$$ $$\textcolor{#23d18b}{\tt{1}}$$ $$\textcolor{#23d18b}{\tt{1}}$$
$$\textcolor{#23d18b}{\tt{TOTAL}}$$ $$\textcolor{#23d18b}{\tt{9}}$$ $$\textcolor{#23d18b}{\tt{9}}$$

Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
1 Security Hotspot
47.3% Duplication on New Code (required ≤ 3%)

See analysis details on SonarQube Cloud

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