Skip to content

Commit

Permalink
Make prompt code snippets conform to new schemas
Browse files Browse the repository at this point in the history
  • Loading branch information
cephalization committed Dec 30, 2024
1 parent ac1cc3d commit e25b015
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 47 deletions.
17 changes: 8 additions & 9 deletions app/src/pages/prompt/promptCodeSnippets.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { CodeLanguage } from "@phoenix/components/code";
import { isObject } from "@phoenix/typeUtils";

import type { PromptCodeExportCard__main$data as PromptVersion } from "./__generated__/PromptCodeExportCard__main.graphql";

Expand Down Expand Up @@ -110,16 +109,16 @@ export const promptCodeSnippets: Record<
messages = `${fmt}`;
args.push(`messages=messages`);
}
if (isObject(prompt.tools) && "tools" in prompt.tools) {
if (prompt.tools) {
const fmt = jsonFormatter({
json: prompt.tools.tools,
json: prompt.tools.map((tool) => tool.definition),
level: 1,
});
args.push(`tools=${fmt}`);
}
if (prompt.outputSchema && "output_schema" in prompt.outputSchema) {
if (prompt.outputSchema && "schema" in prompt.outputSchema) {
const fmt = jsonFormatter({
json: prompt.outputSchema.output_schema,
json: prompt.outputSchema.schema,
level: 1,
});
args.push(`response_format=${fmt}`);
Expand Down Expand Up @@ -170,17 +169,17 @@ print(completion.choices[0].message)
messages = `${fmt}`;
args.push(`messages`);
}
if (isObject(prompt.tools) && "tools" in prompt.tools) {
if (prompt.tools) {
const fmt = jsonFormatter({
json: prompt.tools.tools,
json: prompt.tools.map((tool) => tool.definition),
level: 1,
removeKeyQuotes: true,
});
args.push(`tools: ${fmt}`);
}
if (prompt.outputSchema && "output_schema" in prompt.outputSchema) {
if (prompt.outputSchema && "schema" in prompt.outputSchema) {
const fmt = jsonFormatter({
json: prompt.outputSchema.output_schema,
json: prompt.outputSchema.schema,
level: 1,
removeKeyQuotes: true,
});
Expand Down
41 changes: 22 additions & 19 deletions src/phoenix/server/api/queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
from phoenix.server.api.types.GenerativeModel import GenerativeModel
from phoenix.server.api.types.GenerativeProvider import GenerativeProvider, GenerativeProviderKey
from phoenix.server.api.types.InferencesRole import AncillaryInferencesRole, InferencesRole
from phoenix.server.api.types.JSONSchema import JSONSchema
from phoenix.server.api.types.Model import Model
from phoenix.server.api.types.node import from_global_id, from_global_id_with_expected_type
from phoenix.server.api.types.pagination import ConnectionArgs, CursorString, connection_from_list
Expand Down Expand Up @@ -563,30 +564,32 @@ async def node(self, id: GlobalID, info: Info[Context, None]) -> Node:
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",
"type": "function",
"function": {
"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"],
},
}
)
],
output_schema={
"_version": "output-schema-v1",
"output_schema": {
output_schema=JSONSchema(
schema={
"type": "json_schema",
"json_schema": {
"type": "object",
Expand All @@ -598,7 +601,7 @@ async def node(self, id: GlobalID, info: Info[Context, None]) -> Node:
"required": ["temperature", "location", "unit"],
},
},
},
),
model_name="gpt-4o",
model_provider="openai",
)
Expand Down
40 changes: 21 additions & 19 deletions src/phoenix/server/api/types/Prompt.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,30 +62,32 @@ async def prompt_versions(
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",
"type": "function",
"function": {
"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"],
},
}
)
],
output_schema={
"_version": "output-schema-v1",
"output_schema": {
output_schema=JSONSchema(
schema={
"type": "json_schema",
"json_schema": {
"type": "object",
Expand All @@ -97,7 +99,7 @@ async def prompt_versions(
"required": ["temperature", "location", "unit"],
},
},
},
),
model_name="gpt-4o",
model_provider="openai",
),
Expand Down

0 comments on commit e25b015

Please sign in to comment.