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

feat: Spike out dummy PromptVersion connection #5767

Merged
merged 5 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions app/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -1374,6 +1374,7 @@ type Prompt implements Node {
name: String!
description: String
createdAt: DateTime!
promptVersions(first: Int = 50, last: Int, after: String, before: String): PromptVersionConnection!
}

"""A connection to a list of items."""
Expand Down Expand Up @@ -1402,6 +1403,50 @@ type PromptResponse {
response: String
}

enum PromptTemplateFormat {
MUSTACHE
FSTRING
NONE
}

enum PromptTemplateType {
STRING
CHAT
}

type PromptVersion implements Node {
"""The Globally Unique ID of this object"""
id: GlobalID!
user: String
description: String!
templateType: PromptTemplateType!
templateFormat: PromptTemplateFormat!
template: JSON!
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we can make this a union type and give it a bit more structure

invocationParameters: JSON
tools: JSON
outputSchema: JSON
modelName: String!
modelProvider: String!
}

"""A connection to a list of items."""
type PromptVersionConnection {
"""Pagination data for this connection"""
pageInfo: PageInfo!

"""Contains the nodes in this connection"""
edges: [PromptVersionEdge!]!
}

"""An edge in a connection."""
type PromptVersionEdge {
"""A cursor for use in pagination"""
cursor: String!

"""The item at the end of the edge"""
node: PromptVersion!
}

type Query {
modelProviders: [GenerativeProvider!]!
models(input: ModelsInput = null): [GenerativeModel!]!
Expand Down
2 changes: 1 addition & 1 deletion src/phoenix/server/api/queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,7 @@ async def viewer(self, info: Info[Context, None]) -> Optional[User]:
return to_gql_user(user)

@strawberry.field
def prompts(
async def prompts(
self,
info: Info[Context, None],
first: Optional[int] = 50,
Expand Down
98 changes: 97 additions & 1 deletion src/phoenix/server/api/types/Prompt.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,25 @@
# Part of the Phoenix PromptHub feature set

from datetime import datetime
from typing import Optional

import strawberry
from strawberry.relay import Node, NodeID
from strawberry import UNSET
from strawberry.relay import Connection, Node, NodeID
from strawberry.types import Info

from phoenix.server.api.context import Context
from phoenix.server.api.types.pagination import (
ConnectionArgs,
CursorString,
connection_from_list,
)

from .PromptVersion import (
PromptTemplateFormat,
PromptTemplateType,
PromptVersion,
)


@strawberry.type
Expand All @@ -11,3 +28,82 @@ class Prompt(Node):
name: str
description: Optional[str]
created_at: datetime

@strawberry.field
async def prompt_versions(
self,
info: Info[Context, None],
first: Optional[int] = 50,
last: Optional[int] = UNSET,
after: Optional[CursorString] = UNSET,
before: Optional[CursorString] = UNSET,
) -> Connection[PromptVersion]:
args = ConnectionArgs(
first=first,
after=after if isinstance(after, CursorString) else None,
last=last,
before=before if isinstance(before, CursorString) else None,
)

dummy_data = [
PromptVersion(
id_attr=2,
user="alice",
description="A dummy prompt version",
template_type=PromptTemplateType.CHAT,
template_format=PromptTemplateFormat.MUSTACHE,
template={
"_version": "messages-v1",
"messages": [
{"role": "user", "content": "Hello what's the weather in Antarctica like?"}
],
},
invocation_parameters={"temperature": 0.5},
tools={
"_version": "tools-v1",
"tools": [
{
"definition": {
"name": "get_current_weather",
"description": "Get the current weather in a given location",
"parameters": {
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "A location in the world",
},
"unit": {
"type": "string",
"enum": ["celsius", "fahrenheit"],
"default": "fahrenheit",
"description": "The unit of temperature",
},
},
"required": ["location"],
},
}
}
],
},
model_name="gpt-4o",
model_provider="openai",
),
PromptVersion(
id_attr=1,
user="alice",
description="A dummy prompt version",
template_type=PromptTemplateType.CHAT,
template_format=PromptTemplateFormat.MUSTACHE,
template={
"_version": "messages-v1",
"messages": [
{"role": "user", "content": "Hello what's the weather in Antarctica like?"}
],
},
model_name="gpt-4o",
model_provider="openai",
),
]

return connection_from_list(data=dummy_data, args=args)
37 changes: 37 additions & 0 deletions src/phoenix/server/api/types/PromptVersion.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Part of the Phoenix PromptHub feature set

from enum import Enum
from typing import Optional

import strawberry
from strawberry import UNSET
from strawberry.relay import Node, NodeID
from strawberry.scalars import JSON


@strawberry.enum
class PromptTemplateType(str, Enum):
STRING = "str"
CHAT = "chat"


@strawberry.enum
class PromptTemplateFormat(str, Enum):
MUSTACHE = "mustache"
FSTRING = "fstring"
mikeldking marked this conversation as resolved.
Show resolved Hide resolved
NONE = "none"


@strawberry.type
class PromptVersion(Node):
id_attr: NodeID[int]
user: Optional[str]
description: str
template_type: PromptTemplateType
template_format: PromptTemplateFormat
template: JSON
invocation_parameters: Optional[JSON] = UNSET
tools: Optional[JSON] = UNSET
output_schema: Optional[JSON] = UNSET
model_name: str
model_provider: str
Loading