Skip to content

Commit

Permalink
fix(playground): block playground runs when app is readonly (#5538)
Browse files Browse the repository at this point in the history
* fix(playground): block playground runs when app is readonly

* remove logs
  • Loading branch information
Parker-Stafford authored Nov 25, 2024
1 parent 3a9c8e0 commit 7463069
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
15 changes: 15 additions & 0 deletions app/src/utils/errorUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,18 @@ const isErrorWithSource = (error: unknown): error is ErrorWithSource => {
);
};

const isErrorsArray = (errors: unknown): errors is { message: string }[] => {
return (
Array.isArray(errors) &&
errors.every(
(error) =>
typeof error === "object" &&
error !== null &&
typeof error.message === "string"
)
);
};

/**
* Extracts the error messages from a Relay subscription error.
* A relay subscription error contains a source property with an errors array.
Expand All @@ -96,5 +108,8 @@ export const getErrorMessagesFromRelaySubscriptionError = (
if (isErrorWithSource(error)) {
return error.source.errors.map((error) => error.message);
}
if (isErrorsArray(error)) {
return error.map((error) => error.message);
}
return null;
};
5 changes: 3 additions & 2 deletions src/phoenix/server/api/mutations/chat_mutations.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
from phoenix.datetime_utils import local_now, normalize_datetime
from phoenix.db import models
from phoenix.db.helpers import get_dataset_example_revisions
from phoenix.server.api.auth import IsNotReadOnly
from phoenix.server.api.context import Context
from phoenix.server.api.exceptions import BadRequest, CustomGraphQLError, NotFound
from phoenix.server.api.helpers.playground_clients import (
Expand Down Expand Up @@ -118,7 +119,7 @@ class ChatCompletionOverDatasetMutationPayload:

@strawberry.type
class ChatCompletionMutationMixin:
@strawberry.mutation
@strawberry.mutation(permission_classes=[IsNotReadOnly]) # type: ignore
@classmethod
async def chat_completion_over_dataset(
cls,
Expand Down Expand Up @@ -273,7 +274,7 @@ async def chat_completion_over_dataset(
payload.examples.append(example_payload)
return payload

@strawberry.mutation
@strawberry.mutation(permission_classes=[IsNotReadOnly]) # type: ignore
@classmethod
async def chat_completion(
cls, info: Info[Context, None], input: ChatCompletionInput
Expand Down
5 changes: 3 additions & 2 deletions src/phoenix/server/api/subscriptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

from phoenix.datetime_utils import local_now, normalize_datetime
from phoenix.db import models
from phoenix.server.api.auth import IsNotReadOnly
from phoenix.server.api.context import Context
from phoenix.server.api.exceptions import BadRequest, CustomGraphQLError, NotFound
from phoenix.server.api.helpers.playground_clients import (
Expand Down Expand Up @@ -87,7 +88,7 @@

@strawberry.type
class Subscription:
@strawberry.subscription
@strawberry.subscription(permission_classes=[IsNotReadOnly]) # type: ignore
async def chat_completion(
self, info: Info[Context, None], input: ChatCompletionInput
) -> AsyncIterator[ChatCompletionSubscriptionPayload]:
Expand Down Expand Up @@ -162,7 +163,7 @@ async def chat_completion(
info.context.event_queue.put(SpanInsertEvent(ids=(playground_project_id,)))
yield ChatCompletionSubscriptionResult(span=to_gql_span(db_span))

@strawberry.subscription
@strawberry.subscription(permission_classes=[IsNotReadOnly]) # type: ignore
async def chat_completion_over_dataset(
self, info: Info[Context, None], input: ChatCompletionOverDatasetInput
) -> AsyncIterator[ChatCompletionSubscriptionPayload]:
Expand Down

0 comments on commit 7463069

Please sign in to comment.