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(prompts): graphql types for tools, output_schema #5849

Merged
merged 2 commits into from
Dec 30, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
12 changes: 10 additions & 2 deletions app/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -1091,6 +1091,10 @@ type JSONPromptMessage {
content: JSON!
}

type JSONSchema {
schema: JSON!
}

type LabelFraction {
label: String!
fraction: Float!
Expand Down Expand Up @@ -1448,8 +1452,8 @@ type PromptVersion implements Node {
templateFormat: PromptTemplateFormat!
template: PromptTemplate!
invocationParameters: JSON
tools: JSON
outputSchema: JSON
tools: [ToolDefinition!]!
outputSchema: JSONSchema
modelName: String!
modelProvider: String!
tags: [PromptVersionTag!]!
Expand Down Expand Up @@ -1850,6 +1854,10 @@ type ToolCallChunk implements ChatCompletionSubscriptionPayload {
function: FunctionCallChunk!
}

type ToolDefinition {
definition: JSON!
}

type Trace implements Node {
"""The Globally Unique ID of this object"""
id: GlobalID!
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion app/src/pages/prompt/promptVersionLoader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ export async function promptVersionLoader(args: LoaderFunctionArgs) {
description
invocationParameters
modelName
tools
tools {
definition
}
user
}
}
Expand Down
9 changes: 9 additions & 0 deletions src/phoenix/server/api/types/JSONSchema.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import strawberry
from strawberry.scalars import JSON


@strawberry.type
class JSONSchema:
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this might be largely un-necessary

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But it might be nice to have a "container" for this in case there are non-json schemas?

Copy link
Contributor

Choose a reason for hiding this comment

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

It may be valuable so we can union type for Json schema conforming json, vs non conforming json (schema-less)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

maybe something like that yeah

"""A JSON schema definition used to guide an LLM's output"""

schema: JSON
63 changes: 39 additions & 24 deletions src/phoenix/server/api/types/Prompt.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
TextPromptMessage,
)

from .JSONSchema import JSONSchema
from .PromptVersion import PromptTemplateFormat, PromptTemplateType, PromptVersion
from .ToolDefinition import ToolDefinition


@strawberry.type
Expand Down Expand Up @@ -64,33 +66,30 @@ async def prompt_versions(
template_format=PromptTemplateFormat.MUSTACHE,
template=template,
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",
},
tools=[
ToolDefinition(
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"],
},
}
"required": ["location"],
},
}
],
},
)
],
model_name="gpt-4o",
model_provider="openai",
),
Expand All @@ -103,6 +102,22 @@ async def prompt_versions(
template=template,
model_name="gpt-4o",
model_provider="openai",
tools=[],
output_schema=JSONSchema(
schema={
"type": "json_schema",
"json_schema": {
"name": "response",
"schema": {
"type": "object",
"properties": {},
"required": [],
"additionalProperties": False,
},
"strict": True,
},
}
),
),
]

Expand Down
6 changes: 4 additions & 2 deletions src/phoenix/server/api/types/PromptVersion.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
from phoenix.server.api.context import Context
from phoenix.server.api.types.PromptVersionTemplate import PromptTemplate

from .JSONSchema import JSONSchema
from .PromptVersionTag import PromptVersionTag
from .ToolDefinition import ToolDefinition


@strawberry.enum
Expand All @@ -36,8 +38,8 @@ class PromptVersion(Node):
template_format: PromptTemplateFormat
template: PromptTemplate
invocation_parameters: Optional[JSON] = None
tools: Optional[JSON] = None
output_schema: Optional[JSON] = None
tools: list[ToolDefinition]
output_schema: Optional[JSONSchema] = None
model_name: str
model_provider: str

Expand Down
9 changes: 9 additions & 0 deletions src/phoenix/server/api/types/ToolDefinition.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import strawberry
from strawberry.scalars import JSON


@strawberry.type
class ToolDefinition:
"""The definition of a tool that a generative tool can invoke."""

definition: JSON
Loading