Skip to content

Commit

Permalink
Fix discrepencies between ContentParts with Pydantic, GQL Input, and …
Browse files Browse the repository at this point in the history
…GQL Output

- Pydantic discriminated union was too strict, need to populate type field with defaults during validation since they are not provided by input
- Strawberry input types need to default to UNSET when using OneOf decorator arg
- unlike Strawberry input type, Strawberry output types need to match the same shape as the pydantic models so that they can be automatically converted from ORM model
  • Loading branch information
cephalization committed Jan 15, 2025
1 parent 0c98ea7 commit e7dd684
Show file tree
Hide file tree
Showing 17 changed files with 511 additions and 221 deletions.
30 changes: 23 additions & 7 deletions app/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -252,13 +252,13 @@ input ClusterInput {
id: ID
}

union ContentPart = TextContentValue | ImageContentValue | ToolCallContentValue | ToolResultContentValue
union ContentPart = TextContentPart | ImageContentPart | ToolCallContentPart | ToolResultContentPart

input ContentPartInput @oneOf {
text: TextContentValueInput = null
image: ImageContentValueInput = null
toolCall: ToolCallContentValueInput = null
toolResult: ToolResultContentValueInput = null
text: TextContentValueInput
image: ImageContentValueInput
toolCall: ToolCallContentValueInput
toolResult: ToolResultContentValueInput
}

input CreateApiKeyInput {
Expand Down Expand Up @@ -1045,6 +1045,10 @@ input Granularity {
samplingIntervalMinutes: Int!
}

type ImageContentPart {
image: ImageContentValue!
}

type ImageContentValue {
url: String!
}
Expand Down Expand Up @@ -1913,6 +1917,10 @@ type TextChunk implements ChatCompletionSubscriptionPayload {
content: String!
}

type TextContentPart {
text: TextContentValue!
}

type TextContentValue {
text: String!
}
Expand Down Expand Up @@ -1950,12 +1958,16 @@ type ToolCallChunk implements ChatCompletionSubscriptionPayload {
function: FunctionCallChunk!
}

type ToolCallContentPart {
toolCall: ToolCallContentValue!
}

type ToolCallContentValue {
toolCall: String!
toolCallId: String!
}

input ToolCallContentValueInput {
toolCall: String!
toolCallId: String!
}

type ToolDefinition {
Expand All @@ -1966,6 +1978,10 @@ input ToolDefinitionInput {
definition: JSON!
}

type ToolResultContentPart {
toolResult: ToolResultContentValue!
}

type ToolResultContentValue {
toolCallId: String!
result: JSON!
Expand Down

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

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

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

26 changes: 17 additions & 9 deletions app/src/pages/playground/fetchPlaygroundPrompt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -344,18 +344,26 @@ const fetchPlaygroundPromptQuery = graphql`
role
content {
__typename
... on TextContentValue {
text
... on TextContentPart {
text {
text
}
}
... on ImageContentValue {
url
... on ImageContentPart {
image {
url
}
}
... on ToolCallContentValue {
toolCall
... on ToolCallContentPart {
toolCall {
toolCallId
}
}
... on ToolResultContentValue {
toolCallId
result
... on ToolResultContentPart {
toolResult {
toolCallId
result
}
}
}
}
Expand Down
26 changes: 17 additions & 9 deletions app/src/pages/prompt/PromptChatMessagesCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,26 @@ export function PromptChatMessages({
role
content {
__typename
... on TextContentValue {
text
... on TextContentPart {
text {
text
}
}
... on ImageContentValue {
url
... on ImageContentPart {
image {
url
}
}
... on ToolCallContentValue {
toolCall
... on ToolCallContentPart {
toolCall {
toolCallId
}
}
... on ToolResultContentValue {
toolCallId
result
... on ToolResultContentPart {
toolResult {
toolCallId
result
}
}
}
}
Expand Down
Loading

0 comments on commit e7dd684

Please sign in to comment.