Skip to content

Commit 30ff446

Browse files
authored
Add username field in settings page and add a run_app method consumers (#174)
1 parent c1fcf02 commit 30ff446

File tree

4 files changed

+47
-22
lines changed

4 files changed

+47
-22
lines changed

llmstack/apps/apis.py

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -634,19 +634,23 @@ def patch(self, request, uid):
634634
# Find the versioned app data and update it
635635
app_data = {
636636
"name": request.data["name"] if "name" in request.data else versioned_app_data.data["name"],
637-
"type_slug": request.data["type_slug"]
638-
if "type_slug" in request.data
639-
else versioned_app_data.data["type_slug"],
640-
"description": request.data["description"]
641-
if "description" in request.data
642-
else versioned_app_data.data["description"],
637+
"type_slug": (
638+
request.data["type_slug"] if "type_slug" in request.data else versioned_app_data.data["type_slug"]
639+
),
640+
"description": (
641+
request.data["description"] if "description" in request.data else versioned_app_data.data["description"]
642+
),
643643
"config": request.data["config"] if "config" in request.data else versioned_app_data.data["config"],
644-
"input_fields": request.data["input_fields"]
645-
if "input_fields" in request.data
646-
else versioned_app_data.data["input_fields"],
647-
"output_template": request.data["output_template"]
648-
if "output_template" in request.data
649-
else versioned_app_data.data["output_template"],
644+
"input_fields": (
645+
request.data["input_fields"]
646+
if "input_fields" in request.data
647+
else versioned_app_data.data["input_fields"]
648+
),
649+
"output_template": (
650+
request.data["output_template"]
651+
if "output_template" in request.data
652+
else versioned_app_data.data["output_template"]
653+
),
650654
"processors": processed_processors_data,
651655
}
652656

@@ -888,6 +892,7 @@ def run_app_internal(
888892
request,
889893
platform=None,
890894
preview=False,
895+
version=None,
891896
):
892897
app = get_object_or_404(App, uuid=uuid.UUID(uid))
893898
app_owner = get_object_or_404(Profile, user=app.owner)
@@ -928,6 +933,12 @@ def run_app_internal(
928933
)
929934
.order_by("-created_at")
930935
.first()
936+
if version is None
937+
else AppData.objects.filter(
938+
app_uuid=app.uuid,
939+
version=version,
940+
is_draft=False,
941+
).first()
931942
)
932943

933944
# If we are running a published app, use the published app data

llmstack/base/serializers.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
class ProfileSerializer(serializers.ModelSerializer):
77
user_email = serializers.EmailField(source="user.email")
88
name = serializers.SerializerMethodField()
9+
username = serializers.CharField(source="user.username")
910
openai_key = serializers.SerializerMethodField()
1011
stabilityai_key = serializers.SerializerMethodField()
1112
cohere_key = serializers.SerializerMethodField()
@@ -60,6 +61,7 @@ class Meta:
6061
fields = [
6162
"name",
6263
"user_email",
64+
"username",
6365
"token",
6466
"openai_key",
6567
"stabilityai_key",

llmstack/client/src/pages/setting.jsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ const VisuallyHiddenInput = styled("input")({
4141
const settingsSchema = {
4242
type: "object",
4343
properties: {
44+
username: {
45+
type: "string",
46+
title: "Username",
47+
},
4448
openai_key: {
4549
type: "string",
4650
title: "OpenAI API Key",
@@ -81,6 +85,9 @@ const settingsSchema = {
8185
};
8286

8387
const settingsUiSchema = {
88+
username: {
89+
"ui:default": null,
90+
},
8491
openai_key: {
8592
"ui:widget": "password",
8693
"ui:default": "",
@@ -125,6 +132,7 @@ const settingsUiSchema = {
125132

126133
const SettingPage = () => {
127134
const [formData, setFormData] = useState({
135+
username: "",
128136
token: "",
129137
openai_key: "",
130138
stabilityai_key: "",
@@ -149,6 +157,7 @@ const SettingPage = () => {
149157
() => {},
150158
(profile) => {
151159
setFormData({
160+
username: profile.username,
152161
token: profile.token,
153162
openai_key: profile.openai_key,
154163
stabilityai_key: profile.stabilityai_key,

llmstack/server/consumers.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,17 @@ async def disconnect(self, close_code):
7676
# TODO: Close the stream
7777
pass
7878

79+
def _run_app(self, request_uuid, request, **kwargs):
80+
from llmstack.apps.apis import AppViewSet
81+
82+
return AppViewSet().run_app_internal_async(
83+
uid=self.app_id,
84+
session_id=self._session_id,
85+
request_uuid=request_uuid,
86+
request=request,
87+
preview=self.preview,
88+
)
89+
7990
async def _respond_to_event(self, text_data):
8091
from llmstack.apps.apis import AppViewSet
8192

@@ -94,16 +105,8 @@ async def _respond_to_event(self, text_data):
94105
request = await _build_request_from_input({"input": input, "stream": True}, self.scope)
95106
if is_ratelimited_fn(request, self._respond_to_event):
96107
raise Ratelimited("Rate limit reached.")
97-
# if is_usage_limited_fn(request, self._respond_to_event):
98-
# raise UsageLimitReached("Usage limit reached.")
99-
100-
output_stream = await AppViewSet().run_app_internal_async(
101-
self.app_id,
102-
self._session_id,
103-
request_uuid,
104-
request,
105-
self.preview,
106-
)
108+
109+
output_stream = await self._run_app(request_uuid=request_uuid, request=request)
107110
# Generate a uuid for the response
108111
response_id = str(uuid.uuid4())
109112

0 commit comments

Comments
 (0)