10import { zodToJSONSchema } from "./smhi/toolSchema";
1112export async function callWeatherGPT(question: string) {
13if (!question?.length) {
14return { error: "Ask something" };
22return { error: "Be nice in your question" };
23}
24const weatherFunction = await zodToJSONSchema();
25const max_completion_tokens = 256;
26const now = new Date();
52temperature: 0.7,
53tools: [{
54type: "function",
55function: {
56name: "getWeather",
57description: weatherFunction.description,
58parameters: {
59type: weatherFunction.type,
60properties: weatherFunction.properties,
61required: weatherFunction.required,
62},
63},
71tool_calls: v.array(v.object({
72id: v.string(),
73type: v.literal("function"),
74function: v.object({ name: v.string(), arguments: v.string() }),
75})),
76}),
92});
93const matchingMessage = completion.choices?.find((choice) => choice.finish_reason === "tool_calls")?.message;
94const functionCall = matchingMessage?.tool_calls?.at(0);
95if (!functionCall) {
96const firstMessage = completion.choices[0].message;
97const answer = "content" in firstMessage ? firstMessage.content : null;
98return answer ? { answer } : { error: "Ask questions about the weather" };
99}
100const { name: functionName, arguments: argumentsString } = functionCall.function;
101if (!argumentsString) {
102return {
115paramaters: dataPoints,
116});
117const functionMessageContent = `
118The following is the response schema
119\`\`\`\n${JSON.stringify(zodSchema.schema)}\`\`\`\n
127"role": "tool" as const,
128"tool_call_id": matchingMessage.tool_calls?.at(0)!.id!,
129content: functionMessageContent,
130}]
131: [];
132const formattedFunctionResponseData = await openai.chat.completions.create({
133model: completionOptions.model,
134store: completionOptions.store,
138});
139return {
140summary: formattedFunctionResponseData.choices[0].message.content
141?? "something went wrong",
142data: forecastResponse,
1import { offset, removeOffset } from "npm:@formkit/tempo";
2import { fetchWeatherAtCoordinate } from "./fetcher";
3export async function getWeatherAtCoordinate(
4lon: number,
5lat: number,
1import { toJsonSchema } from "npm:@valibot/to-json-schema";
2import * as v from "npm:valibot";
3export async function getSmhiForecastResponseZodSchema(
4arg: {
5option: "parse";
1export function describeWeatherSymbolCode(code: number) {
2const weatherSymbols = [
3"Clear sky",
31return weatherSymbols[code - 1];
32}
33export function describePcat(code: number) {
34const categories = [
35"No precipitation",
3import { describePcat, describeWeatherSymbolCode } from "./describe";
45export async function fetchWeatherAtCoordinate(lon: number, lat: number) {
6if (!lon || isNaN(lon)) {
7return null;
askSMHImoderation1 match
3import { OpenAI } from "npm:openai";
45export async function openAIModeration(publicMessages: string[]) {
6const openAIKey = process.env.OPENAI_CHAT;
7const headers = {
3import { fetchJSON } from "https://esm.town/v/stevekrouse/fetchJSON";
45export default async function(interval: Interval) {
6try {
7const historicalModels = await blob.getJSON("cerebras-models.json");
4// import { Form, hydrate } from "https://esm.town/v/stevekrouse/ssr_react_mini?v=75";
56// export async function loader(req: Request) {
7// const { sqlite } = await import("https://esm.town/v/std/sqlite?v=4");
8// const [, { columns, rows }] = await sqlite.batch([
19// }
2021// export async function action(req: Request) {
22// const { sqlite } = await import("https://esm.town/v/std/sqlite?v=4");
23// const formData = await req.formData();
46// }
4748// export function Component({ initialTodos, initialLogs }) {
49// const [todos, setTodos] = useState(initialTodos);
50// const [logs, setLogs] = useState(initialLogs);
53// useEffect(() => addLog(`Client rendered`), []);
5455// function addTodo() {
56// setTodos([...todos, { text: newTodo }]);
57// setNewTodo("");
63// }
6465// function toggleTodo(e) {
66// const formData = new FormData(e.target);
67// const id = parseInt(formData.get("id") as string);
70// }
7172// function deleteTodo(e) {
73// const formData = new FormData(e.target);
74// const id = parseInt(formData.get("id") as string);
1const msg = new TextEncoder().encode("data: hello\r\n\r\n");
23export default async function(req: Request): Promise<Response> {
4let timerId: number | undefined;
5try {
annual_feedbackmain.tsx1 match
17)`);
1819async function addFeedback(req: Request) {
20const formData = await req.formData();
21let data = Object.fromEntries(formData.entries());