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

215 - feat: discord integration - part 1 #217

Merged
merged 9 commits into from
Aug 7, 2024

Conversation

MAbdurrehman1
Copy link
Contributor

@MAbdurrehman1 MAbdurrehman1 commented Aug 2, 2024

Closes #215

Notes

  • OpenAIClient relies on Response Format value of the prompt, therefore set it to json for the prompts that require machine readable results. At the moment they are github-pr-assessment and manual-assessment
  • discord_user_id and discord_username is implemented only on database level and Django admin. Leaving API support for this field as follow up work
  • Image generation requests are no longer tracked with PromptLayer because of the changes in promptlayer library
  • "Each /ia command will cost 1 TNB" requirement is not implemented and left as follow up work
  • "Set up the TNB charging system for each command" requirement is not implemented and left as follow up work
  • "Develop error handling for unmet requirements" is implemented partially, the rest is left as follow up work
  • "Future Improvements" are not implemented

@MAbdurrehman1 MAbdurrehman1 requested review from dmugtasimov and buckyroberts and removed request for dmugtasimov August 2, 2024 23:36
MAbdurrehman1 and others added 2 commits August 3, 2024 05:09
* Upgrade PromptLayer and switch to .run() method

* Simplify code

* Cleaning

* Removing old OpenAI client interface

* Update message format

* Cleaning

* Cleaning
return # Ignore messages from the bot itself

User = get_user_model()
user = await sync_to_async(User.objects.get)(id=1)
Copy link
Member

Choose a reason for hiding this comment

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

Need to fix this (id=1)

Copy link
Contributor

@dmugtasimov dmugtasimov left a comment

Choose a reason for hiding this comment

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

Added comments. Maybe I should work on some of them myself. Two major issue I see:

  1. Keep OpenAIClient since it is a good pattern to use (it encapsulates integration logic)
  2. Add unittests for the changes made

OpenAI = promptlayer.openai.OpenAI
promptlayer_client = PromptLayer(api_key=settings.PROMPTLAYER_API_KEY)
OpenAI = promptlayer_client.openai.OpenAI
client = OpenAI()
Copy link
Contributor

Choose a reason for hiding this comment

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

is client = OpenAI() used anywhere?

from thenewboston.general.models import CreatedModified
from thenewboston.general.utils.transfers import change_wallet_balance

promptlayer_client = PromptLayer(api_key=settings.PROMPTLAYER_API_KEY)
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's not create objects on module import. Promptplayer did a good thing deglobalizing the configuration of the client. Now we can move PromptLayer(api_key=settings.PROMPTLAYER_API_KEY) creation into OpenAIClient

I can work on refactoring it if you want

@@ -13,8 +12,9 @@

from ..serializers.openai_image import OpenAIImageSerializer

promptlayer.api_key = settings.PROMPTLAYER_API_KEY
OpenAI = promptlayer.openai.OpenAI
promptlayer_client = PromptLayer(api_key=settings.PROMPTLAYER_API_KEY)
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's not create objects on module import

@@ -69,15 +72,21 @@ def assess(self, save=True):
assessment_points = pull.assessment_points
assessment_explanation = pull.assessment_explanation
case ContributionType.MANUAL.value:
result = OpenAIClient.get_instance().get_chat_completion(
settings.GITHUB_MANUAL_CONTRIBUTION_ASSESSMENT_TEMPLATE_NAME,
response = promptlayer_client.run(
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's keep the logic inside OpenAIClient. So there is just one point of integration to deal with

Copy link
Contributor

Choose a reason for hiding this comment

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

let's not have this empty file

Copy link
Contributor

Choose a reason for hiding this comment

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

let's not have this empty file

Copy link
Contributor

Choose a reason for hiding this comment

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

would rather have it in thenewboston/discord/client.py or thenewboston/general/clients/discord.py

Copy link
Contributor

Choose a reason for hiding this comment

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

let's not have this empty file

@@ -1,50 +0,0 @@
import json
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's not delete this. It is very useful for testing and debugging.

return response.choices[0].message.content


class OpenAIClient:
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's keep dedicated wrapper class client approach. This is very convenient for integration purposes, since you always know the integration point and we to place common conversion logic (between more general interface of official client and what we actually need for our app). It encapsulates integration logic

@dmugtasimov
Copy link
Contributor

Also unitests are failing

@dmugtasimov dmugtasimov merged commit d37b813 into master Aug 7, 2024
1 check passed
Copy link

sentry-io bot commented Aug 7, 2024

Suspect Issues

This pull request was deployed and Sentry observed the following issues:

  • ‼️ Exception: PromptLayer had the following error while getting your prompt template: tasks.sync_contributions View Issue
  • ‼️ BadRequestError: Error code: 400 - {'type': 'error', 'error': {'type': 'invalid_request_error', 'message': 'messag... thenewboston.general.clients.llm in get_chat_co... View Issue

Did you find this useful? React with a 👍 or 👎

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.

Ia Discord Integration
3 participants