Skip to content
Merged
Changes from all commits
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
40 changes: 28 additions & 12 deletions src/utils/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import type { ZodSchema } from 'zod';
import { zodToJsonSchema } from 'zod-to-json-schema';
import type { AIModel, CloudRegion } from './types';
import { getCloudUrlFromRegion } from './urls';
import { analytics } from './analytics';
import { AxiosError } from 'axios';

export const query = async <S>({
message,
Expand All @@ -19,19 +21,33 @@ export const query = async <S>({
}): Promise<S> => {
const jsonSchema = zodToJsonSchema(schema, 'schema').definitions;

const response = await axios.post<{ data: unknown }>(
`${getCloudUrlFromRegion(region)}/api/wizard/query`,
{
message,
model,
json_schema: { ...jsonSchema, name: 'schema', strict: true },
},
{
headers: {
'X-PostHog-Wizard-Hash': wizardHash,
const response = await axios
.post<{ data: unknown }>(
`${getCloudUrlFromRegion(region)}/api/wizard/query`,
{
message,
model,
json_schema: { ...jsonSchema, name: 'schema', strict: true },
},
},
);
{
headers: {
'X-PostHog-Wizard-Hash': wizardHash,
},
},
)
.catch((error) => {
if (error instanceof AxiosError) {
analytics.captureException(error, {
response_status_code: error.response?.status,
message,
model,
json_schema: jsonSchema,
type: 'wizard_query_error',
});
}

throw error;
});
Comment thread
joshsny marked this conversation as resolved.

const validation = schema.safeParse(response.data.data);

Expand Down
Loading