Skip to content

Commit

Permalink
adds litellm gateway
Browse files Browse the repository at this point in the history
  • Loading branch information
akash5100 committed Oct 29, 2024
1 parent b4bbe3a commit c3f0327
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 27 deletions.
45 changes: 19 additions & 26 deletions apiserver/plane/app/views/external/base.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
# Python imports
import requests
# Python import
import os

# Third party imports
from openai import OpenAI
from rest_framework.response import Response
# Third party import
import litellm
import requests

from litellm import completion
from rest_framework import status
from rest_framework.response import Response

# Django imports
# Module import
from plane.app.permissions import ROLE, allow_permission
from plane.app.serializers import (ProjectLiteSerializer,
WorkspaceLiteSerializer)
from plane.db.models import Project, Workspace
from plane.license.utils.instance_value import get_configuration_value

# Module imports
from ..base import BaseAPIView
from plane.app.permissions import allow_permission, ROLE
from plane.db.models import Workspace, Project
from plane.app.serializers import (
ProjectLiteSerializer,
WorkspaceLiteSerializer,
)
from plane.license.utils.instance_value import get_configuration_value


class GPTIntegrationEndpoint(BaseAPIView):
Expand All @@ -32,7 +31,7 @@ def post(self, request, slug, project_id):
},
{
"key": "GPT_ENGINE",
"default": os.environ.get("GPT_ENGINE", "gpt-3.5-turbo"),
"default": os.environ.get("GPT_ENGINE", "gpt-4o-mini"),
},
]
)
Expand All @@ -56,11 +55,8 @@ def post(self, request, slug, project_id):

final_text = task + "\n" + prompt

client = OpenAI(
api_key=OPENAI_API_KEY,
)

response = client.chat.completions.create(
litellm.api_key = OPENAI_API_KEY
response = completion(
model=GPT_ENGINE,
messages=[{"role": "user", "content": final_text}],
)
Expand Down Expand Up @@ -95,7 +91,7 @@ def post(self, request, slug):
},
{
"key": "GPT_ENGINE",
"default": os.environ.get("GPT_ENGINE", "gpt-3.5-turbo"),
"default": os.environ.get("GPT_ENGINE", "gpt-4o-mini"),
},
]
)
Expand All @@ -119,11 +115,8 @@ def post(self, request, slug):

final_text = task + "\n" + prompt

client = OpenAI(
api_key=OPENAI_API_KEY,
)

response = client.chat.completions.create(
litellm.api_key = OPENAI_API_KEY
response = completion(
model=GPT_ENGINE,
messages=[{"role": "user", "content": final_text}],
)
Expand Down
2 changes: 1 addition & 1 deletion apiserver/requirements/base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ uvicorn==0.29.0
# sockets
channels==4.1.0
# ai
openai==1.25.0
litellm==1.51.0
# slack
slack-sdk==3.27.1
# apm
Expand Down

0 comments on commit c3f0327

Please sign in to comment.