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: Add PromptTemplate type #5787

Merged
merged 13 commits into from
Dec 20, 2024

Conversation

anticorrelator
Copy link
Contributor

resolves #5771

@dosubot dosubot bot added the size:XXL This PR changes 1000+ lines, ignoring generated files. label Dec 19, 2024
@anticorrelator anticorrelator changed the base branch from main to prompts December 19, 2024 16:29
@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. and removed size:XXL This PR changes 1000+ lines, ignoring generated files. labels Dec 19, 2024
@@ -29,7 +31,7 @@ class PromptVersion(Node):
description: str
template_type: PromptTemplateType
template_format: PromptTemplateFormat
template: JSON
template: PromptTemplateVersion
Copy link
Contributor

Choose a reason for hiding this comment

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

template_version?

Copy link
Contributor

Choose a reason for hiding this comment

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

This is the wrong type

@@ -1086,6 +1086,11 @@ type JSONInvocationParameter implements InvocationParameterBase {
defaultValue: JSON
}

type JSONPromptMessageGQL {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we remove GQL from the type names in the GraphQL schema?

Copy link
Contributor

Choose a reason for hiding this comment

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

Agreed

AI = "ai" # E.g. the assistant. Normalize to AI for consistency.


class PromptStringTemplate(BaseModel):
Copy link
Contributor

Choose a reason for hiding this comment

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

I see the appeal of keeping the Pydantic models next to their corresponding GraphQL types, but will these models also be needed for the REST API?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah they will - let's de-couple

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@axiomofjoy I will say decoupling these into different files might lead to some weird circular import stuff

Copy link
Contributor

Choose a reason for hiding this comment

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

You can reduce the circular imports by just having the conversion code be functional in its own file and not be attached to classes

return TextPromptMessageGQL.from_model(self)


class JSONPromptMessage(BaseModel):
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need both to and from methods?

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 eventually but we're feeling it out


class PromptMessagesTemplateV1(BaseModel):
_version: str = "messages-v1"
template: list[Union[TextPromptMessage, JSONPromptMessage]]
Copy link
Contributor

Choose a reason for hiding this comment

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

message_templates or messages?

Copy link
Contributor

Choose a reason for hiding this comment

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

ChatTemplateV1?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think it's probably a good idea for the different template types to conform to the same interface for now

Copy link
Contributor

Choose a reason for hiding this comment

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

This should just be a union no?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ah right

Copy link
Contributor Author

Choose a reason for hiding this comment

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

wait no, I think it's list[Union[...]] since there can be multiple messages

Copy link
Contributor

Choose a reason for hiding this comment

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

they key should be messages that's what's confusing here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ah I see, I changed it to template so all of our template wrappers have the same interface which I'm kind of partial to (the wrapper for the plain string template just has a template key)

Copy link
Contributor

Choose a reason for hiding this comment

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

It shouldn't leak into the graphQL type


type PromptMessagesTemplateV1GQL {
version: String!
template: [TextPromptMessageGQLJSONPromptMessageGQL!]!
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not following why this is a list?

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

Choose a reason for hiding this comment

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

The union type should be here

@anticorrelator anticorrelator force-pushed the dustin/add-promptversiontemplate-type branch from 7a90962 to 1154306 Compare December 20, 2024 16:51
import strawberry
from strawberry.scalars import JSON

from phoenix.server.api.helpers.prompthub.models import (
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
from phoenix.server.api.helpers.prompthub.models import (
from phoenix.server.api.helpers.prompts.models import (

Comment on lines 36 to 38
PromptTemplate = strawberry.union(
"PromptTemplateVersion", (PromptStringTemplate, PromptChatTemplateV1)
)
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe just name PromptTemplateVersion to match the underlying GraphQL type.

Comment on lines +19 to +22
@strawberry.type
class JSONPromptMessage:
role: PromptMessageRole
content: JSON
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this for tool call messages, images, etc.?

content: String!
}

union TextPromptMessageJSONPromptMessage = TextPromptMessage | JSONPromptMessage
Copy link
Contributor

@axiomofjoy axiomofjoy Dec 20, 2024

Choose a reason for hiding this comment

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

Can we name this union type as PromptMessage?

@@ -1377,6 +1382,11 @@ type Prompt implements Node {
promptVersions(first: Int = 50, last: Int, after: String, before: String): PromptVersionConnection!
}

type PromptChatTemplateV1 {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
type PromptChatTemplateV1 {
type PromptChatTemplate {

@@ -1377,6 +1382,11 @@ type Prompt implements Node {
promptVersions(first: Int = 50, last: Int, after: String, before: String): PromptVersionConnection!
}

type PromptChatTemplateV1 {
version: String!
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
version: String!
__version: String!

@@ -1377,6 +1382,11 @@ type Prompt implements Node {
promptVersions(first: Int = 50, last: Int, after: String, before: String): PromptVersionConnection!
}

type PromptChatTemplateV1 {
version: String!
messages: [TextPromptMessageJSONPromptMessage!]!
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
messages: [TextPromptMessageJSONPromptMessage!]!
messages: [PromptTemplateMessages!]!

@@ -1395,6 +1405,12 @@ type PromptEdge {
node: Prompt!
}

enum PromptMessageRole {
USER
SYSTEM
Copy link
Contributor

Choose a reason for hiding this comment

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

add a description that this includes the openAI developer role

@@ -1395,6 +1405,12 @@ type PromptEdge {
node: Prompt!
}

enum PromptMessageRole {
USER
Copy link
Contributor

Choose a reason for hiding this comment

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

Missing tool

@mikeldking mikeldking changed the title feat: Add PromptVersionTemplate type feat: Add PromptTemplate type Dec 20, 2024
@dosubot dosubot bot added size:XL This PR changes 500-999 lines, ignoring generated files. and removed size:L This PR changes 100-499 lines, ignoring generated files. labels Dec 20, 2024
@anticorrelator anticorrelator merged commit f3fe933 into prompts Dec 20, 2024
49 checks passed
@anticorrelator anticorrelator deleted the dustin/add-promptversiontemplate-type branch December 20, 2024 22:58
mikeldking added a commit that referenced this pull request Dec 26, 2024
* Flesh out PromptVersionTemplate type

* Return GraphQL objects with the correct type

* Use new types in node query

* Decouple pydantic models and gql types

* Rebuild gql schema

* Rework model names

* Update gql schema

* Propagate name into schema

* Incorporate feedback

* Update schema

* adjust UI to new schema

* cleanup

* Remove `hub` naming and clean up type annotations

---------

Co-authored-by: Mikyo King <[email protected]>
mikeldking added a commit that referenced this pull request Dec 26, 2024
* Flesh out PromptVersionTemplate type

* Return GraphQL objects with the correct type

* Use new types in node query

* Decouple pydantic models and gql types

* Rebuild gql schema

* Rework model names

* Update gql schema

* Propagate name into schema

* Incorporate feedback

* Update schema

* adjust UI to new schema

* cleanup

* Remove `hub` naming and clean up type annotations

---------

Co-authored-by: Mikyo King <[email protected]>
mikeldking added a commit that referenced this pull request Dec 27, 2024
* Flesh out PromptVersionTemplate type

* Return GraphQL objects with the correct type

* Use new types in node query

* Decouple pydantic models and gql types

* Rebuild gql schema

* Rework model names

* Update gql schema

* Propagate name into schema

* Incorporate feedback

* Update schema

* adjust UI to new schema

* cleanup

* Remove `hub` naming and clean up type annotations

---------

Co-authored-by: Mikyo King <[email protected]>
mikeldking added a commit that referenced this pull request Dec 28, 2024
* Flesh out PromptVersionTemplate type

* Return GraphQL objects with the correct type

* Use new types in node query

* Decouple pydantic models and gql types

* Rebuild gql schema

* Rework model names

* Update gql schema

* Propagate name into schema

* Incorporate feedback

* Update schema

* adjust UI to new schema

* cleanup

* Remove `hub` naming and clean up type annotations

---------

Co-authored-by: Mikyo King <[email protected]>
mikeldking added a commit that referenced this pull request Dec 31, 2024
* Flesh out PromptVersionTemplate type

* Return GraphQL objects with the correct type

* Use new types in node query

* Decouple pydantic models and gql types

* Rebuild gql schema

* Rework model names

* Update gql schema

* Propagate name into schema

* Incorporate feedback

* Update schema

* adjust UI to new schema

* cleanup

* Remove `hub` naming and clean up type annotations

---------

Co-authored-by: Mikyo King <[email protected]>
mikeldking added a commit that referenced this pull request Jan 3, 2025
* Flesh out PromptVersionTemplate type

* Return GraphQL objects with the correct type

* Use new types in node query

* Decouple pydantic models and gql types

* Rebuild gql schema

* Rework model names

* Update gql schema

* Propagate name into schema

* Incorporate feedback

* Update schema

* adjust UI to new schema

* cleanup

* Remove `hub` naming and clean up type annotations

---------

Co-authored-by: Mikyo King <[email protected]>
mikeldking added a commit that referenced this pull request Jan 3, 2025
* Flesh out PromptVersionTemplate type

* Return GraphQL objects with the correct type

* Use new types in node query

* Decouple pydantic models and gql types

* Rebuild gql schema

* Rework model names

* Update gql schema

* Propagate name into schema

* Incorporate feedback

* Update schema

* adjust UI to new schema

* cleanup

* Remove `hub` naming and clean up type annotations

---------

Co-authored-by: Mikyo King <[email protected]>
mikeldking added a commit that referenced this pull request Jan 9, 2025
* Flesh out PromptVersionTemplate type

* Return GraphQL objects with the correct type

* Use new types in node query

* Decouple pydantic models and gql types

* Rebuild gql schema

* Rework model names

* Update gql schema

* Propagate name into schema

* Incorporate feedback

* Update schema

* adjust UI to new schema

* cleanup

* Remove `hub` naming and clean up type annotations

---------

Co-authored-by: Mikyo King <[email protected]>
mikeldking added a commit that referenced this pull request Jan 9, 2025
* Flesh out PromptVersionTemplate type

* Return GraphQL objects with the correct type

* Use new types in node query

* Decouple pydantic models and gql types

* Rebuild gql schema

* Rework model names

* Update gql schema

* Propagate name into schema

* Incorporate feedback

* Update schema

* adjust UI to new schema

* cleanup

* Remove `hub` naming and clean up type annotations

---------

Co-authored-by: Mikyo King <[email protected]>
mikeldking added a commit that referenced this pull request Jan 24, 2025
* Flesh out PromptVersionTemplate type

* Return GraphQL objects with the correct type

* Use new types in node query

* Decouple pydantic models and gql types

* Rebuild gql schema

* Rework model names

* Update gql schema

* Propagate name into schema

* Incorporate feedback

* Update schema

* adjust UI to new schema

* cleanup

* Remove `hub` naming and clean up type annotations

---------

Co-authored-by: Mikyo King <[email protected]>
mikeldking added a commit that referenced this pull request Jan 24, 2025
* Flesh out PromptVersionTemplate type

* Return GraphQL objects with the correct type

* Use new types in node query

* Decouple pydantic models and gql types

* Rebuild gql schema

* Rework model names

* Update gql schema

* Propagate name into schema

* Incorporate feedback

* Update schema

* adjust UI to new schema

* cleanup

* Remove `hub` naming and clean up type annotations

---------

Co-authored-by: Mikyo King <[email protected]>
mikeldking added a commit that referenced this pull request Feb 6, 2025
* Flesh out PromptVersionTemplate type

* Return GraphQL objects with the correct type

* Use new types in node query

* Decouple pydantic models and gql types

* Rebuild gql schema

* Rework model names

* Update gql schema

* Propagate name into schema

* Incorporate feedback

* Update schema

* adjust UI to new schema

* cleanup

* Remove `hub` naming and clean up type annotations

---------

Co-authored-by: Mikyo King <[email protected]>
mikeldking added a commit that referenced this pull request Feb 6, 2025
* Flesh out PromptVersionTemplate type

* Return GraphQL objects with the correct type

* Use new types in node query

* Decouple pydantic models and gql types

* Rebuild gql schema

* Rework model names

* Update gql schema

* Propagate name into schema

* Incorporate feedback

* Update schema

* adjust UI to new schema

* cleanup

* Remove `hub` naming and clean up type annotations

---------

Co-authored-by: Mikyo King <[email protected]>
mikeldking added a commit that referenced this pull request Feb 19, 2025
* Flesh out PromptVersionTemplate type

* Return GraphQL objects with the correct type

* Use new types in node query

* Decouple pydantic models and gql types

* Rebuild gql schema

* Rework model names

* Update gql schema

* Propagate name into schema

* Incorporate feedback

* Update schema

* adjust UI to new schema

* cleanup

* Remove `hub` naming and clean up type annotations

---------

Co-authored-by: Mikyo King <[email protected]>
mikeldking added a commit that referenced this pull request Feb 19, 2025
* Flesh out PromptVersionTemplate type

* Return GraphQL objects with the correct type

* Use new types in node query

* Decouple pydantic models and gql types

* Rebuild gql schema

* Rework model names

* Update gql schema

* Propagate name into schema

* Incorporate feedback

* Update schema

* adjust UI to new schema

* cleanup

* Remove `hub` naming and clean up type annotations

---------

Co-authored-by: Mikyo King <[email protected]>
s-yeddula pushed a commit that referenced this pull request Mar 5, 2025
* Flesh out PromptVersionTemplate type

* Return GraphQL objects with the correct type

* Use new types in node query

* Decouple pydantic models and gql types

* Rebuild gql schema

* Rework model names

* Update gql schema

* Propagate name into schema

* Incorporate feedback

* Update schema

* adjust UI to new schema

* cleanup

* Remove `hub` naming and clean up type annotations

---------

Co-authored-by: Mikyo King <[email protected]>
s-yeddula pushed a commit that referenced this pull request Mar 5, 2025
* Flesh out PromptVersionTemplate type

* Return GraphQL objects with the correct type

* Use new types in node query

* Decouple pydantic models and gql types

* Rebuild gql schema

* Rework model names

* Update gql schema

* Propagate name into schema

* Incorporate feedback

* Update schema

* adjust UI to new schema

* cleanup

* Remove `hub` naming and clean up type annotations

---------

Co-authored-by: Mikyo King <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size:XL This PR changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[hub] [gql] ChatPromptTemplate type
3 participants