Skip to content

Commit

Permalink
remove template options
Browse files Browse the repository at this point in the history
  • Loading branch information
axiomofjoy committed Dec 24, 2024
1 parent b7fe57c commit 81b2b11
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 50 deletions.
8 changes: 2 additions & 6 deletions app/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ input ChatCompletionInput {
invocationParameters: [InvocationParameterInput!]! = []
tools: [JSON!]
apiKey: String = null
template: TemplateOptions
templateLanguage: TemplateLanguage
templateVariables: JSON
}

input ChatCompletionMessageInput {
Expand Down Expand Up @@ -1701,11 +1702,6 @@ enum TemplateLanguage {
F_STRING
}

input TemplateOptions {
variables: JSON!
language: TemplateLanguage!
}

type TextChunk implements ChatCompletionSubscriptionPayload {
datasetExampleId: GlobalID
content: String!
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.

6 changes: 2 additions & 4 deletions app/src/pages/playground/playgroundUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1010,10 +1010,8 @@ export const getChatCompletionInput = ({

return {
...baseChatCompletionVariables,
template: {
variables: variablesMap,
language: templateLanguage,
},
templateVariables: variablesMap,
templateLanguage,
};
};

Expand Down
4 changes: 2 additions & 2 deletions src/phoenix/server/api/input_types/ChatCompletionInput.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
from .ChatCompletionMessageInput import ChatCompletionMessageInput
from .GenerativeModelInput import GenerativeModelInput
from .InvocationParameters import InvocationParameterInput
from .TemplateOptions import TemplateOptions


@strawberry.input
Expand All @@ -20,7 +19,8 @@ class ChatCompletionInput:
invocation_parameters: list[InvocationParameterInput] = strawberry.field(default_factory=list)
tools: Optional[list[JSON]] = UNSET
api_key: Optional[str] = strawberry.field(default=None)
template: Optional[TemplateOptions] = UNSET
template_language: Optional[TemplateLanguage] = UNSET
template_variables: Optional[JSON] = UNSET


@strawberry.input
Expand Down
10 changes: 0 additions & 10 deletions src/phoenix/server/api/input_types/TemplateOptions.py

This file was deleted.

28 changes: 16 additions & 12 deletions src/phoenix/server/api/mutations/chat_mutations.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
ChatCompletionInput,
ChatCompletionOverDatasetInput,
)
from phoenix.server.api.input_types.TemplateOptions import TemplateOptions
from phoenix.server.api.subscriptions import (
_default_playground_experiment_description,
_default_playground_experiment_metadata,
Expand Down Expand Up @@ -209,10 +208,8 @@ async def chat_completion_over_dataset(
messages=input.messages,
tools=input.tools,
invocation_parameters=input.invocation_parameters,
template=TemplateOptions(
language=input.template_language,
variables=revision.input,
),
template_language=input.template_language,
template_variables=revision.input,
),
)
for revision in batch
Expand Down Expand Up @@ -316,11 +313,17 @@ async def _chat_completion(
)
for message in input.messages
]
if template_options := input.template:
messages = list(_formatted_messages(messages, template_options))
attributes.update(
{PROMPT_TEMPLATE_VARIABLES: safe_json_dumps(template_options.variables)}
if (template_language := input.template_language) and (
template_variables := input.template_variables
):
messages = list(
_formatted_messages(
messages=messages,
template_language=template_language,
template_variables=template_variables,
)
)
attributes.update({PROMPT_TEMPLATE_VARIABLES: safe_json_dumps(template_variables)})

invocation_parameters = llm_client.construct_invocation_parameters(
input.invocation_parameters
Expand Down Expand Up @@ -459,20 +462,21 @@ async def _chat_completion(

def _formatted_messages(
messages: Iterable[ChatCompletionMessage],
template_options: TemplateOptions,
template_language: TemplateLanguage,
template_variables: dict[str, Any],
) -> Iterator[ChatCompletionMessage]:
"""
Formats the messages using the given template options.
"""
template_formatter = _template_formatter(template_language=template_options.language)
template_formatter = _template_formatter(template_language=template_language)
(
roles,
templates,
tool_call_id,
tool_calls,
) = zip(*messages)
formatted_templates = map(
lambda template: template_formatter.format(template, **template_options.variables),
lambda template: template_formatter.format(template, **template_variables),
templates,
)
formatted_messages = zip(roles, formatted_templates, tool_call_id, tool_calls)
Expand Down
10 changes: 6 additions & 4 deletions src/phoenix/server/api/subscriptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,15 +120,17 @@ async def chat_completion(
for message in input.messages
]
attributes = None
if template_options := input.template:
if (template_language := input.template_language) and (
template_variables := input.template_variables
):
messages = list(
_formatted_messages(
messages=messages,
template_language=template_options.language,
template_variables=template_options.variables,
template_language=template_language,
template_variables=template_variables,
)
)
attributes = {PROMPT_TEMPLATE_VARIABLES: safe_json_dumps(template_options.variables)}
attributes = {PROMPT_TEMPLATE_VARIABLES: safe_json_dumps(template_variables)}
invocation_parameters = llm_client.construct_invocation_parameters(
input.invocation_parameters
)
Expand Down

0 comments on commit 81b2b11

Please sign in to comment.