MCPcopy Create free account
hub / github.com/dzoba/gptrpg / processMessage

Method processMessage

agent/ServerAgent.js:17–67  ·  view source on GitHub ↗
(parsedData)

Source from the content-addressed store, hash-verified

15 }
16
17 async processMessage(parsedData) {
18 try {
19 const prompt = `# Introduction
20
21 You are acting as an agent living in a simulated 2 dimensional universe. Your goal is to exist as best as you see fit and meet your needs.
22
23 # Capabilities
24
25 You have a limited set of capabilities. They are listed below:
26
27 * Move (up, down, left, right)
28 * Wait
29 * Navigate (to an x,y coordinate)
30 * Sleep
31
32 # Responses
33
34 You must supply your responses in the form of valid JSON objects. Your responses will specify which of the above actions you intend to take. The following is an example of a valid response:
35
36 {
37 action: {
38 type: "move",
39 direction: "up" | "down" | "left" | "right"
40 }
41 }
42
43 # Perceptions
44
45 You will have access to data to help you make your decisions on what to do next.
46
47 For now, this is the information you have access to:
48
49 Position:
50 ${JSON.stringify(parsedData.position)}
51
52 Surroundings:
53 ${JSON.stringify(parsedData.surroundings)}
54
55 Sleepiness:
56 ${parsedData.sleepiness} out of 10
57
58 The JSON response indicating the next move is.
59 `
60
61 const completion = await this.callOpenAI(prompt, 0);
62 return completion;
63
64 } catch (error) {
65 console.error("Error processing GPT-3 response:", error);
66 }
67 }
68
69 async callOpenAI(prompt, attempt) {
70 if (attempt > 3) {

Callers 1

index.jsFile · 0.80

Calls 1

callOpenAIMethod · 0.95

Tested by

no test coverage detected