diff --git a/app/games/[gameId]/page.tsx b/app/games/[gameId]/page.tsx
index 5045d85..78a5872 100644
--- a/app/games/[gameId]/page.tsx
+++ b/app/games/[gameId]/page.tsx
@@ -13,6 +13,8 @@ export default function GamePage({ params }: { params: { gameId: string } }) {
gameId: params.gameId as Id<"games">,
});
+ console.log((results));
+
return (
Game {params.gameId}
diff --git a/convex/README.md b/convex/README.md
new file mode 100644
index 0000000..4d82e13
--- /dev/null
+++ b/convex/README.md
@@ -0,0 +1,90 @@
+# Welcome to your Convex functions directory!
+
+Write your Convex functions here.
+See https://docs.convex.dev/functions for more.
+
+A query function that takes two arguments looks like:
+
+```ts
+// functions.js
+import { query } from "./_generated/server";
+import { v } from "convex/values";
+
+export const myQueryFunction = query({
+ // Validators for arguments.
+ args: {
+ first: v.number(),
+ second: v.string(),
+ },
+
+ // Function implementation.
+ handler: async (ctx, args) => {
+ // Read the database as many times as you need here.
+ // See https://docs.convex.dev/database/reading-data.
+ const documents = await ctx.db.query("tablename").collect();
+
+ // Arguments passed from the client are properties of the args object.
+ console.log(args.first, args.second);
+
+ // Write arbitrary JavaScript here: filter, aggregate, build derived data,
+ // remove non-public properties, or create new objects.
+ return documents;
+ },
+});
+```
+
+Using this query function in a React component looks like:
+
+```ts
+const data = useQuery(api.functions.myQueryFunction, {
+ first: 10,
+ second: "hello",
+});
+```
+
+A mutation function looks like:
+
+```ts
+// functions.js
+import { mutation } from "./_generated/server";
+import { v } from "convex/values";
+
+export const myMutationFunction = mutation({
+ // Validators for arguments.
+ args: {
+ first: v.string(),
+ second: v.string(),
+ },
+
+ // Function implementation.
+ handler: async (ctx, args) => {
+ // Insert or modify documents in the database here.
+ // Mutations can also read from the database like queries.
+ // See https://docs.convex.dev/database/writing-data.
+ const message = { body: args.first, author: args.second };
+ const id = await ctx.db.insert("messages", message);
+
+ // Optionally, return a value from your mutation.
+ return await ctx.db.get(id);
+ },
+});
+```
+
+Using this mutation function in a React component looks like:
+
+```ts
+const mutation = useMutation(api.functions.myMutationFunction);
+function handleButtonPress() {
+ // fire and forget, the most common way to use mutations
+ mutation({ first: "Hello!", second: "me" });
+ // OR
+ // use the result once the mutation has completed
+ mutation({ first: "Hello!", second: "me" }).then((result) =>
+ console.log(result),
+ );
+}
+```
+
+Use the Convex CLI to push your functions to a deployment. See everything
+the Convex CLI can do by running `npx convex -h` in your project root
+directory. To learn more, launch the docs with `npx convex docs`.
diff --git a/models/claude-3-5-sonnet.ts b/models/claude-3-5-sonnet.ts
index c47ce9b..c51f1fd 100644
--- a/models/claude-3-5-sonnet.ts
+++ b/models/claude-3-5-sonnet.ts
@@ -6,39 +6,44 @@ export const claude35sonnet: ModelHandler = async (prompt, map) => {
apiKey: process.env.ANTHROPIC_API_KEY,
});
- const response = await anthropic.messages.create({
- model: "claude-3-sonnet-20240307",
- max_tokens: 1024,
- temperature: 0,
- system: prompt,
- messages: [
- {
- role: "user",
- content: JSON.stringify(map),
- },
- ],
- });
-
- const content = response.content[0];
-
- if (content.type !== "text") {
- throw new Error("Unexpected response type from Claude");
+ try {
+ const response = await anthropic.messages.create({
+ model: "claude-3-5-sonnet-20240620",
+ max_tokens: 1024,
+ temperature: 0,
+ system: prompt,
+ messages: [
+ {
+ role: "user",
+ content: JSON.stringify(map),
+ },
+ ],
+ });
+
+ const content = response.content[0];
+
+ if (content.type !== "text") {
+ throw new Error("Unexpected response type from Claude");
+ }
+
+ const parsedResponse = JSON.parse(content.text);
+
+ // Validate the response structure
+ if (
+ !Array.isArray(parsedResponse.boxCoordinates) ||
+ !Array.isArray(parsedResponse.playerCoordinates) ||
+ typeof parsedResponse.reasoning !== "string"
+ ) {
+ throw new Error("Invalid response structure");
+ }
+
+ return {
+ boxCoordinates: parsedResponse.boxCoordinates,
+ playerCoordinates: parsedResponse.playerCoordinates,
+ reasoning: parsedResponse.reasoning,
+ };
+ } catch (error) {
+ console.error("Error in claude35sonnet:", error);
+ throw error;
}
-
- const parsedResponse = JSON.parse(content.text);
-
- // Validate the response structure
- if (
- !Array.isArray(parsedResponse.boxCoordinates) ||
- !Array.isArray(parsedResponse.playerCoordinates) ||
- typeof parsedResponse.reasoning !== "string"
- ) {
- throw new Error("Invalid response structure");
- }
-
- return {
- boxCoordinates: parsedResponse.boxCoordinates,
- playerCoordinates: parsedResponse.playerCoordinates,
- reasoning: parsedResponse.reasoning,
- };
};
diff --git a/models/perplexity-llama.ts b/models/perplexity-llama.ts
index d3c59c2..7bf5e82 100644
--- a/models/perplexity-llama.ts
+++ b/models/perplexity-llama.ts
@@ -1,4 +1,3 @@
-import axios from 'axios';
import { z } from 'zod';
import { ModelHandler } from './index';
@@ -18,7 +17,7 @@ const PerplexityResponseSchema = z.object({
delta: z.object({
role: z.string(),
content: z.string(),
- }),
+ }).optional(),
})
),
usage: z.object({
@@ -42,8 +41,7 @@ export const perplexityModel: ModelHandler = async (prompt: string, map: string[
const messages = [
{ role: 'system', content: 'Be precise and concise.' },
- { role: 'user', content: prompt },
- { role: 'user', content: JSON.stringify(map) },
+ { role: 'user', content: `${prompt}\n\nMap:\n${JSON.stringify(map)}` },
];
const data = {
@@ -63,14 +61,23 @@ export const perplexityModel: ModelHandler = async (prompt: string, map: string[
};
try {
- const response = await axios.post('https://api.perplexity.ai/chat/completions', data, {
+ const response = await fetch('https://api.perplexity.ai/chat/completions', {
+ method: 'POST',
headers: {
'Authorization': `Bearer ${apiKey}`,
'Content-Type': 'application/json',
},
+ body: JSON.stringify(data),
});
- const validatedResponse = PerplexityResponseSchema.parse(response.data);
+ if (!response.ok) {
+ const errorData = await response.json();
+ console.error('API Error:', errorData);
+ throw new Error(`HTTP error! status: ${response.status}, message: ${JSON.stringify(errorData)}`);
+ }
+
+ const responseData = await response.json();
+ const validatedResponse = PerplexityResponseSchema.parse(responseData);
const content = validatedResponse.choices[0].message.content;
const parsedContent = JSON.parse(content);
const gameResponse = GameResponseSchema.parse(parsedContent);
@@ -82,6 +89,6 @@ export const perplexityModel: ModelHandler = async (prompt: string, map: string[
};
} catch (error) {
console.error('Failed to run Perplexity model Error:', error);
- throw new Error('Failed to run Perplexity model');
+ throw error;
}
-};
+};
\ No newline at end of file
diff --git a/package.json b/package.json
index c49ddf5..7748fd0 100644
--- a/package.json
+++ b/package.json
@@ -26,7 +26,6 @@
"@radix-ui/react-toast": "^1.2.1",
"@radix-ui/react-toggle": "^1.1.0",
"@radix-ui/react-toggle-group": "^1.1.0",
- "axios": "^1.7.7",
"class-variance-authority": "^0.7.0",
"clsx": "^2.1.1",
"convex": "^1.16.0",